forked from dkrahmer/MediaTester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
342 lines (299 loc) · 7.64 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/bash
set -e
EchoInColor()
{
str="$1"
color="$2"
if [[ "$color" == "" ]]; then
color="0;32"
fi
color="\033[${color}m"
if [[ "$ENABLE_ANSI" == "true" ]]; then
echo -e "${color}${str}\033[0m"
else
echo -e "${str}"
fi
}
ProgressStart()
{
if [[ "${SHOW_EXTRA_INFO}" != "true" ]]; then
return
fi
EchoInColor "$(date '+%Y-%m-%d %H:%M:%S') - Starting: $1..." "0;32"
}
ProgressEnd()
{
if [[ "${SHOW_EXTRA_INFO}" != "true" ]]; then
return
fi
EchoInColor "$(date '+%Y-%m-%d %H:%M:%S') - Finished: $1" "0;32"
echo -e ""
}
GetFirstFile()
{
while [[ $# -gt 0 ]]
do
local filePath="$1"
if [[ -f "$filePath" ]]; then
echo "$filePath"
return
fi
shift
done
echo ""
return
}
Initialize()
{
local progressName="Initialize"
ProgressStart "$progressName"
SlnFile="MediaTester.sln"
if [[ "$IS_BUILD" == "true" ]] && [[ "$MSBuildPath" == "" ]]; then
# List of MSBuild paths. Preferred paths listed first.
MSBuildPath=$(GetFirstFile \
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" \
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe" \
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" \
)
if [[ "${MSBuildPath}" == "" ]]; then
echo "Could not find MSBuild.exe in any expected paths."
echo "Ensure MS Build Tools or Visual Studio Professional is installed. (MSBuild 16.* required / VS2019)"
exit 1
fi
echo "Using MSBuild: ${MSBuildPath}"
fi
if [[ "$ENABLE_UNIT_TESTS" == "true" ]]; then
# List of \vstest.console.exe paths. Preferred paths listed first.
VsTestPath=$(GetFirstFile \
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" \
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" \
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" \
)
if [[ "${VsTestPath}" == "" ]]; then
echo "Could not find vstest.console.exe in any expected paths."
echo "Ensure MS Build Tools or Visual Studio is installed."
exit 1
fi
echo "Using VsTest: ${VsTestPath}"
fi
ProgressEnd "$progressName"
}
RunSolutionTarget()
{
local slnFile="$1"
local target="$2"
local msBuildPath="$3"
local progressName="${target} solution '${slnFile}'"
ProgressStart "$progressName"
# -m for parallel build
"${msBuildPath}" "${slnFile}" -m -target:${target} -property:Configuration=Release
ProgressEnd "$progressName"
}
# main
if [ $# -eq 0 ]; then
echo "No arguments provided!"
echo " Use '--all --release' for production release build."
echo " Valid arguments:"
echo " --all Build all."
#echo " Unit tests will be run automatically."
#echo " --test Run unit tests without building."
#echo " Release build only."
#echo " Add '-framework' or '-core' for specific targets."
echo " --no-clean Skip the clean step before building."
echo " Unchanged projects will not be rebuilt."
#echo " --no-test Disable running any unit tests."
echo " --no-ansi Do not output ANSI color sequences."
echo " Useful for clean log output or non-ANSI terminals."
echo " --log-file Override default build output log file."
echo " Usage: --log-file [path/filename]"
echo ""
exit 1
fi
POSITIONAL=()
dateStr=$(date '+%Y-%m-%d_%H%M%S')
OUTPUT_DIRECTORY="_output/"
mkdir -p "$OUTPUT_DIRECTORY"
BUILD_LOG_FILE="${OUTPUT_DIRECTORY}build-output_${dateStr}.log"
SHOW_EXTRA_INFO=true
#ENABLE_UNIT_TESTS=true
ENABLE_ANSI=true
ENABLE_CLEAN=true
ENABLE_LIST_OUTPUT=true
ORIGINAL_ARGUMENTS="$@"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--msbuild-path)
shift
MSBuildPath="$1"
shift
;;
--restore)
RUN_INITIALIZE=true
IS_BUILD=true
RESTORE=true
shift
;;
--build)
RUN_INITIALIZE=true
LIST_OUTPUT=true
IS_BUILD=true
BUILD=true
shift
;;
--clean)
RUN_INITIALIZE=true
IS_BUILD=true
CLEAN=true
shift
;;
#--no-test)
# ENABLE_UNIT_TESTS=false
# shift
# ;;
#--test)
# RUN_INITIALIZE=true
# RUN_UNIT_TESTS_FRAMEWORK=true
# RUN_UNIT_TESTS_CORE=true
# shift
# ;;
#--test-framework)
# RUN_INITIALIZE=true
# RUN_UNIT_TESTS_FRAMEWORK=true
# shift
# ;;
#--test-core)
# RUN_INITIALIZE=true
# RUN_UNIT_TESTS_CORE=true
# shift
# ;;
--all)
RUN_INITIALIZE=true
LIST_OUTPUT=true
IS_BUILD=true
CLEAN=true
RESTORE=true
BUILD=true
#RUN_UNIT_TESTS_FRAMEWORK=true
#RUN_UNIT_TESTS_CORE=true
shift
;;
--log-file)
BUILD_LOG_FILE="$2"
shift 2
;;
--release)
GENERATE_DYNAMIC_VERSION=true
IS_RELEASE=true
shift
;;
--release-alpha)
IS_RELEASE=true
RELEASE_TYPE=alpha
shift
;;
--release-beta)
IS_RELEASE=true
RELEASE_TYPE=beta
shift
;;
--unrelease)
IS_UNRELEASE=true
shift
;;
--generate-dynamic-version)
GENERATE_DYNAMIC_VERSION=true
shift
;;
--no-clean)
ENABLE_CLEAN=false
shift
;;
--no-list-output)
ENABLE_LIST_OUTPUT=false
;;
--no-show-extra-info)
SHOW_EXTRA_INFO=false
;;
--no-ansi)
ENABLE_ANSI=false
shift
;;
--automation-mode)
SHOW_EXTRA_INFO=false
ENABLE_LIST_OUTPUT=false
ENABLE_ANSI=false
BUILD_LOG_FILE=/dev/null
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ "${SHOW_EXTRA_INFO}" == "true" ]]; then
echo -e "Logging build output to: ${BUILD_LOG_FILE}"
echo ""
fi
{
set -e
echo "Arguments: ${ORIGINAL_ARGUMENTS}"
echo ""
if [[ "$RUN_INITIALIZE" == "true" ]]; then
Initialize
fi
if [[ "$ENABLE_CLEAN" == "true" ]] && [[ "$CLEAN" == "true" ]]; then
RunSolutionTarget "${SlnFile}" "Clean" "${MSBuildPath}"
fi
if [[ "$RESTORE" == "true" ]]; then
RunSolutionTarget "${SlnFile}" "Restore" "${MSBuildPath}"
fi
if [[ "$BUILD" == "true" ]]; then
RunSolutionTarget "${SlnFile}" "Build" "${MSBuildPath}"
mkdir -p ${OUTPUT_DIRECTORY}MediaTesterGui
mkdir -p ${OUTPUT_DIRECTORY}MediaTesterCli
mkdir -p ${OUTPUT_DIRECTORY}MediaTesterLib
rm -f ${OUTPUT_DIRECTORY}MediaTesterGui/*
rm -f ${OUTPUT_DIRECTORY}MediaTesterCli/*
rm -f ${OUTPUT_DIRECTORY}MediaTesterLib/*
cp MediaTesterGui/bin/Release/net462/MediaTesterGui.exe ${OUTPUT_DIRECTORY}MediaTesterGui/
cp MediaTesterCli/bin/Release/net462/MediaTester.exe ${OUTPUT_DIRECTORY}MediaTesterCli/
cp MediaTesterLib/bin/Release/netstandard2.0/*.dll ${OUTPUT_DIRECTORY}MediaTesterLib/
fi
#if [[ "$ENABLE_UNIT_TESTS" == "true" ]]; then
# if [[ "$RUN_UNIT_TESTS_FRAMEWORK" == "true" ]]; then
# TestFramework
# fi
# if [[ "$RUN_UNIT_TESTS_CORE" == "true" ]]; then
# TestCore
# fi
#fi
if [[ "$IS_UNRELEASE" == "true" ]]; then
UnPrepareProjectsForRelease
fi
if [[ "${SHOW_EXTRA_INFO}" == "true" ]]; then
echo ""
EchoInColor "Build complete!" "1;32"
fi
if [[ "$LIST_OUTPUT" == "true" ]] && [[ "$ENABLE_LIST_OUTPUT" == "true" ]]; then
EchoInColor "Build output can be found in the '${OUTPUT_DIRECTORY}' directory:" "1;32"
if [ -d "${OUTPUT_DIRECTORY}" ]; then
echo ""
EchoInColor "${OUTPUT_DIRECTORY}:"
ls -hoRg ${OUTPUT_DIRECTORY}*/*
fi
fi
} 2>&1 | tee "${BUILD_LOG_FILE}"
ExitCode=${PIPESTATUS[0]}
if [[ "${SHOW_EXTRA_INFO}" == "true" ]]; then
echo ""
EchoInColor "Build output logged to: ${BUILD_LOG_FILE}"
fi
if [[ "$ExitCode" != "0" ]]; then
echo ""
echo "Errors detected!"
fi
exit $ExitCode