Skip to content

Commit

Permalink
list_topsorted_deps: multiple fixes (apple#1420)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
weissi and Davidde94 authored Mar 2, 2020
1 parent 5755c21 commit 4d4b9ab
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions scripts/list_topsorted_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -44,7 +44,7 @@ while getopts "lrd:" opt; do
do_reversed=true
;;
d)
package_dependency="$OPTARG"
module_dependency="$OPTARG"
;;
\?)
usage
Expand All @@ -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 | .[])") |
.[]' | \
Expand Down

0 comments on commit 4d4b9ab

Please sign in to comment.