-
Notifications
You must be signed in to change notification settings - Fork 85
/
build
executable file
·266 lines (230 loc) · 9.15 KB
/
build
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/sh
# I build Snap4Arduino for several platforms.
# If I fail, you may need to run the prepare script first.
# Check out prepare --help for instructions
# Include print_utils
. ./print_utils
print_help() {
echo "Usage: ./build [OPTIONS]"
echo
echo "--platform=TARGET Selects a platform. Accepts both generic platform names"
echo " (all, mobile, desktop, desktop/gnu) and specific names"
echo " (desktop/gnu/64). See --help=platform for details."
echo
echo "--run Builds and runs Snap4Arduino for the specified architecture."
echo " Only for desktop GNU/Linux and Android."
echo
echo "--adbdebug Prints ADB debug information related to the Snap4Arduino pkg."
echo " Only for Android."
echo
echo "--makeinstaller Attempts to create an installer for the Microsoft Windows"
echo " versions. Needs Inno Setup, check prepare script for info."
echo
echo "--rerun Runs the last built version of Snap4Arduino, if it exists."
echo " Only for desktop GNU/Linux."
echo
echo "--keeptmp Do not remove the temporal build directory afterwards."
echo
echo "--pack Compresses the resulting files into a properly named"
echo " package."
echo
echo "--deploy=URL Tries to deploy the built version(s) to a server."
echo " Implicitly runs --pack."
echo
echo " --username=USERNAME Specifies a username for the deploy"
echo " server."
echo " --password=PASSWD Specifies a password for that user."
echo
}
print_help_platforms() {
echo "Usage: ./build --platform=TARGET [--run] [--deploy=URL --username=USERNAME [--dir=PATH]]"
echo
echo "Available platforms are:"
echo "`find src/platforms -follow -name '*.buildme*' | sed -E 's|/[^/]+$||' | cut -c 15-`"
echo
echo "Generic names are also accepted, such as:"
echo "desktop"
echo "desktop/gnu"
echo "mobile"
echo "this"
echo "all"
}
if test $# -eq 0; then
print_help
fi
# parse parameters
while echo $1 | grep ^- > /dev/null; do eval $( echo $1 | sed 's/-//g' | sed 's/=.*//g' | tr -d '\012')=$( echo $1 | sed 's/.*=//g' | tr -d '\012'); shift; done
if test -n "$help"; then
if test "$help" = "platform"; then
print_help_platforms
else
print_help
fi
fi
allplatforms=`find src/platforms -follow -name '*.buildme*' | sed -E 's|/[^/]+$||' | cut -c 15-`
if test -n "$platform"; then
# Placeholder platform names
if test "$platform" = "all"; then
platform=""
elif test "$platform" = "this"; then
if test `arch` = "x86_64" > /dev/null; then
platform="desktop/gnu/64"
elif test `arch` = "i386" > /dev/null; then
platform="desktop/gnu/32"
else
echo "--platform=this only works under GNU/Linux systems"
fi
fi
platforms=`echo "$allplatforms" | grep "$platform"`
fi
# build script functions
build() {
echo "Will build for the following platforms:\n\n$platforms"
for each in $platforms; do
echo
echo "======="
echo "Building for $each..."
echo "======="
echo
rm -rf tmp
echo "Fetching Snap! sources..."
if ! cp -R src/snap tmp; then
print_error "Could not find Snap! sources.\nPlease run prepare --snap first."
exit 1
fi
echo "Fetching Snap4Arduino examples..."
cp -R src/Examples/*.xml tmp/Examples
cat src/Examples/EXAMPLES >> tmp/Examples/EXAMPLES
echo "Fetching Snap4Arduino libraries..."
cp -R src/libraries/*.xml tmp/libraries
cat src/libraries/LIBRARIES >> tmp/libraries/LIBRARIES
echo "Fetching Snap4Arduino Costumes..."
cp -R src/Costumes/*.png tmp/Costumes
cp -R src/Costumes/*.svg tmp/Costumes
cat src/Costumes/COSTUMES >> tmp/Costumes/COSTUMES
cat src/Costumes/COSTUMES >> tmp/Costumes/COSTUMES-full
echo "Fetching Snap4Arduino core..."
if ! cp -R src/s4a tmp; then
print_error "Could not find Snap4Arduino core. Please make sure a src/s4a exists and contains the Snap4Arduino core files."
exit 1
fi
echo "Fetching platform-specific sources..."
if ! cp -R -L src/platforms/$each/root/* tmp; then
print_warning "Could not find any platform-specific files for $each."
fi
echo "Fetching assets..."
if ! cp assets/s4a.ico tmp; then
print_warning "Could not find Snap4Arduino icon."
fi
if ! cp assets/s4a_logo_sm.png tmp; then
print_warning "Could not find Snap4Arduino logo file."
fi
echo "Fetching version file..."
if ! cp src/version tmp; then
print_warning "Could not find version file. This may cause the build script to fail further ahead!"
fi
echo "Running platform-specifig build script..."
src/platforms/$each/build $each $makeinstaller
platform_build_result=$?
if ! test -n "$keeptmp"; then
echo "Removing temporary files..."
rm -rf tmp
fi
echo "Copying license file over..."
cp LICENSE releases/$each
if test $platform_build_result = 0; then # no errors occurred during platform-specific build
print_ok "Done!"
else
print_warning "Platform-specific build script for $each returned an error!\nBuild process may not have been successful!"
fi
done
}
run() {
if test "$platform" = "mobile/android"; then
if ! test -e releases/mobile/android/Snap4Arduino.apk; then
print_error "Failed to run Snap4Arduino for Android. Make sure your device is in USB debug mode, connected to this computer (check the output of adb devices), and the APK has been properly built and placed into releases/mobile/android/Snap4Arduino.apk"
exit 1
else
adb uninstall arduino.org.snap4arduino
adb install -r releases/mobile/android/Snap4Arduino.apk
adb shell monkey -p arduino.org.snap4arduino -c android.intent.category.LAUNCHER 1
if test -n "$adbdebug"; then
adb logcat | grep arduino
fi
fi
elif test "$platform" = "desktop/osx/64" && test `uname -m` = "x86_64" > /dev/null; then
if ! open -a Snap4Arduino.app "releases/desktop/osx/64/"; then
print_error "Failed to run Snap4Arduino for x86_64. System reported this is an `arch` machine.\nMake sure Snap4Arduino has been built first.\nSee build --help for details."
exit 1
fi
elif test "$platform" = "desktop/gnu/64" || test `arch` = "x86_64" > /dev/null; then
if ! releases/desktop/gnu/64/run; then
print_error "Failed to run Snap4Arduino for x86_64. System reported this is an `arch` machine.\nMake sure Snap4Arduino has been built first.\nSee build --help for details."
exit 1
fi
elif test "$platform" = "desktop/gnu/32" || test `arch` = "i386" > /dev/null; then
if ! releases/desktop/gnu/32/run; then
print_error "Failed to run Snap4Arduino for i386. System reported this is an `arch` machine.\nMake sure Snap4Arduino has been built first.\nSee build --help for details."
exit 1
fi
else
print_error "Auto-running is not supported for your current architecture or operating system.\rYour system reports this is an `arch` machine. This script can only auto-run for x86_64 and i386 under GNU/Linux.\nIn other systems, please build Snap4Arduino by using\n./build --platform=TARGET\nand then manually navigate to the releases directory."
fi
}
pack() {
version=`cat src/version`
mkdir -p releases/packages
for each in $platforms; do
echo "Packing $each version"
cd releases/$each
name='Snap4Arduino_'`echo "$each" | sed -E "s/\//-/g"`"_$version"
if echo "$each" | grep win && test -n "$makeinstaller"; then
filename=$name.zip
zip $filename Snap4Arduino-$version*.exe
elif echo "$each" | grep gnu; then
filename=$name.tar.gz
mkdir ../$name
cp -R * ../$name
mv ../$name .
tar -czf $filename $name
rm -rf $name
else
filename=$name.zip
mkdir ../$name
cp -R * ../$name
mv ../$name .
zip -r $filename $name
rm -rf $name
fi
cd -
mv releases/$each/$filename releases/packages
done
}
deploy() {
# not yet working!
for each in $platforms; do
curl -T releases/$each/* ftp://$deploy --user $user:secret
done
}
# parameter assessing
if test -n "$rerun"; then
run=$rerun
run
exit 0
fi
if test -n "$run"; then
build
run
exit 0
fi
if test -n "$platforms"; then
build
fi
if test -n "$deploy"; then
pack
deploy
exit 0
fi
if test -n "$pack"; then
pack
fi