Skip to content

Commit 046fb41

Browse files
danliew-applejrose-apple
authored andcommitted
Improve usability of build-toolchain script. (#14785)
This script improves several things: * Previous it was incredilby easy to accidently mis-use the script. For example running `build-toolchain -n` would set `BUNDLE_PREFIX` to `-n`. The new implementation of command line argument parsing is less fragile and easier to extend. * Provides `--help` (or `-h`) output. * Prints the value of several environment variables before running `build-script`. * Shows the invocation of `build-script`. The accepted order of command line arguments has not changed to avoid breaking existing users of the script.
1 parent 5e031d0 commit 046fb41

File tree

1 file changed

+75
-14
lines changed

1 file changed

+75
-14
lines changed

utils/build-toolchain

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,92 @@
1010
# See https://swift.org/LICENSE.txt for license information
1111
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212

13+
function usage() {
14+
echo "$0 <bundle_prefix> [OPTIONS]"
15+
echo ""
16+
echo "<bundle_prefix> - Prefix to use for bundle name"
17+
echo ""
18+
echo "OPTIONS"
19+
echo ""
20+
echo "-h --help"
21+
echo "Show help information."
22+
echo ""
23+
echo "-n --dry-run"
24+
echo "Do a dry run."
25+
echo ""
26+
if [[ "$(uname -s)" == "Linux" ]] ; then
27+
echo "-t --test"
28+
echo "Run tests."
29+
echo ""
30+
fi
31+
}
32+
1333
cd "$(dirname $0)/.." || exit
1434
SRC_DIR=$PWD
1535

36+
# Set defaults
1637
DRY_RUN=
17-
if [[ "$2" == "-n" || "$2" == "--dry-run" ]] ; then
18-
DRY_RUN="-n"
19-
shift
38+
BUNDLE_PREFIX=
39+
case $(uname -s) in
40+
Darwin)
41+
SWIFT_PACKAGE=buildbot_osx_package
42+
;;
43+
Linux)
44+
SWIFT_PACKAGE=buildbot_linux,no_test
45+
;;
46+
*)
47+
echo "Unrecognised platform $(uname -s)"
48+
exit 1
49+
;;
50+
esac
51+
52+
# Process command line arguments
53+
FIRST_ARG_PROCESSED=0
54+
while [ $# -ne 0 ]; do
55+
case "$1" in
56+
-n|--dry-run)
57+
DRY_RUN="-n"
58+
;;
59+
-t|--test)
60+
if [ "$(uname -s)" == "Linux" ]; then
61+
SWIFT_PACKAGE=buildbot_linux
62+
else
63+
echo "--test is not supported on \"$(uname -s)\". See --help"
64+
exit 1
65+
fi
66+
;;
67+
-h|--help)
68+
usage
69+
exit 0
70+
;;
71+
*)
72+
if [ ${FIRST_ARG_PROCESSED} -eq 0 ]; then
73+
# This is the bundle prefix
74+
BUNDLE_PREFIX="$1"
75+
else
76+
echo "Unrecognised argument \"$1\""
77+
exit 1
78+
fi
79+
;;
80+
esac
81+
FIRST_ARG_PROCESSED=1
82+
shift
83+
done
84+
85+
if [ -z "${BUNDLE_PREFIX}" ]; then
86+
echo "Bundle prefix cannot be empty. See $0 --help"
87+
exit 1
2088
fi
2189

90+
# Report the commands being run
91+
set -x
2292
YEAR=$(date +"%Y")
2393
MONTH=$(date +"%m")
2494
DAY=$(date +"%d")
2595
TOOLCHAIN_VERSION="swift-LOCAL-${YEAR}-${MONTH}-${DAY}-a"
2696
ARCHIVE="${TOOLCHAIN_VERSION}-osx.tar.gz"
2797
SYM_ARCHIVE="${TOOLCHAIN_VERSION}-osx-symbols.tar.gz"
28-
BUNDLE_PREFIX=${1:?Please specify bundle prefix e.g. $0 local.swift}
98+
BUNDLE_PREFIX=${BUNDLE_PREFIX:?Please specify a bundle prefix}
2999
BUNDLE_IDENTIFIER="${BUNDLE_PREFIX}.${YEAR}${MONTH}${DAY}"
30100
DISPLAY_NAME_SHORT="Local Swift Development Snapshot"
31101
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
@@ -36,16 +106,7 @@ SWIFT_INSTALL_DIR="${SRC_DIR}/swift-nightly-install"
36106
SWIFT_INSTALL_SYMROOT="${SRC_DIR}/swift-nightly-symroot"
37107
SWIFT_TOOLCHAIN_DIR="/Library/Developer/Toolchains/${TOOLCHAIN_NAME}.xctoolchain"
38108
SYMBOLS_PACKAGE="${SRC_DIR}/${SYM_ARCHIVE}"
39-
40-
if [[ "$(uname -s)" == "Darwin" ]] ; then
41-
SWIFT_PACKAGE=buildbot_osx_package
42-
else
43-
if [[ "$2" == "-t" || "$2" == "--test" ]] ; then
44-
SWIFT_PACKAGE=buildbot_linux
45-
else
46-
SWIFT_PACKAGE=buildbot_linux,no_test
47-
fi
48-
fi
109+
DRY_RUN="${DRY_RUN}"
49110

50111
./utils/build-script ${DRY_RUN} --preset="${SWIFT_PACKAGE}" \
51112
install_destdir="${SWIFT_INSTALL_DIR}" \

0 commit comments

Comments
 (0)