19
19
# This script will clean, build, and run tests against each installation of Xcode available on the
20
20
# machine using bazel.
21
21
#
22
- # Arguments:
23
- # 1. bazel action (build or test, usually)
24
- # 2. BUILD target.
25
- # 3. Minimum Xcode version. E.g. "8" or "8.2.1"
22
+ # Ordered arguments:
23
+ # 1. action: bazel ACTION. E.g. "build" or "test".
24
+ # 2. target: Bazel build target. E.g. "//path/to/target:Target"
25
+ #
26
+ # Named arguments:
27
+ # -m|--min-xcode-version <version>: Every Xcode version equal to or greater than this value will
28
+ # build and run tests. E.g. "8.2.1" will run 8.2.1, 8.3.3, 9,
29
+ # etc...
30
+ # -v|--verbose: Generates verbose output on local runs.
31
+ # Does not affect kokoro runs.
26
32
#
27
33
# Example usage:
28
- # bazel.sh build //:CatalogByConvention
29
- # bazel.sh test //:CatalogByConventionTests
34
+ # bazel.sh build //:CatalogByConvention --xcode-version 8.2
35
+ # bazel.sh test //:CatalogByConventionTests -v
30
36
31
37
# Fail on any error.
32
38
set -e
33
39
34
- # Display commands to stderr.
35
- set -x
36
-
37
- script_version=" v3.2.0"
38
- echo " bazel_build_and_test version $script_version "
40
+ script_version=" v4.0.0"
41
+ echo " $( basename $0 ) version $script_version "
39
42
40
43
version_as_number () {
41
44
padded_version=" ${1% .} " # Strip any trailing dots
@@ -46,38 +49,72 @@ version_as_number() {
46
49
echo " ${padded_version// .} "
47
50
}
48
51
49
- action= " $1 "
50
- target= " $2 "
51
- min_xcode_version =" $( version_as_number $3 ) "
52
+ POSITIONAL=()
53
+ while [[ $# -gt 0 ]] ; do
54
+ key =" $1 "
52
55
53
- # Dependencies
56
+ case $key in
57
+ -m|--min-xcode-version)
58
+ MIN_XCODE_VERSION=" $( version_as_number $2 ) "
59
+ shift
60
+ shift
61
+ ;;
62
+ -v|--verbose)
63
+ VERBOSE_OUTPUT=" 1"
64
+ shift
65
+ ;;
66
+ * )
67
+ POSITIONAL+=(" $1 " )
68
+ shift
69
+ ;;
70
+ esac
71
+ done
72
+ set -- " ${POSITIONAL[@]} " # restore positional parameters
54
73
55
74
if [ -n " $KOKORO_BUILD_NUMBER " ]; then
56
75
# Move into our cloned repo
57
76
cd github/repo
77
+
78
+ # Always enable verbose output on kokoro runs.
79
+ VERBOSE_OUTPUT=1
80
+ fi
81
+
82
+ if [ -n " $VERBOSE_OUTPUT " ]; then
83
+ verbosity_flags=" -s"
84
+
85
+ # Display commands to stderr.
86
+ set -x
58
87
fi
59
88
60
- # Runs our tests on every available Xcode 8 or 9 installation.
89
+ ACTION=" $1 "
90
+ TARGET=" $2 "
91
+
92
+ # Runs our tests on every available Xcode installation.
61
93
ls /Applications/ | grep " Xcode" | while read -r xcode_path; do
62
94
xcode_version=$( cat /Applications/$xcode_path /Contents/version.plist \
63
95
| grep " CFBundleShortVersionString" -A1 \
64
96
| grep string \
65
97
| cut -d' >' -f2 \
66
98
| cut -d' <' -f1)
67
- if [ -n " $min_xcode_version " ]; then
99
+ if [ -n " $MIN_XCODE_VERSION " ]; then
68
100
xcode_version_as_number=" $( version_as_number $xcode_version ) "
69
101
70
- if [ " $xcode_version_as_number " -lt " $min_xcode_version " ]; then
102
+ if [ " $xcode_version_as_number " -lt " $MIN_XCODE_VERSION " ]; then
71
103
continue
72
104
fi
73
105
fi
74
106
75
107
extra_args=" "
76
- if [ " $action " == " build" ]; then
77
- echo " 🏗️ $target with Xcode $xcode_version ..."
78
- elif [ " $action " == " test" ]; then
79
- echo " 🛠️ $target with Xcode $xcode_version ..."
80
- extra_args=" --test_output=all"
108
+ if [ " $ACTION " == " build" ]; then
109
+ echo " 🏗️ $TARGET with Xcode $xcode_version ..."
110
+ elif [ " $ACTION " == " test" ]; then
111
+ echo " 🛠️ $TARGET with Xcode $xcode_version ..."
112
+
113
+ if [ -n " $VERBOSE_OUTPUT " ]; then
114
+ extra_args=" --test_output=all"
115
+ else
116
+ extra_args=" --test_output=errors"
117
+ fi
81
118
82
119
if [ -n " $KOKORO_BUILD_NUMBER " ]; then
83
120
sudo xcode-select --switch /Applications/$xcode_path /Contents/Developer
@@ -90,5 +127,5 @@ ls /Applications/ | grep "Xcode" | while read -r xcode_path; do
90
127
fi
91
128
92
129
bazel clean
93
- bazel $action $target --xcode_version $xcode_version $extra_args -s
130
+ bazel $ACTION $TARGET --xcode_version $xcode_version $extra_args $verbosity_flags
94
131
done
0 commit comments