forked from hig-dev/libvideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·317 lines (274 loc) · 7.44 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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
test=1
nuget=1
samples=1
run=0
cache=0
config="Release"
verbosity="minimal"
scriptroot="$(cd "$(dirname $0)"; pwd -P)"
nugetpath="$scriptroot/NuGet.exe"
cachefile="$scriptroot/$(basename $0).cache"
targets="portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10"
osys=$(uname)
windows="$(uname | grep -E 'CYGWIN|MINGW|MSYS' 1> /dev/null; echo $?)"
msbuildprompt="Please specify the directory where MSBuild is installed.
Example: ./build.sh --msbuild \"/C/Program Files (x86)/MSBuild/14.0/Bin\""
usage="Usage: ./build.sh [OPTION]...
Options:
-c, --config [DEBUG|RELEASE] set build configuration to Debug or Release
-h, --help display this help text and exit
-m, --msbuild specify path to MSBuild.exe (required on first run)
--nocache do not cache the path to MSBuild.exe if specified
--norun build nothing unless specified by other options
-n, --nuget create NuGet package post-build
-s, --samples build all projects in the samples/ dir
-t, --test compile and run tests after libvideo.sln is built
-v, --verbosity set MSBuild verbosity, e.g. quiet"
error() {
echo "$1" 1>&2
}
usage() {
error "$usage"
}
failerr() {
exitcode=$?
if [ "$exitcode" -ne 0 ]
then
error "$1"
exit $exitcode
fi
}
project() {
if [ "$1" != "packages" -a "$1" != ".vs" -a "${1##*.}" != "sln" ]
then
return 0
fi
return 1
}
executable() {
grep "<OutputType>Exe</OutputType>" "$1/$1.csproj" &> /dev/null
return "$?"
}
nuget() {
if [ $windows -eq 0 ]
then
$nugetpath $@
else
mono $nugetpath $@
fi
}
buildproj() {
nuget restore
if [ $windows -eq 0 ]
then
"$msbuildpath" /property:Configuration=$config /verbosity:$verbosity
else
mono "$msbuildpath" /property:Configuration=$config /verbosity:$verbosity
fi
}
absolute() {
echo "$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")"
}
# get options
while [[ "$#" > 0 ]]
do
case "$1" in
-t|--test)
test=0
;;
-n|--nuget)
nuget=0
;;
-c|--config)
case "${2,,}" in
"debug")
config="Debug"
;;
"release")
# enabled by default
;;
*)
usage
exit 1
;;
esac
shift
;;
--norun)
run=1
;;
-h|--help)
usage
exit 0
;;
-m|--msbuild)
# IMPORTANT: all reads/writes to $msbuildpath MUST be quoted
# because the typical path for Windows users is in Program Files (x86).
msbuildpath="$2/MSBuild.exe"
shift
;;
--nocache)
cache=1
;;
-v|--verbosity)
case "${2,,}" in
"quiet"|"normal"|"detailed"|"diagnostic")
verbosity="${2,,}"
;;
"minimal")
# enabled by default
;;
*)
usage
exit 1
;;
esac
shift
;;
-s|--samples)
samples=0
;;
*)
usage
exit 1
;;
esac
shift
done
# check for Mono (mostly plagiarized from CoreFX)
if [ $windows -ne 0 ]
then
if [ $osys == "Linux" ]
then
monoroot=/usr
elif [ $osys == "FreeBSD" ]
then
monoroot=/usr/local
else
# OS X (Darwin)
monoroot=/Library/Frameworks/Mono.framework/Versions/Current
fi
referenceassemblyroot=$monoroot/lib/mono/xbuild-frameworks
monoversion=$(mono --version | grep "version 4.[1-9]")
if [ $? -ne 0 ]
then
# if built from tarball, Mono only identifies itself as 4.0.1
monoversion=$(mono --version | egrep "version 4.0.[1-9]+(.[0-9]+)?")
if [ $? -ne 0 ]
then
error "Mono 4.0.1.44 or later is required to build libvideo on Unix."
exit 1
else
error "WARNING: Mono 4.0.1.44 or later is required to build libvideo on Unix. Unable to assess if current version is supported."
fi
fi
if [ ! -e "$referenceassemblyroot/.NETPortable" ]
then
error "PCL reference assemblies not found! Install 'referenceassemblies-pcl' via your distro's package manager, and try again."
exit 1
fi
fi
# determine path to MSBuild.exe
if [ -z "$msbuildpath" ]
then
msbuildpath="$(cat $cachefile 2> /dev/null)"
if [ $? -ne 0 ]
then
error "$msbuildprompt"
exit 1
elif [ ! -e "$msbuildpath" ]
then
error "\"$msbuildpath\" was read from the cache, but it does not exist."
error "$msbuildprompt"
exit 1
fi
else
if [ ! -e "$msbuildpath" ]
then
error "\"$msbuildpath\" does not exist."
exit 1
fi
if [ $cache -eq 0 ]
then
msbuildpath="$(absolute "$msbuildpath")"
echo "$msbuildpath" > $cachefile
fi
fi
# restore NuGet.exe if not yet installed
# will admit I stole a few of these lines from the CoreFX build.sh...
if [ ! -e $nugetpath ]
then
echo "Restoring NuGet.exe..."
# curl has HTTPS CA trust-issues less often than wget, so try that first
which curl &> /dev/null
if [ $? -eq 0 ]; then
curl -sSL -o $nugetpath https://api.nuget.org/downloads/nuget.exe
else
which wget &> /dev/null
failerr "cURL or wget is required to build libvideo."
wget -q -O $nugetpath https://api.nuget.org/downloads/nuget.exe
fi
failerr "Failed to restore NuGet.exe."
fi
# start the actual build
if [ "$run" -eq 0 ]
then
echo "Building src..."
cd $scriptroot/src
buildproj
failerr "MSBuild failed on libvideo.sln! Exiting..."
fi
if [ "$test" -eq 0 ]
then
echo "Running tests..."
for test in $scriptroot/tests/*
do
echo "Building test $test..."
cd $test
buildproj
failerr "MSBuild failed on $test.sln! Exiting..."
for subtest in *
do
if project "$subtest" && executable "$subtest"
then
echo "Running subtest $subtest..."
cd $subtest/bin/$config
./$subtest.exe
failerr "Subtest $subtest failed! Exiting..."
fi
done
done
fi
if [ "$samples" -eq 0 ]
then
echo "Building samples..."
for sample in $scriptroot/samples/*
do
echo "Building sample $sample..."
cd $sample
buildproj
failerr "MSBuild failed on $sample.sln! Exiting..."
done
fi
if [ "$nuget" -eq 0 ]
then
echo "Creating NuGet packages..."
for packageroot in $scriptroot/nuget/*
do
package="$(basename $packageroot)"
echo "Getting assemblies for $package..."
mkdir -p $packageroot/lib/$targets
cd $scriptroot/src/$package/bin/$config
cp $package.dll $packageroot/lib/$targets
echo "Cleaning existing $package packages..."
cd $packageroot
rm *.nupkg 2> /dev/null
for spec in *.nuspec
do
echo "Packing $spec..."
nuget pack $spec
failerr "Packing $spec failed! Exiting..."
done
done
fi