-
Notifications
You must be signed in to change notification settings - Fork 7
/
icebuilder
executable file
·210 lines (180 loc) · 5.49 KB
/
icebuilder
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#
set -eo pipefail
readonly ICE_BUILDER_XCODE_VERSION=3.1.0
logDebug()
{
[ -z "$DEBUG" ] || echo "$*"
}
logError()
{
echo "$*" >&2
}
calledFromXcode()
{
if [[ -z $XCODE_PRODUCT_BUILD_VERSION || -z $DERIVED_FILE_DIR || -z $INPUT_FILE_PATH ]]; then
return 1
fi
return 0
}
# Run slice sliceCompiler. We always include Ice slice file directory as well as the INPUT_FILE_DIR.
compileSliceFile()
{
logDebug "Compiling slice file: $INPUT_FILE_NAME"
set -x # print the executed slice compiler command
$sliceCompiler -I"$INPUT_FILE_DIR" \
-I"$sliceDir" \
--output-dir "$outputDir" \
"${sliceCompilerArguments[@]}" \
"$INPUT_FILE_PATH"
}
# Output directory is detected by comparing the SCRIPT_OUTPUT_FILE_{0,1} variables.
# These are expected to the be the destination of the slice compiler generated header
# and source files. Both files must share the same base directory, as this is how we
# determine the output directory to pass to the slice compiler.
setOutputDir()
{
if [ "$SCRIPT_OUTPUT_FILE_COUNT" -ne 2 ]; then
logError "Please specify a header and source output file."
return 1
fi
local -r outputFile0=${SCRIPT_OUTPUT_FILE_0}
logDebug "Output file 0: $outputFile0"
local -r outputFile1=${SCRIPT_OUTPUT_FILE_1}
logDebug "Output file 1: $outputFile1"
local -r outputFileDir0=$(dirname "$outputFile0")
local -r outputFileDir1=$(dirname "$outputFile1")
if [ "$outputFileDir0" != "$outputFileDir1" ]; then
logError "Output files must be in the same directory."
return 1
fi
outputDir="$outputFileDir0"
}
main()
{
if ! calledFromXcode; then
logError "Ice Builder for Xcode must be executed from an Xcode environment."
exit 0
fi
if ! setOutputDir; then
exit 1
fi
# Always check user specified Ice home. Fail if the specified
# directory does not exist or is not a valid Ice installation
if [ -n "$iceHome" ]; then
if ! setIceHomeDir "$iceHome"; then
logError "${iceHome} is not a valid Ice distribution."
exit 1
fi
else
# Try the following in order:
# 1. Search $ADDITIONAL_SDK_DIRS for a IceTouch-like SDK layout
# 2. Search for an Ice installation in `/usr/local`
if setIceSDKDir; then
logDebug "Ice SDK (absolute path): $iceSDKDir"
elif setIceHomeDir '/usr/local'; then
logDebug "Ice Home: $iceHomeDir"
else
logError "Unable to find valid Ice, Ice SDK, or Ice Touch distribution."
exit 1
fi
fi
readonly iceVersion=$("$sliceCompiler" -v 2>&1)
logDebug "Ice version: $iceVersion"
compileSliceFile
}
# Check if given directory is a valid Ice installation and set required variables
setIceHomeDir()
{
iceHomeDir="$1"
# source build
sliceDir="${iceHomeDir}/slice"
sliceCompiler="${iceHomeDir}/cpp/bin/slice2${language}"
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0
# "usr" style install
sliceDir="${iceHomeDir}/share/ice/slice"
sliceCompiler="${iceHomeDir}/bin/slice2${language}"
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0
# "opt" style install
sliceDir="${iceHomeDir}/slice"
sliceCompiler="${iceHomeDir}/bin/slice2${language}"
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0
# Unable to find Ice home; unset variables
iceHomeDir=
sliceDir=
sliceCompiler=
return 1
}
# Find SDK from ADDITIONAL_SDK_DIRS and set required variables
setIceSDKDir()
{
for sdk in $ADDITIONAL_SDK_DIRS
do
local -r sdkDir=$(dirname "$sdk")
# IceTouch == IceTouch 1.3 and 3.6
# IceSDK == Ice 3.7 beta
if [[ "$sdk" =~ "IceTouch" ]] || [[ "$sdk" =~ "IceSDK" ]]; then
iceSDKDir="$sdk"
sliceDir="${sdkDir}/slice" # Slice file directory included the SDK
sliceCompiler="${sdkDir}/bin/slice2${language}" # Either 'slice2cpp' or 'slice2objc'
# Check that the slice directory exists, and that the slice compiler exists and is executable
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0
fi
done
# Unable to find Ice SDK; unset variables
iceSDKDir=
sliceDir=
sliceCompiler=
return 1
}
printUsage()
{
cat <<EOF
Usage: $(basename "$0") [options] [-- <slice compiler flags>]
Options:
-h, --help Show this message.
-v, --version Display Ice Builder for Xcode version.
--cpp Use slice2cpp. Default is slice2objc.
--ice-home Location of Ice install.
-- ARGS Pass agruments directly to the slice compiler.
EOF
}
#
# Process arguments and run slice compiler
#
logDebug "Ice Builder for Xcode version: $ICE_BUILDER_XCODE_VERSION"
sliceCompilerArguments=()
language=objc
while [[ $# -gt 0 ]]; do
opt="$1"
case $opt in
--cpp)
language=cpp
;;
-h|--help)
printUsage
exit
;;
--ice-home)
shift
iceHome="$1"
;;
-v|--version)
echo "$ICE_BUILDER_XCODE_VERSION"
exit
;;
--)
shift
sliceCompilerArguments=("$@")
break
;;
*)
logError "Unknown option: '$opt'"
exit 1
;;
esac
shift
done
main