Repository navigation
Expand file tree
/
Copy pathsetup.cmd
More file actions
208 lines (190 loc) · 6.61 KB
/
Copy pathsetup.cmd
File metadata and controls
208 lines (190 loc) · 6.61 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
@echo off
setlocal
set "REPO=%~dp0"
set "REPO=%REPO:~0,-1%"
set "VS_INSTALLER=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
set "PATH=%LOCALAPPDATA%\Microsoft\WinGet\Links;%ProgramFiles%\WinGet\Links;%ProgramFiles%\nodejs;%USERPROFILE%\.cargo\bin;%VS_INSTALLER%;%PATH%"
set "LINKHUB_ONLY=0"
if /i "%~1"=="--linkhub-only" set "LINKHUB_ONLY=1"
if "%LINKHUB_ONLY%"=="1" goto linkhub_build
call :ensure_tool uv astral-sh.uv
if errorlevel 1 exit /b 1
call :ensure_node
if errorlevel 1 exit /b 1
set "PYTHON_VERSION="
set /p PYTHON_VERSION=<"%REPO%\.python-version"
if not defined PYTHON_VERSION (
echo ERROR: .python-version must specify the supported Python minor.
exit /b 1
)
set "UV_PYTHON_INSTALL_DIR=%REPO%\.tools\python"
echo [INFO] Upgrading repository-local Python %PYTHON_VERSION% ...
call uv python install --upgrade --no-bin --no-registry "%PYTHON_VERSION%"
if errorlevel 1 (
echo ERROR: uv could not upgrade Python %PYTHON_VERSION%.
exit /b 1
)
set "PYTHON_EXE="
for /f "delims=" %%P in ('uv python find --managed-python --system --no-project "%PYTHON_VERSION%"') do set "PYTHON_EXE=%%P"
if not defined PYTHON_EXE (
echo ERROR: The repository-local Python installation could not be located.
exit /b 1
)
echo [INFO] Synchronizing the project environment ...
call uv sync --project "%REPO%" --python "%PYTHON_EXE%" --managed-python --locked --dev --extra simulation
if errorlevel 1 (
echo ERROR: uv sync failed.
exit /b 1
)
echo [INFO] Checking Python with Ruff ...
call uv run --no-sync --project "%REPO%" ruff check "%REPO%"
if errorlevel 1 (
echo ERROR: Ruff checks failed.
exit /b 1
)
echo [INFO] Checking Python with Pyright ...
call uv run --no-sync --project "%REPO%" python -m pyright --project "%REPO%\pyrightconfig.json" --pythonpath "%REPO%\.venv\Scripts\python.exe" --warnings
if errorlevel 1 (
echo ERROR: Pyright checks failed.
exit /b 1
)
:linkhub_build
if "%LINKHUB_ONLY%"=="1" (
call :ensure_node
if errorlevel 1 exit /b 1
)
call :ensure_msvc
if errorlevel 1 exit /b 1
call :ensure_tool cargo Rustlang.Rustup
if errorlevel 1 exit /b 1
pushd "%REPO%\linkhub-ui"
if errorlevel 1 (
echo ERROR: LinkHub UI directory was not found.
exit /b 1
)
if "%LINKHUB_ONLY%"=="0" goto install_ui_dependencies
if exist "node_modules\" goto build_ui
:install_ui_dependencies
echo [INFO] Installing LinkHub UI dependencies ...
call npm ci --no-audit --no-fund
if errorlevel 1 (
popd
echo ERROR: LinkHub UI dependency installation failed.
exit /b 1
)
:build_ui
echo [INFO] Building LinkHub UI ...
if "%LINKHUB_ONLY%"=="1" (
call npm run build:assets
) else (
call npm run build
)
if errorlevel 1 (
popd
echo ERROR: LinkHub UI build failed.
exit /b 1
)
popd
echo [INFO] Building LinkHub ...
set "CARGO_BUILD_FLAGS="
if "%LINKHUB_ONLY%"=="1" set "CARGO_BUILD_FLAGS=--locked"
call cargo build --manifest-path "%REPO%\linkhub\Cargo.toml" %CARGO_BUILD_FLAGS% --release
if errorlevel 1 (
echo ERROR: LinkHub build failed.
exit /b 1
)
if "%LINKHUB_ONLY%"=="0" (
call uv run --no-sync --project "%REPO%" python --version
if errorlevel 1 (
echo ERROR: The managed Python environment could not be verified.
exit /b 1
)
)
echo [INFO] Done.
endlocal
exit /b 0
:ensure_tool
where %~1 >nul 2>nul
if not errorlevel 1 exit /b 0
call :install_package %~2
if errorlevel 1 exit /b 1
where %~1 >nul 2>nul
if not errorlevel 1 exit /b 0
echo ERROR: %~1 is not available after installation. Open a new terminal
echo and run setup.cmd again.
exit /b 1
:ensure_node
set "NODE_MAJOR="
set /p NODE_MAJOR=<"%REPO%\.node-version"
if not defined NODE_MAJOR (
echo ERROR: .node-version must specify the supported Node.js major.
exit /b 1
)
set "NODE_SETUP_FLAGS="
if "%LINKHUB_ONLY%"=="1" set "NODE_SETUP_FLAGS=-InstallOnly"
call powershell -NoProfile -ExecutionPolicy Bypass -File "%REPO%\scripts\setup_node.ps1" -RepoRoot "%REPO%" -NodeMajor "%NODE_MAJOR%" %NODE_SETUP_FLAGS%
if errorlevel 1 (
echo ERROR: Repository-local Node.js setup failed.
exit /b 1
)
set "PATH=%REPO%\.tools\node;%PATH%"
call "%REPO%\.tools\node\node" -e "if (process.versions.node.split('.')[0] !== process.argv[1]) process.exit(1)" "%NODE_MAJOR%"
if errorlevel 1 (
echo ERROR: The repository-local Node.js version could not be verified.
exit /b 1
)
if not exist "%REPO%\.tools\node\npm.cmd" (
echo ERROR: npm is missing from the repository-local Node.js installation.
exit /b 1
)
exit /b 0
:install_package
where winget >nul 2>nul
if errorlevel 1 (
echo ERROR: WinGet is required to install %~1. Install or update App Installer
echo from Microsoft Store, then run setup.cmd again.
exit /b 1
)
echo [INFO] Installing %~1 with WinGet ...
call winget install --exact --source winget --accept-package-agreements --accept-source-agreements --disable-interactivity --id %*
if not errorlevel 1 exit /b 0
echo ERROR: WinGet could not install %~1. If a restart is required,
echo restart Windows and run setup.cmd again.
exit /b 1
:check_msvc
set "VC_INSTALL="
set "SDK_FOUND="
where vswhere >nul 2>nul
if errorlevel 1 exit /b 1
for /f "delims=" %%I in ('vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set "VC_INSTALL=%%I"
if not defined VC_INSTALL exit /b 1
for /d %%D in ("%ProgramFiles(x86)%\Windows Kits\10\Lib\*") do (
if exist "%%~fD\um\x64\kernel32.lib" if exist "%%~fD\ucrt\x64\ucrt.lib" set "SDK_FOUND=1"
)
if not defined SDK_FOUND exit /b 1
exit /b 0
:ensure_msvc
call :check_msvc
if not errorlevel 1 exit /b 0
set "BUILD_TOOLS="
where vswhere >nul 2>nul
if errorlevel 1 goto :install_msvc
for /f "delims=" %%I in ('vswhere -latest -products Microsoft.VisualStudio.Product.BuildTools -property installationPath') do set "BUILD_TOOLS=%%I"
if not defined BUILD_TOOLS goto :install_msvc
echo [INFO] Adding the C++ build workload to existing Visual Studio Build Tools ...
call "%VS_INSTALLER%\setup" modify --installPath "%BUILD_TOOLS%" --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --passive --norestart
if errorlevel 1 (
echo ERROR: C++ workload installation failed. Restart Windows if required,
echo then run setup.cmd again.
exit /b 1
)
goto :verify_msvc
:install_msvc
call :install_package Microsoft.VisualStudio.2022.BuildTools --override "--wait --passive --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
if errorlevel 1 exit /b 1
:verify_msvc
call :check_msvc
if not errorlevel 1 exit /b 0
echo ERROR: Visual Studio C++ tools or the x64 Windows SDK are still missing.
echo Restart Windows if required, then run setup.cmd again.
exit /b 1