-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbuild.sh
executable file
·67 lines (53 loc) · 1.67 KB
/
build.sh
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
#!/bin/bash
# Documentation:
# This script builds a <TARGET> for all provided <PLATFORMS>.
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
# You can pass in a list of <PLATFORMS> if you want to customize the build.
# Usage:
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
# e.g. `bash scripts/build.sh MyTarget iOS macOS`
# Exit immediately if a command exits with a non-zero status
set -e
# Verify that all required arguments are provided
if [ $# -eq 0 ]; then
echo "Error: This script requires at least one argument"
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
echo "For instance: $0 MyTarget iOS macOS"
exit 1
fi
# Define argument variables
TARGET=$1
# Remove TARGET from arguments list
shift
# Define platforms variable
if [ $# -eq 0 ]; then
set -- iOS macOS tvOS watchOS xrOS
fi
PLATFORMS=$@
# A function that builds $TARGET for a specific platform
build_platform() {
# Define a local $PLATFORM variable
local PLATFORM=$1
# Build $TARGET for the $PLATFORM
echo "Building $TARGET for $PLATFORM..."
if ! xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM; then
echo "Failed to build $TARGET for $PLATFORM"
return 1
fi
# Complete successfully
echo "Successfully built $TARGET for $PLATFORM"
}
# Start script
echo ""
echo "Building $TARGET for [$PLATFORMS]..."
echo ""
# Loop through all platforms and call the build function
for PLATFORM in $PLATFORMS; do
if ! build_platform "$PLATFORM"; then
exit 1
fi
done
# Complete successfully
echo ""
echo "Building $TARGET completed successfully!"
echo ""