1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
#!/bin/bash
#
# Helper to do build so you don't have to remember all the steps/args.
set -eu
# Some base locations.
readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
readonly ProtoRootDir="${ScriptDir}/../.."
readonly BazelFlags="${BAZEL_FLAGS:---announce_rc --macos_minimum_os=11.0}"
# Invoke with BAZEL=bazelisk to use that instead.
readonly BazelBin="${BAZEL:-bazel}"
printUsage() {
NAME=$(basename "${0}")
cat << EOF
usage: ${NAME} [OPTIONS]
This script does the common build steps needed.
OPTIONS:
General:
-h, --help
Show this message
-c, --clean
Issue a clean before the normal build.
--full-build
By default only protoc is built within protobuf, this option will
enable a full build/test of the entire protobuf project.
--skip-xcode
Skip the invoke of Xcode to test the runtime on both iOS and OS X.
--skip-xcode-ios
Skip the invoke of Xcode to test the runtime on iOS.
--skip-xcode-debug
Skip the Xcode Debug configuration.
--skip-xcode-release
Skip the Xcode Release configuration.
--skip-xcode-osx | --skip-xcode-macos
Skip the invoke of Xcode to test the runtime on OS X.
--skip-xcode-tvos
Skip the invoke of Xcode to test the runtime on tvOS.
--skip-objc-conformance
Skip the Objective C conformance tests (run on OS X).
--skip-xcpretty
By default, if xcpretty is installed, it will be used, this option will
skip it even it it is installed.
--xcode-quiet
Pass -quiet to xcodebuild.
EOF
}
header() {
echo ""
echo "========================================================================"
echo " ${@}"
echo "========================================================================"
}
xcodebuild_xcpretty() {
set -o pipefail && xcodebuild "${@}" | xcpretty
}
if hash xcpretty >/dev/null 2>&1 ; then
XCODEBUILD=xcodebuild_xcpretty
else
XCODEBUILD=xcodebuild
fi
DO_CLEAN=no
FULL_BUILD=no
DO_XCODE_IOS_TESTS=yes
DO_XCODE_OSX_TESTS=yes
DO_XCODE_TVOS_TESTS=yes
DO_XCODE_DEBUG=yes
DO_XCODE_RELEASE=yes
DO_OBJC_CONFORMANCE_TESTS=yes
XCODE_QUIET=no
while [[ $# != 0 ]]; do
case "${1}" in
-h | --help )
printUsage
exit 0
;;
-c | --clean )
DO_CLEAN=yes
;;
--full-build )
FULL_BUILD=yes
;;
--skip-xcode )
DO_XCODE_IOS_TESTS=no
DO_XCODE_OSX_TESTS=no
DO_XCODE_TVOS_TESTS=no
;;
--skip-xcode-ios )
DO_XCODE_IOS_TESTS=no
;;
--skip-xcode-osx | --skip-xcode-macos)
DO_XCODE_OSX_TESTS=no
;;
--skip-xcode-tvos )
DO_XCODE_TVOS_TESTS=no
;;
--skip-xcode-debug )
DO_XCODE_DEBUG=no
;;
--skip-xcode-release )
DO_XCODE_RELEASE=no
;;
--skip-objc-conformance )
DO_OBJC_CONFORMANCE_TESTS=no
;;
--skip-xcpretty )
XCODEBUILD=xcodebuild
;;
--xcode-quiet )
XCODE_QUIET=yes
;;
-*)
echo "ERROR: Unknown option: ${1}" 1>&2
printUsage
exit 1
;;
*)
echo "ERROR: Unknown argument: ${1}" 1>&2
printUsage
exit 1
;;
esac
shift
done
# Into the proto dir.
cd "${ProtoRootDir}"
if [[ "${DO_CLEAN}" == "yes" ]] ; then
header "Cleaning"
${BazelBin} clean
if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
XCODEBUILD_CLEAN_BASE_IOS=(
xcodebuild
-project objectivec/ProtocolBuffers_iOS.xcodeproj
-scheme ProtocolBuffers
)
if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
"${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
fi
if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
"${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
fi
fi
if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
XCODEBUILD_CLEAN_BASE_OSX=(
xcodebuild
-project objectivec/ProtocolBuffers_OSX.xcodeproj
-scheme ProtocolBuffers
)
if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
"${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
fi
if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
"${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
fi
fi
if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then
XCODEBUILD_CLEAN_BASE_OSX=(
xcodebuild
-project objectivec/ProtocolBuffers_tvOS.xcodeproj
-scheme ProtocolBuffers
)
if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
"${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
fi
if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
"${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
fi
fi
fi
if [[ "${FULL_BUILD}" == "yes" ]] ; then
header "Build/Test: everything"
${BazelBin} test //:protoc //:protobuf //src/... $BazelFlags
else
header "Building: protoc"
${BazelBin} build //:protoc $BazelFlags
fi
# Ensure the WKT sources checked in are current.
objectivec/generate_well_known_types.sh --check-only
header "Checking on the ObjC Runtime pddm expansions"
${BazelBin} test //objectivec:sources_pddm_expansion_test $BazelFlags
readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
XCODEBUILD_TEST_BASE_IOS=(
"${XCODEBUILD}"
-project objectivec/ProtocolBuffers_iOS.xcodeproj
-scheme ProtocolBuffers
)
if [[ "${XCODE_QUIET}" == "yes" ]] ; then
XCODEBUILD_TEST_BASE_IOS+=( -quiet )
fi
# Don't need to worry about form factors or retina/non retina.
# NOTE: Different Xcode have different simulated hardware/os support.
case "${XCODE_VERSION}" in
[6-9].* | 1[0-2].* )
echo "ERROR: Xcode 13.3.1 or higher is required." 1>&2
exit 11
;;
13.* | 14.*)
XCODEBUILD_TEST_BASE_IOS+=(
-destination "platform=iOS Simulator,name=iPhone 13,OS=latest"
)
;;
15.* | 16.*)
XCODEBUILD_TEST_BASE_IOS+=(
-destination "platform=iOS Simulator,name=iPhone 15,OS=latest"
)
;;
* )
echo ""
echo "ATTENTION: Time to update the simulator targets for Xcode ${XCODE_VERSION}"
echo ""
echo "ERROR: Build aborted!"
exit 2
;;
esac
if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
header "Doing Xcode iOS build/tests - Debug"
"${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
fi
if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
header "Doing Xcode iOS build/tests - Release"
"${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
fi
# Don't leave the simulator in the developer's face.
killall Simulator 2> /dev/null || true
fi
if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
XCODEBUILD_TEST_BASE_OSX=(
"${XCODEBUILD}"
-project objectivec/ProtocolBuffers_OSX.xcodeproj
-scheme ProtocolBuffers
-destination "platform=macOS"
)
if [[ "${XCODE_QUIET}" == "yes" ]] ; then
XCODEBUILD_TEST_BASE_OSX+=( -quiet )
fi
case "${XCODE_VERSION}" in
[6-9].* | 1[0-2].* )
echo "ERROR: Xcode 13.3.1 or higher is required." 1>&2
exit 11
;;
esac
if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
header "Doing Xcode OS X build/tests - Debug"
"${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
fi
if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
header "Doing Xcode OS X build/tests - Release"
"${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
fi
fi
if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then
XCODEBUILD_TEST_BASE_TVOS=(
"${XCODEBUILD}"
-project objectivec/ProtocolBuffers_tvOS.xcodeproj
-scheme ProtocolBuffers
)
case "${XCODE_VERSION}" in
[6-9].* | 1[0-2].* )
echo "ERROR: Xcode 13.3.1 or higher is required." 1>&2
exit 11
;;
13.* | 14.*)
XCODEBUILD_TEST_BASE_TVOS+=(
-destination "platform=tvOS Simulator,name=Apple TV 4K (2nd generation),OS=latest"
)
;;
15.* | 16.*)
XCODEBUILD_TEST_BASE_TVOS+=(
-destination "platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest"
)
;;
* )
echo ""
echo "ATTENTION: Time to update the simulator targets for Xcode ${XCODE_VERSION}"
echo ""
echo "ERROR: Build aborted!"
exit 2
;;
esac
if [[ "${XCODE_QUIET}" == "yes" ]] ; then
XCODEBUILD_TEST_BASE_TVOS+=( -quiet )
fi
if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
header "Doing Xcode tvOS build/tests - Debug"
"${XCODEBUILD_TEST_BASE_TVOS[@]}" -configuration Debug test
fi
if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
header "Doing Xcode tvOS build/tests - Release"
"${XCODEBUILD_TEST_BASE_TVOS[@]}" -configuration Release test
fi
fi
if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
header "Running ObjC Conformance Tests"
${BazelBin} test //objectivec:conformance_test $BazelFlags
fi
echo ""
echo "$(basename "${0}"): Success!"
|