mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
160 lines
3.4 KiB
Bash
Executable File
160 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
export SCRIPT_DIR=$(dirname "$0")
|
|
|
|
##
|
|
## Configuration Variables
|
|
##
|
|
|
|
SCHEMES="$@"
|
|
|
|
config ()
|
|
{
|
|
# The workspace to build.
|
|
#
|
|
# If not set and no workspace is found, the -workspace flag will not be passed
|
|
# to `xctool`.
|
|
#
|
|
# Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will
|
|
# take precedence.
|
|
: ${XCWORKSPACE=$(find_pattern "*.xcworkspace")}
|
|
|
|
# The project to build.
|
|
#
|
|
# If not set and no project is found, the -project flag will not be passed
|
|
# to `xctool`.
|
|
#
|
|
# Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will
|
|
# take precedence.
|
|
: ${XCODEPROJ=$(find_pattern "*.xcodeproj")}
|
|
|
|
# A bootstrap script to run before building.
|
|
#
|
|
# If this file does not exist, it is not considered an error.
|
|
: ${BOOTSTRAP="$SCRIPT_DIR/bootstrap"}
|
|
|
|
# Extra options to pass to xctool.
|
|
: ${XCTOOL_OPTIONS="RUN_CLANG_STATIC_ANALYZER=NO"}
|
|
|
|
# A whitespace-separated list of default schemes to build.
|
|
#
|
|
# Individual names can be quoted to avoid word splitting.
|
|
: ${SCHEMES:=$(xcodebuild -list -project "$XCODEPROJ" 2>/dev/null | awk -f "$SCRIPT_DIR/schemes.awk")}
|
|
|
|
export XCWORKSPACE
|
|
export XCODEPROJ
|
|
export BOOTSTRAP
|
|
export XCTOOL_OPTIONS
|
|
export SCHEMES
|
|
}
|
|
|
|
##
|
|
## Build Process
|
|
##
|
|
|
|
main ()
|
|
{
|
|
config
|
|
|
|
if [ -f "$BOOTSTRAP" ]
|
|
then
|
|
echo "*** Bootstrapping..."
|
|
"$BOOTSTRAP" || exit $?
|
|
fi
|
|
|
|
echo "*** Prebuilding OpenSSL"
|
|
$SCRIPT_DIR/update_libssl_ios
|
|
|
|
echo "*** The following schemes will be built:"
|
|
echo "$SCHEMES" | xargs -n 1 echo " "
|
|
echo
|
|
|
|
echo "$SCHEMES" | xargs -n 1 | (
|
|
local status=0
|
|
|
|
while read scheme
|
|
do
|
|
build_scheme "$scheme" || status=1
|
|
done
|
|
|
|
exit $status
|
|
)
|
|
}
|
|
|
|
find_pattern ()
|
|
{
|
|
ls -d $1 2>/dev/null | head -n 1
|
|
}
|
|
|
|
run_xctool ()
|
|
{
|
|
if [ -n "$XCWORKSPACE" ]
|
|
then
|
|
xctool -workspace "$XCWORKSPACE" $XCTOOL_OPTIONS "$@" \
|
|
ONLY_ACTIVE_ARCH=NO \
|
|
CODE_SIGN_IDENTITY="" \
|
|
CODE_SIGNING_REQUIRED=NO 2>&1
|
|
elif [ -n "$XCODEPROJ" ]
|
|
then
|
|
xctool -project "$XCODEPROJ" $XCTOOL_OPTIONS "$@" \
|
|
ONLY_ACTIVE_ARCH=NO \
|
|
CODE_SIGN_IDENTITY="" \
|
|
CODE_SIGNING_REQUIRED=NO 2>&1
|
|
else
|
|
echo "*** No workspace or project file found."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
parse_build ()
|
|
{
|
|
awk -f "$SCRIPT_DIR/xctool.awk" 2>&1 >/dev/null
|
|
}
|
|
|
|
build_scheme ()
|
|
{
|
|
local scheme=$1
|
|
|
|
echo "*** Building and testing $scheme..."
|
|
echo
|
|
|
|
local sdkflags=()
|
|
local action=test
|
|
|
|
# Determine whether we can run unit tests for this target.
|
|
run_xctool -scheme "$scheme" run-tests | parse_build
|
|
|
|
local awkstatus=$?
|
|
|
|
if [ "$awkstatus" -eq "1" ]
|
|
then
|
|
# SDK not found, try for iphonesimulator.
|
|
sdkflags=(-sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 5")
|
|
|
|
# Determine whether the unit tests will run with iphonesimulator
|
|
run_xctool "${sdkflags[@]}" -scheme "$scheme" run-tests | parse_build
|
|
|
|
awkstatus=$?
|
|
|
|
if [ "$awkstatus" -ne "0" ]
|
|
then
|
|
# Unit tests will not run on iphonesimulator.
|
|
sdkflags=()
|
|
fi
|
|
fi
|
|
|
|
if [ "$awkstatus" -ne "0" ]
|
|
then
|
|
# Unit tests aren't supported.
|
|
action=build
|
|
fi
|
|
|
|
run_xctool "${sdkflags[@]}" -scheme "$scheme" $action
|
|
}
|
|
|
|
export -f build_scheme
|
|
export -f run_xctool
|
|
export -f parse_build
|
|
|
|
main
|