list_topsorted_deps: multiple fixes (#1420)

Motivation:

list_topsorted_dependencies had multiple issues:
- it would list some executable targets (even in libs-only mode)
- it confused packages with modules
- it would also list dependencies from outside the current package

Modifications:

Address all of the above.

Result:

Script more useful, inside and outside of swift-nio.

Co-authored-by: David Evans <david.evans@blackpoint.co>
This commit is contained in:
Johannes WeissandDavid Evans authored and GitHub committed 2020-03-02 15:49:09 +00:00
1 parent 5755c21a61
commit 4d4b9ab4b9
1 file changed
+8 -6
+8 -6
View File
@@ -23,7 +23,7 @@ function usage() {
echo "OPTIONS:"
echo " -l: Only dependencies of library targets"
echo " -r: Reverse the output"
echo " -d <PACKAGE>: Prints the dependencies of the given package"
echo " -d <PACKAGE>: Prints the dependencies of the given module"
}
function tac_compat() {
@@ -34,7 +34,7 @@ tmpfile=$(mktemp /tmp/.list_topsorted_dependencies_XXXXXX)
only_libs=false
do_reversed=false
package_dependency=""
module_dependency=""
while getopts "lrd:" opt; do
case $opt in
l)
@@ -44,7 +44,7 @@ while getopts "lrd:" opt; do
do_reversed=true
;;
d)
package_dependency="$OPTARG"
module_dependency="$OPTARG"
;;
\?)
usage
@@ -58,24 +58,26 @@ if $do_reversed; then
transform=tac_compat
fi
if [[ ! -z "$package_dependency" ]]; then
if [[ ! -z "$module_dependency" ]]; then
swift package dump-package | jq -r ".targets |
map(select(.name == \"$package_dependency\" and .type == \"regular\") | .dependencies | map(.byName | first)) | .[] | .[]"
map(select(.name == \"$module_dependency\" and .type == \"regular\") | .dependencies | map(.byName | first)) | .[] | .[]"
exit 0
fi
(
cd "$here/.."
if $only_libs; then
find Sources -name 'main.swift' | cut -d/ -f2 >> "$tmpfile"
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 $names |
map(.name as $name |
select(.name == $name and .type == "regular") |
{ "\($name)": .dependencies | map(.byName | first) } ) |
{ "\($name)": .dependencies | map(.byName | first) | map(. as $current | $names | map(select($current == .))) | flatten } ) |
map(to_entries[]) |
map("\(.key) \(.value | .[])") |
.[]' | \