Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit 05d259e

Browse files
committed
Add jspahrsummers/objc-build-scripts
1 parent 628f812 commit 05d259e

File tree

6 files changed

+210
-0
lines changed

6 files changed

+210
-0
lines changed

script/LICENSE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
**Copyright (c) 2013 Justin Spahr-Summers**
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

script/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
These scripts are primarily meant to support the use of
2+
[Janky](https://github.com/github/janky). To use them, read the contents of this
3+
repository into a `script` folder:
4+
5+
```
6+
$ git remote add objc-build-scripts https://github.com/jspahrsummers/objc-build-scripts.git
7+
$ git fetch objc-build-scripts
8+
$ git read-tree --prefix=script/ -u objc-build-scripts/master
9+
```
10+
11+
Then commit the changes to incorporate the scripts into your own repository's
12+
history. You can also freely tweak the scripts for your specific project's
13+
needs.
14+
15+
To bring in upstream changes later:
16+
17+
```
18+
$ git fetch -p objc-build-scripts
19+
$ git merge -Xsubtree=script objc-build-scripts/master
20+
```

script/bootstrap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(dirname "$0")
4+
cd "$SCRIPT_DIR/.."
5+
6+
set -o errexit
7+
8+
echo "*** Updating submodules..."
9+
git submodule sync --quiet
10+
git submodule update --init
11+
git submodule foreach --recursive --quiet "git submodule sync --quiet && git submodule update --init"

script/cibuild

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(dirname "$0")
4+
cd "$SCRIPT_DIR/.."
5+
6+
##
7+
## Configuration Variables
8+
##
9+
10+
# The build configuration to use.
11+
if [ -z "$XCCONFIGURATION" ]
12+
then
13+
XCCONFIGURATION="Release"
14+
fi
15+
16+
# The workspace to build.
17+
#
18+
# If not set and no workspace is found, the -workspace flag will not be passed
19+
# to xcodebuild.
20+
if [ -z "$XCWORKSPACE" ]
21+
then
22+
XCWORKSPACE=$(ls -d *.xcworkspace 2>/dev/null | head -n 1)
23+
fi
24+
25+
# A bootstrap script to run before building.
26+
#
27+
# If this file does not exist, it is not considered an error.
28+
BOOTSTRAP="$SCRIPT_DIR/bootstrap"
29+
30+
# A whitespace-separated list of default targets or schemes to build, if none
31+
# are specified on the command line.
32+
#
33+
# Individual names can be quoted to avoid word splitting.
34+
DEFAULT_TARGETS=
35+
36+
# Extra build settings to pass to xcodebuild.
37+
XCODEBUILD_SETTINGS="TEST_AFTER_BUILD=YES"
38+
39+
##
40+
## Build Process
41+
##
42+
43+
if [ -z "$*" ]
44+
then
45+
# lol recursive shell script
46+
if [ -n "$DEFAULT_TARGETS" ]
47+
then
48+
echo "$DEFAULT_TARGETS" | xargs "$SCRIPT_DIR/cibuild"
49+
else
50+
xcodebuild -list | awk -f "$SCRIPT_DIR/targets.awk" | xargs "$SCRIPT_DIR/cibuild"
51+
fi
52+
53+
exit $?
54+
fi
55+
56+
if [ -f "$BOOTSTRAP" ]
57+
then
58+
echo "*** Bootstrapping..."
59+
bash "$BOOTSTRAP" || exit $?
60+
fi
61+
62+
echo "*** The following targets will be built:"
63+
64+
for target in "$@"
65+
do
66+
echo "$target"
67+
done
68+
69+
echo "*** Cleaning all targets..."
70+
xcodebuild -alltargets clean OBJROOT="$PWD/build" SYMROOT="$PWD/build" $XCODEBUILD_SETTINGS
71+
72+
run_xcodebuild ()
73+
{
74+
local scheme=$1
75+
76+
if [ -n "$XCWORKSPACE" ]
77+
then
78+
xcodebuild -workspace "$XCWORKSPACE" -scheme "$scheme" -configuration "$XCCONFIGURATION" build OBJROOT="$PWD/build" SYMROOT="$PWD/build" $XCODEBUILD_SETTINGS
79+
else
80+
xcodebuild -scheme "$scheme" -configuration "$XCCONFIGURATION" build OBJROOT="$PWD/build" SYMROOT="$PWD/build" $XCODEBUILD_SETTINGS
81+
fi
82+
83+
local status=$?
84+
85+
return $status
86+
}
87+
88+
build_scheme ()
89+
{
90+
local scheme=$1
91+
92+
run_xcodebuild "$scheme" 2>&1 | awk -f "$SCRIPT_DIR/xcodebuild.awk"
93+
94+
local awkstatus=$?
95+
local xcstatus=${PIPESTATUS[0]}
96+
97+
if [ "$xcstatus" -eq "65" ]
98+
then
99+
# This probably means that there's no scheme by that name. Give up.
100+
echo "*** Error building scheme $scheme -- perhaps it doesn't exist"
101+
elif [ "$awkstatus" -eq "1" ]
102+
then
103+
return $awkstatus
104+
fi
105+
106+
return $xcstatus
107+
}
108+
109+
echo "*** Building..."
110+
111+
for scheme in "$@"
112+
do
113+
build_scheme "$scheme" || exit $?
114+
done

script/targets.awk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BEGIN {
2+
FS = "\n";
3+
}
4+
5+
/Targets:/ {
6+
while (getline && $0 != "") {
7+
if ($0 ~ /Tests/) continue;
8+
9+
sub(/^ +/, "");
10+
print "'" $0 "'";
11+
}
12+
}

script/xcodebuild.awk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Exit statuses:
2+
#
3+
# 0 - No errors found.
4+
# 1 - Build or test failure. Errors will be logged automatically.
5+
# 2 - Untestable target. Retry with the "build" action.
6+
7+
BEGIN {
8+
status = 0;
9+
}
10+
11+
{
12+
print;
13+
fflush(stdout);
14+
}
15+
16+
/is not valid for Testing/ {
17+
exit 2;
18+
}
19+
20+
/[0-9]+: (error|warning):/ {
21+
errors = errors $0 "\n";
22+
}
23+
24+
/(TEST|BUILD) FAILED/ {
25+
status = 1;
26+
}
27+
28+
END {
29+
if (length(errors) > 0) {
30+
print "\n*** All errors:\n" errors;
31+
}
32+
33+
fflush(stdout);
34+
exit status;
35+
}

0 commit comments

Comments
 (0)