Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
108 lines (85 loc) · 3.24 KB
/
Copy pathbuild.ps1
File metadata and controls
108 lines (85 loc) · 3.24 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
param(
[switch]$CoreOnly,
[switch]$Benchmark,
[switch]$PrepareData,
[switch]$RunDemo,
[switch]$Clean
)
$ErrorActionPreference = "Stop"
$ROOT = Split-Path -Parent $MyInvocation.MyCommand.Path
$BUILD = Join-Path $ROOT "build"
$DEBUG_DIR = Join-Path $BUILD "Debug"
$python = if ($env:PYTHON) { $env:PYTHON } else { (Get-Command python).Source }
function Invoke-Step {
param([string]$Name, [scriptblock]$Action)
Write-Host "==> $Name" -ForegroundColor Cyan
$previous = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
& $Action
} finally {
$ErrorActionPreference = $previous
}
if ($LASTEXITCODE -ne 0) {
throw "$Name failed with exit code $LASTEXITCODE"
}
}
$cache = Join-Path $BUILD "CMakeCache.txt"
if (-not $Clean -and (Test-Path $cache)) {
$home_line = Select-String -Path $cache -Pattern "^CMAKE_HOME_DIRECTORY:INTERNAL=(.*)$"
if ($home_line) {
$cached_root = $home_line.Matches[0].Groups[1].Value
if ((Resolve-Path -LiteralPath $cached_root -ErrorAction SilentlyContinue).Path -ne $ROOT) {
Write-Host "Build cache points at $cached_root; removing it." -ForegroundColor Yellow
$Clean = $true
}
}
}
if ($Clean -and (Test-Path $BUILD)) {
Remove-Item -Recurse -Force $BUILD
}
$cmakeArgs = @(
"-S", $ROOT,
"-B", $BUILD,
"-DWINTERGREEN_BUILD_PYTHON=$(if ($CoreOnly) { 'OFF' } else { 'ON' })",
"-DWINTERGREEN_BUILD_TESTS=ON",
"-DWINTERGREEN_BUILD_BENCHMARKS=ON"
)
if (-not $CoreOnly) {
$ErrorActionPreference = "Continue"
$pybind11Dir = & $python -m pybind11 --cmakedir 2>$null
$ErrorActionPreference = "Stop"
if ($LASTEXITCODE -ne 0) {
throw "pybind11 is not installed for $python. Install it, or run .\build.ps1 -CoreOnly."
}
$cmakeArgs += "-Dpybind11_DIR=$($pybind11Dir.Trim())"
$cmakeArgs += "-DPython_EXECUTABLE=$python"
}
Invoke-Step "Configure" { cmake @cmakeArgs }
Invoke-Step "Build Debug" { cmake --build $BUILD --config Debug --parallel }
Invoke-Step "Test Debug" { ctest --test-dir $BUILD -C Debug --output-on-failure }
if (-not $CoreOnly) {
Invoke-Step "Test Python" {
$env:PYTHONPATH = "$DEBUG_DIR;$(Join-Path $ROOT 'demo')"
& $python -m unittest discover -s (Join-Path $ROOT "tests") -p "test_python.py" -v
}
}
if ($Benchmark) {
$results = Join-Path $ROOT "benchmarks\results.csv"
$graph = Join-Path $ROOT "benchmarks\results.png"
Invoke-Step "Build Release" { cmake --build $BUILD --config Release --parallel }
Invoke-Step "Test Release" { ctest --test-dir $BUILD -C Release --output-on-failure }
Invoke-Step "Benchmark" {
& (Join-Path $BUILD "Release\wintergreen_benchmark.exe") "--csv=$results"
}
Invoke-Step "Graph" { & $python (Join-Path $ROOT "benchmarks\plot.py") $results $graph }
}
if ($PrepareData) {
Invoke-Step "Download images" { & $python (Join-Path $ROOT "demo\download_dataset.py") }
Invoke-Step "Generate embeddings" { & $python (Join-Path $ROOT "demo\generate_embeddings.py") }
}
if ($RunDemo) {
Write-Host "==> Demo on http://127.0.0.1:5000 (Ctrl+C to stop)" -ForegroundColor Cyan
$env:PYTHONPATH = "$DEBUG_DIR;$env:PYTHONPATH"
& $python (Join-Path $ROOT "demo\app.py")
}