mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Motivation: Newer versions of SwiftPM for the Swift 5 release have changed the output format of swift package dump-package. This has broken our list_topsorted_dependencies script. This script is highly useful, so we'd like to keep it working. The discussion on SR-9191 suggests that SwiftPM considers this format changeable at any time, so we may need to make a change like this in future. We may want to consider writing tests for this script to ensure its continued good functioning. Modifications: - Amended the jq scripts to parse the new JSON format. Result: list_topsorted_dependencies will work with Swift 5 development copies of SwiftPM. Note that this will break this script with earlier copies of SwiftPM, but as we only support Swift 5 on the master branch this change is safe to make.
91 lines
2.5 KiB
Bash
Executable File
91 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
##===----------------------------------------------------------------------===##
|
|
##
|
|
## This source file is part of the SwiftNIO open source project
|
|
##
|
|
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
|
## Licensed under Apache License v2.0
|
|
##
|
|
## See LICENSE.txt for license information
|
|
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
##
|
|
## SPDX-License-Identifier: Apache-2.0
|
|
##
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
set -eu
|
|
|
|
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
function usage() {
|
|
echo "$0 -l"
|
|
echo
|
|
echo "OPTIONS:"
|
|
echo " -l: Only dependencies of library targets"
|
|
echo " -r: Reverse the output"
|
|
echo " -d <PACKAGE>: Prints the dependencies of the given package"
|
|
}
|
|
|
|
function tac_compat() {
|
|
sed '1!G;h;$!d'
|
|
}
|
|
|
|
tmpfile=$(mktemp /tmp/.list_topsorted_dependencies_XXXXXX)
|
|
|
|
only_libs=false
|
|
do_reversed=false
|
|
package_dependency=""
|
|
while getopts "lrd:" opt; do
|
|
case $opt in
|
|
l)
|
|
only_libs=true
|
|
;;
|
|
r)
|
|
do_reversed=true
|
|
;;
|
|
d)
|
|
package_dependency="$OPTARG"
|
|
;;
|
|
\?)
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
transform=cat
|
|
if $do_reversed; then
|
|
transform=tac_compat
|
|
fi
|
|
|
|
if [[ ! -z "$package_dependency" ]]; then
|
|
swift package dump-package | jq -r ".targets |
|
|
map(select(.name == \"$package_dependency\" and .type == \"regular\") | .dependencies | map(.byName | first)) | .[] | .[]"
|
|
exit 0
|
|
fi
|
|
|
|
(
|
|
cd "$here/.."
|
|
if $only_libs; then
|
|
swift package dump-package | jq '.products |
|
|
map(select(.type | has("library") | not)) |
|
|
map(.name) | .[]' | tr -d '"' \
|
|
>> "$tmpfile"
|
|
fi
|
|
swift package dump-package | jq '.targets |
|
|
map(.name as $name |
|
|
select(.name == $name and .type == "regular") |
|
|
{ "\($name)": .dependencies | map(.byName | first) } ) |
|
|
map(to_entries[]) |
|
|
map("\(.key) \(.value | .[])") |
|
|
.[]' | \
|
|
tr -d '"' | \
|
|
tsort | "$transform" | while read -r line; do
|
|
if ! grep -q "^$line\$" "$tmpfile"; then
|
|
echo "$line"
|
|
fi
|
|
done
|
|
)
|
|
|
|
rm "$tmpfile"
|