-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathsetup.bat
More file actions
448 lines (386 loc) · 14.3 KB
/
setup.bat
File metadata and controls
448 lines (386 loc) · 14.3 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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
:: Shared setup script for all G-Assist plugins (Python, C++, Node.js)
:: Usage: setup.bat <plugin-name|all> [-deploy]
@echo off
setlocal EnableDelayedExpansion
set EXAMPLES_DIR=%~dp0
set SDK_PYTHON=%EXAMPLES_DIR%..\sdk\python
set SDK_CPP=%EXAMPLES_DIR%..\sdk\cpp
set SDK_NODEJS=%EXAMPLES_DIR%..\sdk\nodejs
set RISE_PYTHON=%PROGRAMDATA%\NVIDIA Corporation\nvtopps\rise\python\python.exe
set DEPLOY_BASE=%PROGRAMDATA%\NVIDIA Corporation\nvtopps\rise\plugins
:: Check for help flag
if "%~1"=="" goto show_help
if "%~1"=="-h" goto show_help
if "%~1"=="--help" goto show_help
if "%~1"=="-?" goto show_help
if "%~1"=="/?" goto show_help
:: Get plugin name and deploy flag
set PLUGIN_NAME=%~1
set DEPLOY=0
if "%~2"=="-deploy" set DEPLOY=1
if "%~2"=="--deploy" set DEPLOY=1
echo.
echo ============================================================
echo G-Assist Plugin Setup
echo ============================================================
echo.
:: Handle "all" - setup all plugins
if /i "%PLUGIN_NAME%"=="all" (
echo Setting up ALL plugins...
echo.
for /d %%d in ("%EXAMPLES_DIR%*") do (
if exist "%%d\manifest.json" (
call :setup_plugin "%%~nxd"
)
)
echo.
echo ============================================================
echo All plugins setup complete!
echo ============================================================
)
if /i "%PLUGIN_NAME%"=="all" goto :done
:: Single plugin setup
if exist "%EXAMPLES_DIR%%PLUGIN_NAME%\manifest.json" (
call :setup_plugin "%PLUGIN_NAME%"
) else (
echo ERROR: Plugin "%PLUGIN_NAME%" not found.
echo.
echo Available plugins:
for /d %%d in ("%EXAMPLES_DIR%*") do (
if exist "%%d\manifest.json" (
echo - %%~nxd
)
)
exit /b 1
)
goto :done
:: ============================================================
:: SUBROUTINE: Setup a single plugin
:: ============================================================
:setup_plugin
set "P_NAME=%~1"
set "P_DIR=%EXAMPLES_DIR%%P_NAME%"
set "P_LIBS=%P_DIR%\libs"
set "P_DEPLOY_DIR=%DEPLOY_BASE%\%P_NAME%"
echo ------------------------------------------------------------
echo Setting up: %P_NAME%
echo ------------------------------------------------------------
:: Detect plugin type
set "P_TYPE=unknown"
if exist "%P_DIR%\plugin.py" set "P_TYPE=python"
if exist "%P_DIR%\plugin.cpp" set "P_TYPE=cpp"
if exist "%P_DIR%\main.cpp" set "P_TYPE=cpp"
if exist "%P_DIR%\CMakeLists.txt" set "P_TYPE=cpp"
if exist "%P_DIR%\*.vcxproj" set "P_TYPE=cpp"
if exist "%P_DIR%\plugin.js" set "P_TYPE=nodejs"
echo Plugin type: %P_TYPE%
:: Create libs folder if it doesn't exist
if not exist "%P_LIBS%" mkdir "%P_LIBS%"
:: Handle based on plugin type
if "%P_TYPE%"=="python" call :setup_python
if "%P_TYPE%"=="cpp" call :setup_cpp
if "%P_TYPE%"=="nodejs" call :setup_nodejs
if "%P_TYPE%"=="unknown" (
echo WARNING: Could not detect plugin type
)
echo Setup complete for %P_NAME%
:: Deploy if -deploy flag was passed
if %DEPLOY%==1 (
call :deploy_plugin
)
echo.
goto :eof
:: ============================================================
:: PYTHON SETUP
:: ============================================================
:setup_python
echo [Python Plugin]
:: Check Python version
call :check_python_version
:: Pip install requirements if file exists
set "P_REQUIREMENTS=%P_DIR%\requirements.txt"
if exist "%P_REQUIREMENTS%" (
findstr /v /r "^#" "%P_REQUIREMENTS%" | findstr /r /v "^$" >nul 2>&1
if not errorlevel 1 (
echo Installing pip dependencies to libs/...
%PYTHON% -m pip install -r "%P_REQUIREMENTS%" --target "%P_LIBS%" --upgrade --quiet
) else (
echo No pip dependencies in requirements.txt
)
) else (
echo No requirements.txt found
)
:: Copy gassist_sdk from SDK folder
if exist "%SDK_PYTHON%\gassist_sdk" (
echo Copying Python SDK to libs/gassist_sdk/...
xcopy /E /I /Y "%SDK_PYTHON%\gassist_sdk" "%P_LIBS%\gassist_sdk" >nul
)
goto :eof
:: ============================================================
:: C++ SETUP
:: ============================================================
:setup_cpp
echo [C++ Plugin]
:: Create include directory in libs
if not exist "%P_LIBS%\include" mkdir "%P_LIBS%\include"
:: Copy gassist_sdk.hpp from SDK folder
if exist "%SDK_CPP%\gassist_sdk.hpp" (
echo Copying C++ SDK to libs/include/gassist_sdk.hpp...
copy /Y "%SDK_CPP%\gassist_sdk.hpp" "%P_LIBS%\include\" >nul
)
:: Check if nlohmann/json exists in logiled (common location)
set "NLOHMANN_SRC=%EXAMPLES_DIR%logiled\nlohmann"
if exist "%NLOHMANN_SRC%\json.hpp" (
echo Copying nlohmann/json.hpp to libs/include/nlohmann/...
if not exist "%P_LIBS%\include\nlohmann" mkdir "%P_LIBS%\include\nlohmann"
copy /Y "%NLOHMANN_SRC%\json.hpp" "%P_LIBS%\include\nlohmann\" >nul
) else (
echo NOTE: nlohmann/json not found. CMake will download it during build.
)
:: Copy DLLs from any SDK redist folders to libs/ (for runtime loading)
:: Note: Using "dir ... >nul 2>&1 &&" since "if exist *.dll" doesn't work with wildcards
dir "%P_DIR%\iCUESDK\redist\x64\*.dll" >nul 2>&1 && (
echo Copying iCUESDK runtime DLLs to libs/...
copy /Y "%P_DIR%\iCUESDK\redist\x64\*.dll" "%P_LIBS%\" >nul
)
dir "%P_DIR%\AutomationSDK\redist\x64\*.dll" >nul 2>&1 && (
echo Copying AutomationSDK runtime DLLs to libs/...
copy /Y "%P_DIR%\AutomationSDK\redist\x64\*.dll" "%P_LIBS%\" >nul
)
echo.
echo To build: mkdir build ^& cd build ^& cmake .. ^& cmake --build . --config Release
echo Or for VS: msbuild *.sln /p:Configuration=Release /p:Platform=x64
goto :eof
:: ============================================================
:: NODE.JS SETUP
:: ============================================================
:setup_nodejs
echo [Node.js Plugin]
:: Copy gassist-sdk.js from SDK folder
if exist "%SDK_NODEJS%\gassist-sdk.js" (
echo Copying Node.js SDK to libs/gassist-sdk.js...
copy /Y "%SDK_NODEJS%\gassist-sdk.js" "%P_LIBS%\" >nul
)
:: Check if Node.js is available
where /q node
if errorlevel 1 (
echo WARNING: Node.js not found in PATH
) else (
for /f "tokens=1" %%v in ('node --version') do echo Node.js version: %%v
)
goto :eof
:: ============================================================
:: DEPLOY PLUGIN
:: ============================================================
:deploy_plugin
echo Deploying to %P_DEPLOY_DIR%...
:: ============================================================
:: PRE-DEPLOYMENT: Validate source manifest
:: ============================================================
call :validate_manifest "%P_DIR%\manifest.json" "SOURCE"
if errorlevel 1 (
echo.
echo ERROR: Source manifest validation failed - NOT deploying!
echo Fix the issues above before deploying.
goto :eof
)
:: Create deploy directory if it doesn't exist
if not exist "%P_DEPLOY_DIR%" mkdir "%P_DEPLOY_DIR%"
:: Copy common files
if exist "%P_DIR%\manifest.json" copy /Y "%P_DIR%\manifest.json" "%P_DEPLOY_DIR%\" >nul
if exist "%P_DIR%\config.json" copy /Y "%P_DIR%\config.json" "%P_DEPLOY_DIR%\" >nul
:: Copy type-specific files
if "%P_TYPE%"=="python" (
if exist "%P_DIR%\plugin.py" copy /Y "%P_DIR%\plugin.py" "%P_DEPLOY_DIR%\" >nul
if exist "%P_LIBS%" xcopy /E /I /Y "%P_LIBS%" "%P_DEPLOY_DIR%\libs" >nul
)
if "%P_TYPE%"=="cpp" (
:: For C++, copy built executable and any DLLs
set "CPP_BUILD_DIR=%P_DIR%\build\Release"
:: Try build/Release first (CMake output)
if exist "!CPP_BUILD_DIR!\*.exe" (
echo Copying executable from build/Release...
copy /Y "!CPP_BUILD_DIR!\*.exe" "%P_DEPLOY_DIR%\" >nul
:: Copy any DLLs from build directory
if exist "!CPP_BUILD_DIR!\*.dll" (
echo Copying DLLs from build/Release...
copy /Y "!CPP_BUILD_DIR!\*.dll" "%P_DEPLOY_DIR%\" >nul
)
) else if exist "%P_DIR%\x64\Release\*.exe" (
:: Try x64/Release (Visual Studio output)
echo Copying executable from x64/Release...
copy /Y "%P_DIR%\x64\Release\*.exe" "%P_DEPLOY_DIR%\" >nul
if exist "%P_DIR%\x64\Release\*.dll" (
echo Copying DLLs from x64/Release...
copy /Y "%P_DIR%\x64\Release\*.dll" "%P_DEPLOY_DIR%\" >nul
)
) else if exist "%P_DIR%\Release\*.exe" (
:: Try Release folder
echo Copying executable from Release...
copy /Y "%P_DIR%\Release\*.exe" "%P_DEPLOY_DIR%\" >nul
if exist "%P_DIR%\Release\*.dll" (
echo Copying DLLs from Release...
copy /Y "%P_DIR%\Release\*.dll" "%P_DEPLOY_DIR%\" >nul
)
) else if exist "%P_DIR%\*.exe" (
:: Try root folder
echo Copying executable from plugin folder...
copy /Y "%P_DIR%\*.exe" "%P_DEPLOY_DIR%\" >nul
if exist "%P_DIR%\*.dll" (
echo Copying DLLs from plugin folder...
copy /Y "%P_DIR%\*.dll" "%P_DEPLOY_DIR%\" >nul
)
) else (
echo WARNING: No executable found. Build the plugin first with CMake.
)
:: Copy any DLLs from libs folder to deployed plugin's libs/
dir "%P_LIBS%\*.dll" >nul 2>&1 && (
echo Copying runtime DLLs to libs/...
if not exist "%P_DEPLOY_DIR%\libs" mkdir "%P_DEPLOY_DIR%\libs"
copy /Y "%P_LIBS%\*.dll" "%P_DEPLOY_DIR%\libs\" >nul
)
)
if "%P_TYPE%"=="nodejs" (
if exist "%P_DIR%\plugin.js" copy /Y "%P_DIR%\plugin.js" "%P_DEPLOY_DIR%\" >nul
if exist "%P_DIR%\launch.bat" copy /Y "%P_DIR%\launch.bat" "%P_DEPLOY_DIR%\" >nul
if exist "%P_LIBS%\gassist-sdk.js" copy /Y "%P_LIBS%\gassist-sdk.js" "%P_DEPLOY_DIR%\" >nul
)
:: ============================================================
:: POST-DEPLOYMENT: Validate deployed manifest
:: ============================================================
call :validate_manifest "%P_DEPLOY_DIR%\manifest.json" "DEPLOYED"
if errorlevel 1 (
echo.
echo WARNING: Deployed manifest validation failed!
echo The plugin may not load correctly in G-Assist.
)
echo Deployed to: %P_DEPLOY_DIR%
goto :eof
:: ============================================================
:: VALIDATE MANIFEST
:: Checks manifest.json for common issues that would prevent loading
:: Usage: call :validate_manifest "path\to\manifest.json" "SOURCE|DEPLOYED"
:: ============================================================
:validate_manifest
set "MANIFEST_PATH=%~1"
set "MANIFEST_TYPE=%~2"
set "VALIDATION_ERRORS=0"
echo Validating %MANIFEST_TYPE% manifest...
:: Check file exists
if not exist "%MANIFEST_PATH%" (
echo [ERROR] manifest.json not found
exit /b 1
)
:: Check file is not empty (0 bytes)
for %%F in ("%MANIFEST_PATH%") do set MANIFEST_SIZE=%%~zF
if "%MANIFEST_SIZE%"=="0" (
echo [ERROR] manifest.json is EMPTY
exit /b 1
)
:: Validate JSON using PowerShell
powershell.exe -NoProfile -Command "try { Get-Content '%MANIFEST_PATH%' -Raw | ConvertFrom-Json | Out-Null; Write-Host ' [OK] Manifest is valid'; exit 0 } catch { Write-Host ' [ERROR] Invalid JSON'; exit 1 }"
if %ERRORLEVEL% neq 0 exit /b 1
exit /b 0
:: ============================================================
:: CHECK PYTHON VERSION
:: ============================================================
:check_python_version
:: Determine if we have 'python' or 'python3' in the path
where /q python
if ERRORLEVEL 1 (
where /q python3
if ERRORLEVEL 1 (
echo WARNING: Python not found in PATH
goto :eof
)
set PYTHON=python3
) else (
set PYTHON=python
)
:: Get current Python version
for /f "tokens=2" %%v in ('%PYTHON% --version 2^>^&1') do set CURRENT_VERSION=%%v
echo Using Python: %PYTHON% (version %CURRENT_VERSION%)
:: Check if RISE embedded Python exists and compare versions
if exist "%RISE_PYTHON%" (
for /f "tokens=2" %%v in ('"%RISE_PYTHON%" --version 2^>^&1') do set RISE_VERSION=%%v
echo RISE embedded Python: !RISE_VERSION!
:: Compare major.minor versions
for /f "tokens=1,2 delims=." %%a in ("%CURRENT_VERSION%") do set CURRENT_MAJOR_MINOR=%%a.%%b
for /f "tokens=1,2 delims=." %%a in ("!RISE_VERSION!") do set RISE_MAJOR_MINOR=%%a.%%b
if not "!CURRENT_MAJOR_MINOR!"=="!RISE_MAJOR_MINOR!" (
echo.
echo WARNING: Python version mismatch!
echo Your Python: %CURRENT_VERSION% - RISE Python: !RISE_VERSION!
echo Consider using RISE Python: "%RISE_PYTHON%"
echo.
)
)
goto :eof
:: ============================================================
:: HELP
:: ============================================================
:show_help
echo.
echo G-Assist Plugin Setup Script
echo ============================
echo.
echo This script sets up plugin dependencies for Python, C++, and Node.js plugins.
echo.
echo USAGE:
echo setup.bat ^<plugin-name^> [-deploy]
echo setup.bat all [-deploy]
echo.
echo ARGUMENTS:
echo ^<plugin-name^> Name of the plugin folder to setup
echo all Setup all plugins in the examples folder
echo.
echo OPTIONS:
echo -deploy Also deploy the plugin(s) to RISE plugins folder
echo -h, --help Show this help message
echo.
echo WHAT IT DOES:
echo.
echo Python plugins (plugin.py):
echo - Pip installs packages from requirements.txt to libs/
echo - Copies gassist_sdk from SDK to libs/
echo.
echo C++ plugins (plugin.cpp or CMakeLists.txt):
echo - Copies gassist_sdk.hpp to libs/include/
echo - Copies nlohmann/json.hpp to libs/include/nlohmann/ (if available)
echo - Note: Use CMake to build the executable
echo - Deploy copies .exe and any .dll files from build output
echo.
echo Node.js plugins (plugin.js):
echo - Copies gassist-sdk.js to libs/
echo.
echo EXAMPLES:
echo setup.bat hello-world Setup Python plugin
echo setup.bat hello-world-cpp Setup C++ plugin
echo setup.bat hello-world-nodejs Setup Node.js plugin
echo setup.bat all Setup all plugins
echo setup.bat hello-world -deploy Setup and deploy
echo.
echo AVAILABLE PLUGINS:
for /d %%d in ("%EXAMPLES_DIR%*") do (
if exist "%%d\manifest.json" (
set "PTYPE="
if exist "%%d\plugin.py" set "PTYPE=[Python]"
if exist "%%d\plugin.cpp" set "PTYPE=[C++]"
if exist "%%d\main.cpp" set "PTYPE=[C++]"
if exist "%%d\*.vcxproj" set "PTYPE=[C++]"
if exist "%%d\CMakeLists.txt" set "PTYPE=[C++]"
if exist "%%d\plugin.js" set "PTYPE=[Node.js]"
echo - %%~nxd !PTYPE!
)
)
echo.
echo SDK PATHS:
echo Python: %SDK_PYTHON%
echo C++: %SDK_CPP%
echo Node.js: %SDK_NODEJS%
echo.
endlocal
exit /b 0
:done
endlocal
exit /b 0