-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathxcode-build.sh
More file actions
executable file
·147 lines (104 loc) · 4.88 KB
/
xcode-build.sh
File metadata and controls
executable file
·147 lines (104 loc) · 4.88 KB
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
#!/bin/sh
source common.sh
function xcode_build {
BUILD_DIRECTORY=${WORKSPACE}/build
echo xcodebuild -configuration "$CONFIGURATION" -sdk "$SDK" -target "$TARGET" DSTROOT="${BUILD_DIRECTORY}" OBJROOT="${BUILD_DIRECTORY}/objects" SYMROOT="${BUILD_DIRECTORY}" SHARED_PRECOMPS_DIR="${BUILD_DIRECTORY}/shared" "$*" || fail "xcodebuild failed"
#xcodebuild -configuration "$CONFIGURATION" -sdk "$SDK" -target "$TARGET" DSTROOT="${BUILD_DIRECTORY}" OBJROOT="${BUILD_DIRECTORY}/objects" SYMROOT="${BUILD_DIRECTORY}" SHARED_PRECOMPS_DIR="${BUILD_DIRECTORY}/shared" OTHER_CODE_SIGN_FLAGS="--keychain /Users/groundkeeper/Library/Keychains/jenkins.keychain" "$*" || fail "xcodebuild failed"
xcodebuild -configuration "$CONFIGURATION" -sdk "$SDK" -target "$TARGET" DSTROOT="${BUILD_DIRECTORY}" OBJROOT="${BUILD_DIRECTORY}/objects" SYMROOT="${BUILD_DIRECTORY}" SHARED_PRECOMPS_DIR="${BUILD_DIRECTORY}/shared" "$*" || fail "xcodebuild failed"
}
if [ -z "$CONFIGURATION" ]; then
fail "Configration ERROR: CONFIGURATION missing"
exit 1
fi
if [ -z "$SDK" ]; then
fail "Configration ERROR: No SDK specified"
exit 1
fi
if [ -z "$TARGET" ]; then
fail "Configration ERROR: No TARGET specified"
exit 1
fi
#echo $WORKING_DIRECTORY;
if [ $WORKING_DIRECTORY ]; then
echo cd ${WORKING_DIRECTORY}
cd ${WORKING_DIRECTORY}
fi
section_print "Building $CONFIGURATION using sdk $SDK"
#strange way to force backslash
if [ $PROJECT_DIRECTORY ]; then
PROJECT_DIRECTORY=${PROJECT_DIRECTORY%/}
PROJECT_DIRECTORY="$PROJECT_DIRECTORY/"
section_print "Project Directory is specified and is $PROJECT_DIRECTORY"
cd "$PROJECT_DIRECTORY" || fail "no directory $PROJECT_DIRECTORY"
pwd
fi
if [ $INFO_PLIST ]; then
if [ -z "$INFO_PLIST" ]; then
INFO_PLIST=`ls *Info.plist | head -n1`
fi
INFO_PLIST=`cd "${PROJECT_DIRECTORY}" ; pwd`/${INFO_PLIST%.*}
fi
#section_print "Cleaning up previous build"
#xcode_build clean
#rm -rf "${WORKSPACE}/build"
# Modify the bundle identifier (only in build configuration Debug and bundle identifier has to be set)
if [ $CONFIGURATION = "Debug" ] && [ "$BUNDLE_IDENTIFIER" ]; then
section_print "Setting Bundle Identifer to $BUNDLE_IDENTIFIER"
# modify bundle identifier
/usr/libexec/PlistBuddy "$INFO_PLIST.plist" -c "Set :CFBundleIdentifier $BUNDLE_IDENTIFIER"
plutil -convert xml1 "$INFO_PLIST".plist
fi
# Modify bundle version for Hockey Kit builds in build configuration Debug
if [ $CONFIGURATION = "Debug" ] && [ -n "$INFO_PLIST" ]; then
section_print "Setting build number to bundle version for HockeyKit builds"
# Get version from Info.plist
BUNDLE_VERSION=`/usr/libexec/PlistBuddy "$INFO_PLIST.plist" -c "Print :CFBundleVersion"`
# Append build number to bundle version
BUNDLE_VERSION="$BUNDLE_VERSION #$BUILD_NUMBER"
/usr/libexec/PlistBuddy "$INFO_PLIST.plist" -c "Set :CFBundleVersion $BUNDLE_VERSION"
fi
section_print "Building $CONFIGURATION"
if [ -n "$PROVISIONING" ] && [ -n "$SIGN_IDENTITY" ]; then
BUILD_PARAMETERS="${BUILD_PARAMETERS} CODE_SIGN_IDENTITY=$SIGN_IDENTITY"
fi
if [ -n "$XCODE_SETTINGS" ]; then
BUILD_PARAMETERS="${BUILD_PARAMETERS} $XCODE_SETTINGS"
fi
xcode_build "${BUILD_PARAMETERS}"
#xcodebuild -sdk iphonesimulator -configuration ELO-DMS -target UnitTests TEST_AFTER_BUILD=YES
section_print "Packaging ipa"
PROJECT_DIRECTORY=${WORKSPACE}/build/${CONFIGURATION}-${SDK}
if [ ! -d "$PROJECT_DIRECTORY" ]; then
echo "No Release build found: $PROJECT_DIRECTORY"
section_print "Build Successful"
exit
fi
#printenv
APPLICATION_NAME=`ls -1 "$PROJECT_DIRECTORY" | grep ".*\.app$" | head -n1`
APPLICATION_NAME=${APPLICATION_NAME%.*}
# If command line tools are not installed in /usr/bin we need to let codesign know where to find codesign_allocate
if [ ! $CODESIGN_ALLOCATE ];
then
export CODESIGN_ALLOCATE=$(xcrun -find codesign_allocate)
fi
if [ -n "$PROVISIONING" ] && [ -n "$PROVISIONING_URL" ] && [ -n "$SIGN_IDENTITY" ]; then
section_print "Sign the Application"
xcrun -sdk "$SDK" PackageApplication -v "${PROJECT_DIRECTORY}/${APPLICATION_NAME}.app" -o "${PROJECT_DIRECTORY}/${APPLICATION_NAME}.ipa" --sign "${SIGN_IDENTITY}" --embed "${PROVISIONING}.mobileprovision"
if [ $? -gt 0 ]; then
fail "Error packaging/signing application"
fi
else
section_print "SIGN SKIPPED because PROVISIONING or SIGN_IDENTITY are not configured properly"
exit
fi
if [ -z "$VERSION_NUMBER" ]; then
APPLICATION_ID=${APPLICATION_NAME}-${BUILD_ID};
else
APPLICATION_ID=${APPLICATION_NAME}-${VERSION_NUMBER};
fi
mv "${PROJECT_DIRECTORY}/${APPLICATION_NAME}.app" "${PROJECT_DIRECTORY}/${APPLICATION_ID}.app"
mv "${PROJECT_DIRECTORY}/${APPLICATION_NAME}.app.dSYM" "${PROJECT_DIRECTORY}/${APPLICATION_ID}.app.dSYM"
mv "${PROJECT_DIRECTORY}/${APPLICATION_NAME}.ipa" "${PROJECT_DIRECTORY}/${APPLICATION_ID}.ipa"
cd "${PROJECT_DIRECTORY}"
zip -r "${APPLICATION_ID}.zip" . -i "${APPLICATION_ID}.app*"
section_print "Build Successful"