Files
swift-nio-http2/scripts/list_topsorted_dependencies.sh
T
George Barnett f6cde03ef8 Bump Swift version in build_podspec.sh (#294)
Motivation:

SwiftNIO recently dropped support for Swift 5.0 and Swift 5.1 but our
build_podspec.sh script doesn't reflect this change. Additionally the
list_topsorted_dependencies.sh script always assumed named depenencies
when listing module depenencies. Since our tools version has now been
bumped to 5.2 that's no longer the case and the script produces a bunch
of nulls which throws the build_podspec.sh script off course.

Modifications:

- Bump the Swift version in build_podspec.sh to 5.2
- Include "product" dependencies when listing module dependencies in
  list_topsorted_dependencies.sh

Result:

Podspecs are created as expected
2021-08-17 10:11:26 +01:00

93 lines
2.7 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 module"
}
function tac_compat() {
sed '1!G;h;$!d'
}
tmpfile=$(mktemp /tmp/.list_topsorted_dependencies_XXXXXX)
only_libs=false
do_reversed=false
module_dependency=""
while getopts "lrd:" opt; do
case $opt in
l)
only_libs=true
;;
r)
do_reversed=true
;;
d)
module_dependency="$OPTARG"
;;
\?)
usage
exit 1
;;
esac
done
transform=cat
if $do_reversed; then
transform=tac_compat
fi
if [[ ! -z "$module_dependency" ]]; then
swift package dump-package | jq -r ".targets |
map(select(.name == \"$module_dependency\" and .type == \"regular\") | .dependencies | map(.byName | first) + map(.product | first) ) | del(.[][] | nulls) | .[] | .[]"
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) | map(. as $current | $names | map(select($current == .))) | flatten } ) |
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"