-
-
Notifications
You must be signed in to change notification settings - Fork 901
Expand file tree
/
Copy pathtools.ps1
More file actions
273 lines (239 loc) · 7.76 KB
/
tools.ps1
File metadata and controls
273 lines (239 loc) · 7.76 KB
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
Set-PSDebug -Trace 0
Set-StrictMode -Version 3
$ErrorActionPreference = "Stop"
$cecho = "$PSScriptRoot\cecho.cmd"
# Create marker file to indicate whether Release or Debug build was installed.
function mark {
param(
[Parameter(Mandatory = $true)]
[string]$installation_dir
)
if (-not (Test-Path -Path $installation_dir)) {
throw "Directory '$installation_dir' does not exist."
}
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
if (Test-Path -Path $marker_filepath) {
return
}
. $cecho 0 13 "Marking installation in '$installation_dir' with '$ENV:MARKER_FILE'."
New-Item -Path $marker_filepath -ItemType File | Out-Null
}
# This function can be deprecated in the future, since installations are marked automatically.
# It's here only to avoid some disruption during the transition period.
function mark_based_on_artifacts {
param(
[Parameter(Mandatory = $true)]
[string]$dependency_name,
[Parameter(Mandatory = $true)]
[string]$installation_dir
)
if ($dependency_name -eq "hdf5") {
if ($env:BUILD_CFG -eq "Debug") {
$artifact = "lib\libhdf5_D.lib"
}
else {
$artifact = "lib\libhdf5.lib"
}
}
elseif ($dependency_name -eq "opencollada") {
if ($env:BUILD_CFG -eq "Debug") {
$artifact = "lib\opencollada\OpenCOLLADAFrameworkd.lib"
}
else {
$artifact = "lib\opencollada\OpenCOLLADAFramework.lib"
}
}
elseif ($dependency_name -eq "OpenCASCADE") {
# New OCCT folder layout was introduced after marker files were added,
# so installation don't need artifact-based detection.
return
}
elseif ($dependency_name -eq "rocksdb") {
if ($env:BUILD_CFG -eq "Debug") {
$artifact = "lib\rocksdb_d.lib"
}
else {
$artifact = "lib\rocksdb.lib"
}
}
else {
throw "Unexpected dependency name '$dependency_name'."
}
$artifact_filepath = Join-Path -Path $installation_dir -ChildPath $artifact
if (-not (Test-Path -Path $artifact_filepath)) {
return
}
if (-not (Test-Path -Path $installation_dir)) {
throw "Directory '$installation_dir' does not exist."
}
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
if (Test-Path -Path $marker_filepath) {
return
}
. $cecho 0 13 "Found artifact '$artifact' for dependency '$dependency_name' $env:BUILD_CFG."
& mark $installation_dir
}
# Check if installation exists for the current `BUILD_CFG`.
# Returns exit code 200 if installation exists, 404 otherwise.
# Since we want Release and Debug installation to coexist,
# we add special marker file to indicate which build type was installed.
function check_installation {
param(
[Parameter(Mandatory = $true)]
[string]$dependency_name,
[Parameter(Mandatory = $true)]
[string]$installation_dir
)
if (-not (Test-Path -Path $installation_dir)) {
exit 404
}
& mark_based_on_artifacts $dependency_name $installation_dir
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
if (-not (Test-Path -Path $marker_filepath)) {
exit 404
}
exit 200
}
# Dependencies Release/Debug configs compatibility:
# - hdf5: incompatible
# - OpenCASCADE: incompatible
# - rocksdb: incompatible
# - opencollada: incompatible
# - zstd: compatible
function setup_build_cfg {
if (-not $env:BUILD_CFG) {
throw "Variable 'BUILD_CFG' is not defined."
}
if ($env:BUILD_CFG -eq "Debug") {
$ENV:MARKER_FILE = ".debug_installation"
}
else {
$ENV:MARKER_FILE = ".release_installation"
}
}
function extract_file {
param(
[Parameter(Mandatory = $true)]
[string]$dependency_name,
[Parameter(Mandatory = $true)]
[string]$filename,
[Parameter(Mandatory = $true)]
[string]$destination_dir,
[Parameter(Mandatory = $true)]
[string]$dir_after_extraction
)
if (Test-Path -Path "$dir_after_extraction") {
. $cecho 0 13 "$dependency_name already extracted into '$dir_after_extraction'. Skipping."
return
}
. $cecho 0 13 "Extracting $dependency_name into '$destination_dir' from '$filename'."
7za x "$filename" -o"$destination_dir"
}
function download_file {
param(
[Parameter(Mandatory = $true)]
[string]$dependency_name,
[Parameter(Mandatory = $true)]
[string]$url,
[Parameter(Mandatory = $true)]
[string]$destination_dir,
[Parameter(Mandatory = $true)]
[string]$filename
)
mkdir "$destination_dir" -Force | Out-Null
pushd "$destination_dir"
if (Test-Path -Path "$filename") {
. $cecho 0 13 "$dependency_name already downloaded. Skipping."
return
}
. $cecho 0 13 "Downloading $dependency_name into '$destination_dir'"
Invoke-WebRequest $url -OutFile $filename
}
# Required env variables:
# - DEPS_DIR
function git_clone_and_checkout_revision {
param(
[Parameter(Mandatory = $true)]
[string]$dependency_name,
[Parameter(Mandatory = $true)]
[string]$git_url,
[Parameter(Mandatory = $true)]
[string]$dest_dir,
[Parameter(Mandatory = $false)]
[string]$revision
)
if (Test-Path -Path "$dest_dir") {
. $cecho 0 13 "Cloning $dependency_name is already cloned."
return
}
. $cecho 0 13 "Cloning $dependency_name into '$dest_dir'."
pushd "$env:DEPS_DIR"
git clone $git_url $dest_dir
popd
pushd "$dest_dir"
git fetch
. $cecho 0 13 "Checking out $dependency_name revision $revision."
git reset --hard
git checkout $revision
popd
}
function install_cmake_project {
param(
[Parameter(Mandatory = $true)]
[string]$dependency_name,
[Parameter(Mandatory = $true)]
[string]$build_dir,
[Parameter(Mandatory = $true)]
[string]$configuration
)
pushd "$build_dir"
. $cecho 0 13 "Installing $dependency_name ($configuration). Please be patient, this may take a while."
$command = "cmake --install . --config $configuration"
. $cecho 0 13 "$command"
Invoke-Expression $command
popd
}
function check_boost_vc145_compatibility {
param(
[Parameter(Mandatory = $true)]
[string]$VC_VER,
[Parameter(Mandatory = $true)]
[string]$DEPS_DIR,
[Parameter(Mandatory = $true)]
[string]$BOOST_ROOT
)
$boost_build_path = "$BOOST_ROOT/tools/build"
if ($VC_VER -ne "14.5") {
. $cecho 0 13 "VC_VER is not 14.5, no need to install updated b2."
return
}
$res = Select-String -Path "$boost_build_path/src/engine/build.bat" -Pattern 'vc143, vc145' -Quiet;
if ($res) {
. $cecho 0 13 "vc145 already supported, no need to install updated b2."
return
}
$b2_version = "5.4.2"
$b2_stem = "b2-$b2_version"
$b2_path = "$DEPS_DIR\$b2_stem"
$b2_filename = "$b2_stem.zip"
& download_file "b2" "https://github.com/bfgroup/b2/releases/download/$b2_version/$b2_filename" "$DEPS_DIR" "$b2_filename"
& extract_file "b2" "$b2_filename" "$DEPS_DIR" "$b2_path"
. $cecho 0 13 "Installing b2 with vc145 support..."
Remove-Item -Recurse -Path "$boost_build_path"
Copy-Item -Path "$b2_path" -Destination "$boost_build_path" -Recurse
. $cecho 0 13 "b2 with vc145 support installed."
}
function main {
& setup_build_cfg
# Dispatch command.
$command = $Args[0]
if ($args.Count -gt 1) {
$command_args = $Args[1..($args.Count - 1)]
}
else {
$command_args = @()
}
& $command @command_args
}
& main @Args
exit 0