Skip to content

Commit

Permalink
updating build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed Aug 26, 2024
1 parent d6f4285 commit 2b09318
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tools/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set SELF=%~dp0
if "%1" equ "" (
echo Usage: build.bat debug^|release "{version}"
echo e.g. build.bat release "20.12.2"
echo e.g. build.bat release "20"
exit /b -1
)
FOR /F "tokens=* USEBACKQ" %%F IN (`node -p process.arch`) DO (SET ARCH=%%F)
Expand All @@ -20,7 +21,21 @@ if not exist "%NODEEXE%" (
)
for %%i in ("%NODEEXE%") do set NODEDIR=%%~dpi
SET DESTDIRROOT=%SELF%\..\lib\native\win32

set VERSION=%1

if %MAJORVERSION% equ %VERSION% (
echo Getting latest version of Node.js v%1
FOR /F "tokens=* USEBACKQ" %%F IN (`node "%SELF%\get_version.js" "%VERSION%"`) DO (SET VERSION=%%F)
)

if %MAJORVERSION% equ %VERSION% (
echo Cannot determine Node.js version for %VERSION%
exit /b -1
)

echo Building Node.js v%VERSION%

pushd %SELF%\..

if "%ARCH%" == "arm64" (
Expand All @@ -40,8 +55,9 @@ if not exist "%DESTDIR%" mkdir "%DESTDIR%"
type NUL > %DESTDIR%\node.version
echo %VERSION%> %DESTDIR%\node.version

if exist "%DESTDIR%\node.exe" goto gyp
echo Downloading node.exe %2 %3...
rem if exist "%DESTDIR%\node.exe" goto gyp

echo Downloading node.exe %2 %3
node "%SELF%\download.js" %2 %3 "%DESTDIR%"
if %ERRORLEVEL% neq 0 (
echo Cannot download node.exe %2 v%3
Expand Down Expand Up @@ -69,8 +85,8 @@ if %ERRORLEVEL% neq 0 (
REM Conflict when building arm64 binaries
if "%ARCH%" == "arm64" (
FOR %%F IN (build\*.vcxproj) DO (
echo Patch /fp:strict in %%F
powershell -Command "(Get-Content -Raw %%F) -replace '<FloatingPointModel>Strict</FloatingPointModel>', '<!-- <FloatingPointModel>Strict</FloatingPointModel> -->' | Out-File -Encoding Utf8 %%F"
echo Patch /fp:strict in %%F
powershell -Command "(Get-Content -Raw %%F) -replace '<FloatingPointModel>Strict</FloatingPointModel>', '<!-- <FloatingPointModel>Strict</FloatingPointModel> -->' | Out-File -Encoding Utf8 %%F"
)
)

Expand Down
38 changes: 38 additions & 0 deletions tools/get_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var {http} = require('follow-redirects');

try_get();

function try_get() {
let url = 'http://nodejs.org/dist/index.json';

http.get(url,(res) => {
let body = "";

if (res.statusCode !== 200) {
throw new Error(`Unable to get Node.js versions from ${url}`);
}

res.on("data", (chunk) => {
body += chunk;
});

res.on("end", () => {
try {
let json = JSON.parse(body);

for (const el of json.sort()) {
let version = el.version.substring(1, el.version.length) ;
if(version.startsWith(process.argv[2])){
console.log(version)
return version;
}
}
} catch (error) {
throw error;
};
});

}).on("error", (error) => {
throw new Error(error);
});
}

0 comments on commit 2b09318

Please sign in to comment.