2015-05-21 21:14:52 +00:00
|
|
|
#!/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}/../.."
|
|
|
|
|
|
|
|
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.
|
|
|
|
-a, --autogen
|
|
|
|
Start by rerunning autogen & configure.
|
2016-04-19 21:57:17 +00:00
|
|
|
-r, --regenerate-descriptors
|
|
|
|
Run generate_descriptor_proto.sh to regenerate all the checked in
|
|
|
|
proto sources.
|
2015-05-21 21:14:52 +00:00
|
|
|
-j #, --jobs #
|
|
|
|
Force the number of parallel jobs (useful for debugging build issues).
|
2015-11-04 22:26:03 +00:00
|
|
|
--core-only
|
|
|
|
Skip some of the core protobuf build/checks to shorten the build time.
|
2015-05-21 21:14:52 +00:00
|
|
|
--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.
|
2016-05-24 15:27:33 +00:00
|
|
|
--skip-xcode-debug
|
|
|
|
Skip the Xcode Debug configuration.
|
|
|
|
--skip-xcode-release
|
|
|
|
Skip the Xcode Release configuration.
|
2015-05-21 21:14:52 +00:00
|
|
|
--skip-xcode-osx
|
|
|
|
Skip the invoke of Xcode to test the runtime on OS X.
|
2015-11-17 15:18:49 +00:00
|
|
|
--skip-objc-conformance
|
|
|
|
Skip the Objective C conformance tests (run on OS X).
|
2016-12-08 19:53:04 +00:00
|
|
|
--xcode-quiet
|
|
|
|
Pass -quiet to xcodebuild.
|
2015-05-21 21:14:52 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
header() {
|
|
|
|
echo ""
|
|
|
|
echo "========================================================================"
|
|
|
|
echo " ${@}"
|
|
|
|
echo "========================================================================"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Thanks to libtool, builds can fail in odd ways and since it eats some output
|
|
|
|
# it can be hard to spot, so force error output if make exits with a non zero.
|
|
|
|
wrapped_make() {
|
|
|
|
set +e # Don't stop if the command fails.
|
|
|
|
make $*
|
|
|
|
MAKE_EXIT_STATUS=$?
|
|
|
|
if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then
|
|
|
|
echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}"
|
|
|
|
exit ${MAKE_EXIT_STATUS}
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu)
|
2016-05-24 15:27:33 +00:00
|
|
|
if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then
|
|
|
|
NUM_MAKE_JOBS=2
|
2015-05-21 21:14:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
DO_AUTOGEN=no
|
|
|
|
DO_CLEAN=no
|
2016-04-19 21:57:17 +00:00
|
|
|
REGEN_DESCRIPTORS=no
|
2015-11-04 22:26:03 +00:00
|
|
|
CORE_ONLY=no
|
2015-05-21 21:14:52 +00:00
|
|
|
DO_XCODE_IOS_TESTS=yes
|
|
|
|
DO_XCODE_OSX_TESTS=yes
|
2016-05-24 15:27:33 +00:00
|
|
|
DO_XCODE_DEBUG=yes
|
|
|
|
DO_XCODE_RELEASE=yes
|
2015-11-17 15:18:49 +00:00
|
|
|
DO_OBJC_CONFORMANCE_TESTS=yes
|
2016-12-08 19:53:04 +00:00
|
|
|
XCODE_QUIET=no
|
2015-05-21 21:14:52 +00:00
|
|
|
while [[ $# != 0 ]]; do
|
|
|
|
case "${1}" in
|
|
|
|
-h | --help )
|
|
|
|
printUsage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-c | --clean )
|
|
|
|
DO_CLEAN=yes
|
|
|
|
;;
|
|
|
|
-a | --autogen )
|
|
|
|
DO_AUTOGEN=yes
|
|
|
|
;;
|
2016-04-19 21:57:17 +00:00
|
|
|
-r | --regenerate-descriptors )
|
|
|
|
REGEN_DESCRIPTORS=yes
|
2015-05-21 21:14:52 +00:00
|
|
|
;;
|
|
|
|
-j | --jobs )
|
|
|
|
shift
|
|
|
|
NUM_MAKE_JOBS="${1}"
|
|
|
|
;;
|
2015-11-04 22:26:03 +00:00
|
|
|
--core-only )
|
|
|
|
CORE_ONLY=yes
|
|
|
|
;;
|
2015-05-21 21:14:52 +00:00
|
|
|
--skip-xcode )
|
|
|
|
DO_XCODE_IOS_TESTS=no
|
|
|
|
DO_XCODE_OSX_TESTS=no
|
|
|
|
;;
|
|
|
|
--skip-xcode-ios )
|
|
|
|
DO_XCODE_IOS_TESTS=no
|
|
|
|
;;
|
|
|
|
--skip-xcode-osx )
|
|
|
|
DO_XCODE_OSX_TESTS=no
|
|
|
|
;;
|
2016-05-24 15:27:33 +00:00
|
|
|
--skip-xcode-debug )
|
|
|
|
DO_XCODE_DEBUG=no
|
|
|
|
;;
|
|
|
|
--skip-xcode-release )
|
|
|
|
DO_XCODE_RELEASE=no
|
|
|
|
;;
|
2015-11-17 15:18:49 +00:00
|
|
|
--skip-objc-conformance )
|
|
|
|
DO_OBJC_CONFORMANCE_TESTS=no
|
|
|
|
;;
|
2016-12-08 19:53:04 +00:00
|
|
|
--xcode-quiet )
|
|
|
|
XCODE_QUIET=yes
|
|
|
|
;;
|
2015-05-21 21:14:52 +00:00
|
|
|
-*)
|
|
|
|
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.
|
2015-11-04 20:10:49 +00:00
|
|
|
cd "${ProtoRootDir}"
|
2015-05-21 21:14:52 +00:00
|
|
|
|
|
|
|
# if no Makefile, force the autogen.
|
|
|
|
if [[ ! -f Makefile ]] ; then
|
|
|
|
DO_AUTOGEN=yes
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${DO_AUTOGEN}" == "yes" ]] ; then
|
|
|
|
header "Running autogen & configure"
|
|
|
|
./autogen.sh
|
2015-12-02 16:48:14 +00:00
|
|
|
./configure \
|
|
|
|
CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function" \
|
|
|
|
CXXFLAGS="-Wnon-virtual-dtor -Woverloaded-virtual"
|
2015-05-21 21:14:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${DO_CLEAN}" == "yes" ]] ; then
|
|
|
|
header "Cleaning"
|
|
|
|
wrapped_make clean
|
|
|
|
if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
|
|
|
|
XCODEBUILD_CLEAN_BASE_IOS=(
|
|
|
|
xcodebuild
|
|
|
|
-project objectivec/ProtocolBuffers_iOS.xcodeproj
|
|
|
|
-scheme ProtocolBuffers
|
|
|
|
)
|
2016-05-24 15:27:33 +00:00
|
|
|
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
|
2015-05-21 21:14:52 +00:00
|
|
|
fi
|
|
|
|
if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
|
|
|
|
XCODEBUILD_CLEAN_BASE_OSX=(
|
|
|
|
xcodebuild
|
|
|
|
-project objectivec/ProtocolBuffers_OSX.xcodeproj
|
|
|
|
-scheme ProtocolBuffers
|
|
|
|
)
|
2016-05-24 15:27:33 +00:00
|
|
|
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
|
2015-05-21 21:14:52 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-04-19 21:57:17 +00:00
|
|
|
if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then
|
|
|
|
header "Regenerating the descriptor sources."
|
2015-05-21 21:14:52 +00:00
|
|
|
./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
|
|
|
|
fi
|
|
|
|
|
2015-11-04 22:26:03 +00:00
|
|
|
if [[ "${CORE_ONLY}" == "yes" ]] ; then
|
|
|
|
header "Building core Only"
|
|
|
|
wrapped_make -j "${NUM_MAKE_JOBS}"
|
|
|
|
else
|
|
|
|
header "Building"
|
|
|
|
# Can't issue these together, when fully parallel, something sometimes chokes
|
|
|
|
# at random.
|
|
|
|
wrapped_make -j "${NUM_MAKE_JOBS}" all
|
|
|
|
wrapped_make -j "${NUM_MAKE_JOBS}" check
|
|
|
|
# Fire off the conformance tests also.
|
|
|
|
cd conformance
|
2015-11-17 15:18:49 +00:00
|
|
|
wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
|
2015-11-04 22:26:03 +00:00
|
|
|
cd ..
|
|
|
|
fi
|
2015-05-21 21:14:52 +00:00
|
|
|
|
2016-04-19 21:57:17 +00:00
|
|
|
# Ensure the WKT sources checked in are current.
|
|
|
|
objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}"
|
2015-05-21 21:14:52 +00:00
|
|
|
|
|
|
|
header "Checking on the ObjC Runtime Code"
|
|
|
|
objectivec/DevTools/pddm_tests.py
|
|
|
|
if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
|
|
|
|
echo ""
|
|
|
|
echo "Update by running:"
|
|
|
|
echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-12-08 19:53:04 +00:00
|
|
|
readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
|
|
|
|
readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
|
|
|
|
|
2015-05-21 21:14:52 +00:00
|
|
|
if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
|
|
|
|
XCODEBUILD_TEST_BASE_IOS=(
|
|
|
|
xcodebuild
|
|
|
|
-project objectivec/ProtocolBuffers_iOS.xcodeproj
|
|
|
|
-scheme ProtocolBuffers
|
|
|
|
)
|
2016-12-08 19:53:04 +00:00
|
|
|
if [[ "${XCODE_QUIET}" == "yes" ]] ; then
|
|
|
|
XCODEBUILD_TEST_BASE_IOS+=( -quiet )
|
|
|
|
fi
|
2015-11-04 22:26:03 +00:00
|
|
|
# Don't need to worry about form factors or retina/non retina;
|
|
|
|
# just pick a mix of OS Versions and 32/64 bit.
|
|
|
|
# NOTE: Different Xcode have different simulated hardware/os support.
|
|
|
|
case "${XCODE_VERSION}" in
|
|
|
|
6.* )
|
2016-10-03 15:20:54 +00:00
|
|
|
echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2
|
2015-12-10 20:49:53 +00:00
|
|
|
exit 10
|
2015-11-04 22:26:03 +00:00
|
|
|
;;
|
2016-10-03 15:20:54 +00:00
|
|
|
7.* )
|
|
|
|
echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2
|
|
|
|
echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
|
|
|
|
exit 11
|
2015-11-04 22:26:03 +00:00
|
|
|
;;
|
2016-10-03 15:20:54 +00:00
|
|
|
8.0* )
|
|
|
|
# The 8.* device seem to hang and never start under Xcode 8.
|
2016-04-06 19:29:52 +00:00
|
|
|
XCODEBUILD_TEST_BASE_IOS+=(
|
2016-10-03 15:20:54 +00:00
|
|
|
-destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit
|
|
|
|
-destination "platform=iOS Simulator,name=iPhone 7,OS=10.0" # 64bit
|
2016-02-16 14:19:50 +00:00
|
|
|
)
|
|
|
|
;;
|
2017-11-15 04:00:02 +00:00
|
|
|
8.[1-3]* )
|
2017-03-29 15:02:51 +00:00
|
|
|
XCODEBUILD_TEST_BASE_IOS+=(
|
2017-10-03 00:13:59 +00:00
|
|
|
-destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
|
|
|
|
-destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
|
|
|
|
)
|
|
|
|
;;
|
2017-12-18 15:35:38 +00:00
|
|
|
9.[0-2]* )
|
2017-10-03 00:13:59 +00:00
|
|
|
XCODEBUILD_TEST_BASE_IOS+=(
|
2017-03-29 15:02:51 +00:00
|
|
|
-destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
|
2017-08-07 15:34:48 +00:00
|
|
|
-destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
|
2017-12-18 15:35:38 +00:00
|
|
|
# 9.0-9.2 all seem to often fail running destinations in parallel
|
2017-11-15 04:00:02 +00:00
|
|
|
-disable-concurrent-testing
|
2017-03-29 15:02:51 +00:00
|
|
|
)
|
|
|
|
;;
|
2015-11-04 22:26:03 +00:00
|
|
|
* )
|
|
|
|
echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
2016-05-24 15:27:33 +00:00
|
|
|
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
|
2015-05-21 21:14:52 +00:00
|
|
|
# Don't leave the simulator in the developer's face.
|
2017-11-15 04:00:02 +00:00
|
|
|
killall Simulator 2> /dev/null || true
|
2015-05-21 21:14:52 +00:00
|
|
|
fi
|
|
|
|
if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
|
|
|
|
XCODEBUILD_TEST_BASE_OSX=(
|
|
|
|
xcodebuild
|
|
|
|
-project objectivec/ProtocolBuffers_OSX.xcodeproj
|
|
|
|
-scheme ProtocolBuffers
|
|
|
|
# Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
|
|
|
|
-destination "platform=OS X,arch=x86_64" # 64bit
|
|
|
|
)
|
2016-12-08 19:53:04 +00:00
|
|
|
if [[ "${XCODE_QUIET}" == "yes" ]] ; then
|
|
|
|
XCODEBUILD_TEST_BASE_OSX+=( -quiet )
|
|
|
|
fi
|
2016-10-03 15:20:54 +00:00
|
|
|
case "${XCODE_VERSION}" in
|
|
|
|
6.* )
|
|
|
|
echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2
|
|
|
|
exit 10
|
|
|
|
;;
|
|
|
|
7.* )
|
|
|
|
echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2
|
|
|
|
echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
|
|
|
|
exit 11
|
|
|
|
;;
|
|
|
|
esac
|
2016-05-24 15:27:33 +00:00
|
|
|
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
|
2015-05-21 21:14:52 +00:00
|
|
|
fi
|
2015-11-17 15:18:49 +00:00
|
|
|
|
|
|
|
if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
|
2016-05-24 15:27:33 +00:00
|
|
|
header "Running ObjC Conformance Tests"
|
2015-11-17 15:18:49 +00:00
|
|
|
cd conformance
|
|
|
|
wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
|
|
|
|
cd ..
|
|
|
|
fi
|