forked from dotnet/ClangSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·242 lines (201 loc) · 5.34 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
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
ScriptRoot="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$ScriptRoot/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
ScriptRoot="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
architecture=''
build=false
ci=false
configuration='Debug'
help=false
pack=false
restore=false
solution=''
test=false
verbosity='minimal'
properties=''
while [[ $# -gt 0 ]]; do
lower="$(echo "$1" | awk '{print tolower($0)}')"
case $lower in
--architecture)
architecture=$2
shift 2
;;
--build)
build=true
shift 1
;;
--ci)
ci=true
shift 1
;;
--configuration)
configuration=$2
shift 2
;;
--help)
help=true
shift 1
;;
--pack)
pack=true
shift 1
;;
--restore)
restore=true
shift 1
;;
--solution)
solution=$2
shift 2
;;
--test)
test=true
shift 1
;;
--verbosity)
verbosity=$2
shift 2
;;
*)
properties="$properties $1"
shift 1
;;
esac
done
function Build {
logFile="$LogDir/$configuration/build.binlog"
if [[ -z "$properties" ]]; then
dotnet build -c "$configuration" --no-restore -v "$verbosity" /bl:"$logFile" /err "$solution"
else
dotnet build -c "$configuration" --no-restore -v "$verbosity" /bl:"$logFile" /err "${properties[@]}" "$solution"
fi
LASTEXITCODE=$?
if [ "$LASTEXITCODE" != 0 ]; then
echo "'Build' failed for '$solution'"
return "$LASTEXITCODE"
fi
}
function CreateDirectory {
if [ ! -d "$1" ]
then
mkdir -p "$1"
fi
}
function Help {
echo "Common settings:"
echo " --configuration <value> Build configuration (Debug, Release)"
echo " --verbosity <value> Msbuild verbosity (q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic])"
echo " --help Print help and exit"
echo ""
echo "Actions:"
echo " --restore Restore dependencies"
echo " --build Build solution"
echo " --test Run all tests in the solution"
echo " --pack Package build artifacts"
echo ""
echo "Advanced settings:"
echo " --solution <value> Path to solution to build"
echo " --ci Set when running on CI server"
echo " --architecture <value> Test Architecture (<auto>, amd64, x64, x86, arm64, arm)"
echo ""
echo "Command line arguments not listed above are passed through to MSBuild."
}
function Pack {
logFile="$LogDir/$configuration/pack.binlog"
if [[ -z "$properties" ]]; then
dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "$solution"
else
dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "${properties[@]}" "$solution"
fi
LASTEXITCODE=$?
if [ "$LASTEXITCODE" != 0 ]; then
echo "'Build' failed for '$solution'"
return "$LASTEXITCODE"
fi
}
function Restore {
logFile="$LogDir/$configuration/restore.binlog"
if [[ -z "$properties" ]]; then
dotnet restore -v "$verbosity" /bl:"$logFile" /err "$solution"
else
dotnet restore -v "$verbosity" /bl:"$logFile" /err "${properties[@]}" "$solution"
fi
LASTEXITCODE=$?
if [ "$LASTEXITCODE" != 0 ]; then
echo "'Restore' failed for '$solution'"
return "$LASTEXITCODE"
fi
}
function Test {
logFile="$LogDir/$configuration/test.binlog"
if [[ -z "$properties" ]]; then
dotnet test -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "$solution"
else
dotnet test -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "${properties[@]}" "$solution"
fi
LASTEXITCODE=$?
if [ "$LASTEXITCODE" != 0 ]; then
echo "'Test' failed for '$solution'"
return "$LASTEXITCODE"
fi
}
if $help; then
Help
exit 0
fi
if $ci; then
build=true
pack=true
restore=true
test=true
if [[ -z "$architecture" ]]; then
architecture="<auto>"
fi
fi
RepoRoot="$ScriptRoot/.."
if [[ -z "$solution" ]]; then
solution="$RepoRoot/ClangSharp.sln"
fi
ArtifactsDir="$RepoRoot/artifacts"
CreateDirectory "$ArtifactsDir"
LogDir="$ArtifactsDir/log"
CreateDirectory "$LogDir"
if [[ ! -z "$architecture" ]]; then
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_MULTILEVEL_LOOKUP=0
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
DotNetInstallScript="$ArtifactsDir/dotnet-install.sh"
wget -O "$DotNetInstallScript" "https://dot.net/v1/dotnet-install.sh"
DotNetInstallDirectory="$ArtifactsDir/dotnet"
CreateDirectory "$DotNetInstallDirectory"
. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
PATH="$DotNetInstallDirectory:$PATH:"
fi
if $restore; then
Restore
if [ "$LASTEXITCODE" != 0 ]; then
return "$LASTEXITCODE"
fi
fi
if $build; then
Build
if [ "$LASTEXITCODE" != 0 ]; then
return "$LASTEXITCODE"
fi
fi
if $test; then
Test
if [ "$LASTEXITCODE" != 0 ]; then
return "$LASTEXITCODE"
fi
fi
if $pack; then
Pack
if [ "$LASTEXITCODE" != 0 ]; then
return "$LASTEXITCODE"
fi
fi