Skip to content

Instantly share code, notes, and snippets.

@refack
Last active August 3, 2017 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refack/969ecc6642981bfd7caef7d948d78076 to your computer and use it in GitHub Desktop.
Save refack/969ecc6642981bfd7caef7d948d78076 to your computer and use it in GitHub Desktop.
$invocation = (Get-Variable MyInvocation).Value
cd (Split-Path $invocation.MyCommand.Path)
if ($Args[0] -eq "help") { return help }
if ($Args[0] -eq "--help") { return help }
if ($Args[0] -eq "-help") { return help }
if ($Args[0] -eq "/help") { return help }
if ($Args[0] -eq "?") { return help }
if ($Args[0] -eq "-?") { return help }
if ($Args[0] -eq "--?") { return help }
if ($Args[0] -eq "/?") { return help }
# Process arguments.
$config=Release
$target=Build
$target_arch=x64
$target_env=
$noprojgen=
$nobuild=
$sign=
$nosnapshot=
$notargettype=
$cctest_args=
$test_args=
$package=
$msi=
$upload=
$licensertf=
$jslint=
$cpplint=
$build_testgc_addon=
$noetw=
$noetw_msi_arg=
$noperfctr=
$noperfctr_msi_arg=
$i18n_arg=
$download_arg=
$build_release=
$enable_vtune_arg=
$configure_flags=
$build_addons=
$dll=
$build_addons_napi=
$test_node_inspect=
function next-arg
{
if $Args[0] -eq "" goto args-done
if ($Args[0] -eq "debug" $config=Debug&goto arg-ok
if ($Args[0] -eq "release" $config=Release&goto arg-ok
if ($Args[0] -eq "clean" $target=Clean&goto arg-ok
if ($Args[0] -eq "ia32" $target_arch=x86&goto arg-ok
if ($Args[0] -eq "x86" $target_arch=x86&goto arg-ok
if ($Args[0] -eq "x64" $target_arch=x64&goto arg-ok
if ($Args[0] -eq "vc2015" $target_env=vc2015&goto arg-ok
if ($Args[0] -eq "noprojgen" $noprojgen=1&goto arg-ok
if ($Args[0] -eq "nobuild" $nobuild=1&goto arg-ok
if ($Args[0] -eq "nosign" $"sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok
if ($Args[0] -eq "sign" $sign=1&goto arg-ok
if ($Args[0] -eq "nosnapshot" $nosnapshot=1&goto arg-ok
if ($Args[0] -eq "noetw" $noetw=1&goto arg-ok
if ($Args[0] -eq "noperfctr" $noperfctr=1&goto arg-ok
if ($Args[0] -eq "notargettype" $notargettype=1&goto arg-ok
if ($Args[0] -eq "licensertf" $licensertf=1&goto arg-ok
if ($Args[0] -eq "test" $test_args=%test_args% addons addons-napi doctool known_issues message parallel s-eqential -J&$cpplint=1&$jslint=1&$build_addons=1&$build_addons_napi=1&goto arg-ok
if ($Args[0] -eq "test-ci" $test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons addons-napi doctool inspector known_issues message s-eqential parallel&$cctest_args=%cctest_args% --gtest_output=tap:cctest.tap&$build_addons=1&$build_addons_napi=1&goto arg-ok
if ($Args[0] -eq "test-addons" $test_args=%test_args% addons&$build_addons=1&goto arg-ok
if ($Args[0] -eq "test-addons-napi" $test_args=%test_args% addons-napi&$build_addons_napi=1&goto arg-ok
if ($Args[0] -eq "test-simple" $test_args=%test_args% s-eqential parallel -J&goto arg-ok
if ($Args[0] -eq "test-message" $test_args=%test_args% message&goto arg-ok
if ($Args[0] -eq "test-gc" $test_args=%test_args% gc&$build_testgc_addon=1&goto arg-ok
if ($Args[0] -eq "test-inspector" $test_args=%test_args% inspector&goto arg-ok
if ($Args[0] -eq "test-tick-processor" $test_args=%test_args% tick-processor&goto arg-ok
if ($Args[0] -eq "test-internet" $test_args=%test_args% internet&goto arg-ok
if ($Args[0] -eq "test-pummel" $test_args=%test_args% pummel&goto arg-ok
if ($Args[0] -eq "test-all" $test_args=%test_args% s-eqential parallel message gc inspector internet pummel&$build_testgc_addon=1&$cpplint=1&$jslint=1&goto arg-ok
if ($Args[0] -eq "test-known-issues" $test_args=%test_args% known_issues&goto arg-ok
if ($Args[0] -eq "test-node-inspect" $test_node_inspect=1&goto arg-ok
if ($Args[0] -eq "jslint" $jslint=1&goto arg-ok
if ($Args[0] -eq "jslint-ci" $jslint_ci=1&goto arg-ok
if ($Args[0] -eq "lint" $cpplint=1&$jslint=1&goto arg-ok
if ($Args[0] -eq "lint-ci" $cpplint=1&$jslint_ci=1&goto arg-ok
if ($Args[0] -eq "package" $package=1&goto arg-ok
if ($Args[0] -eq "msi" $msi=1&$licensertf=1&$download_arg="--download=all"&$i18n_arg=small-icu&goto arg-ok
if ($Args[0] -eq "build-release" $build_release=1&$sign=1&goto arg-ok
if ($Args[0] -eq "upload" $upload=1&goto arg-ok
if ($Args[0] -eq "small-icu" $i18n_arg=%1&goto arg-ok
if ($Args[0] -eq "full-icu" $i18n_arg=%1&goto arg-ok
if ($Args[0] -eq "intl-none" $i18n_arg=%1&goto arg-ok
if ($Args[0] -eq "without-intl" $i18n_arg=%1&goto arg-ok
if ($Args[0] -eq "download-all" $download_arg="--download=all"&goto arg-ok
if ($Args[0] -eq "ignore-flaky" $test_args=%test_args% --flaky-tests=dontcare&goto arg-ok
if ($Args[0] -eq "enable-vtune" $enable_vtune_arg=1&goto arg-ok
if ($Args[0] -eq "dll" $dll=1&goto arg-ok
echo Error: invalid command line option `%1`.
exit /b 1
:arg-ok
:arg-ok
shift
goto next-arg
}
function args-done
{
if defined build_release (
$config=Release
$package=1
$msi=1
$licensertf=1
$download_arg="--download=all"
$i18n_arg=small-icu
)
:: assign path to node_exe
$node_exe=%config%\node.exe
if "%config%" -eq "Debug" $configure_flags=%configure_flags% --debug
if defined nosnapshot $configure_flags=%configure_flags% --without-snapshot
if defined noetw $configure_flags=%configure_flags% --without-etw& $noetw_msi_arg=/p:NoETW=1
if defined noperfctr $configure_flags=%configure_flags% --without-perfctr& $noperfctr_msi_arg=/p:NoPerfCtr=1
if defined release_urlbase $configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
if defined download_arg $configure_flags=%configure_flags% %download_arg%
if defined enable_vtune_arg $configure_flags=%configure_flags% --enable-vtune-profiling
if defined dll $configure_flags=%configure_flags% --shared
if "%i18n_arg%" -eq "full-icu" $configure_flags=%configure_flags% --with-intl=full-icu
if "%i18n_arg%" -eq "small-icu" $configure_flags=%configure_flags% --with-intl=small-icu
if "%i18n_arg%" -eq "intl-none" $configure_flags=%configure_flags% --with-intl=none
if "%i18n_arg%" -eq "without-intl" $configure_flags=%configure_flags% --without-intl
if defined config_flags $configure_flags=%configure_flags% %config_flags%
if not exist "%~dp0deps\icu" goto no-depsicu
if "%target%" -eq "Clean" echo deleting %~dp0deps\icu
if "%target%" -eq "Clean" rmdir /S /Q %~dp0deps\icu
:no-depsicu
call :getnodeversion || exit /b 1
if "%target%" -eq "Clean" rmdir /Q /S "%~dp0%config%\node-v%FULLVERSION%-win-%target_arch%" > nul 2> nul
}
if (defined noprojgen if defined nobuild if not defined sign if not defined msi goto) {return licensertf}
function set-env
{
# Set environment for msbuild
# Look for Visual Studio 2015
echo Looking for Visual Studio 2015
if not defined VS140COMNTOOLS goto msbuild-not-found
if not exist "%VS140COMNTOOLS%\..\..\vc\vcvarsall.bat" goto msbuild-not-found
echo Found Visual Studio 2015
if defined msi (
echo Looking for WiX installation for Visual Studio 2015...
if not exist "%WIX%\SDK\VS2015" (
echo Failed to find WiX install for Visual Studio 2015
echo VS2015 support for WiX is only present starting at version 3.10
goto wix-not-found
)
)
if "%VCVARS_VER%" NEQ "140" (
call "%VS140COMNTOOLS%\..\..\vc\vcvarsall.bat"
$VCVARS_VER=140
)
if not defined VCINSTALLDIR goto msbuild-not-found
$GYP_MSVS_VERSION=2015
$PLATFORM_TOOLSET=v140
return msbuild-found
}
function msbuild-not-found
{
echo Failed to find Visual Studio installation.
return
}
function wix-not-found
{
echo Build skipped. To generate installer, you need to install Wix.
return run
}
function msbuild-found
{
return project-gen
}
function project-gen
{
# Skip project generation if r-eqested.
if (defined noprojgen) {msbuild}
# Generate the VS project.
echo configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
python configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
if errorlevel 1 goto create-msvs-files-failed
if not exist node.sln goto create-msvs-files-failed
echo Project files generated.
}
function msbuild
{
# Skip build if r-eqested.
if defined nobuild goto sign
# Build the sln with msbuild.
$msbplatform=Win32
if "%target_arch%" -eq "x64" set "msbplatform=x64"
msbuild node.sln /m /t:%target% /p:Configuration=%config% /p:Platform=%msbplatform% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
if errorlevel 1 return
if "%target%" -eq "Clean" return
}
function sign
{
# Skip signing unless the `sign` option was specified.
if not defined sign goto licensertf
call tools\sign.bat Release\node.exe
if errorlevel 1 echo Failed to sign exe&return
}
function licensertf
{
# Skip license.rtf generation if not r-eqested.
if not defined licensertf goto package
%config%\node tools\license2rtf.js < LICENSE > %config%\license.rtf
if errorlevel 1 echo Failed to generate license.rtf&return
}
function package
{
if (not defined package) {return msi}
echo Creating package...
cd Release
mkdir node-v%FULLVERSION%-win-%target_arch% > nul 2> nul
mkdir node-v%FULLVERSION%-win-%target_arch%\node_modules > nul 2>nul
copy /Y node.exe node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy node.exe && goto package_error
copy /Y ..\LICENSE node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy LICENSE && goto package_error
copy /Y ..\README.md node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy README.md && goto package_error
copy /Y ..\CHANGELOG.md node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy CHANGELOG.md && goto package_error
robocopy /e ..\deps\npm node-v%FULLVERSION%-win-%target_arch%\node_modules\npm > nul
if errorlevel 8 echo Cannot copy npm package && goto package_error
copy /Y ..\deps\npm\bin\npm node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy npm && goto package_error
copy /Y ..\deps\npm\bin\npm.cmd node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy npm.cmd && goto package_error
copy /Y ..\tools\msvs\nodevars.bat node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy nodevars.bat && goto package_error
if not defined noetw (
copy /Y ..\src\res\node_etw_provider.man node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy node_etw_provider.man && goto package_error
)
if not defined noperfctr (
copy /Y ..\src\res\node_perfctr_provider.man node-v%FULLVERSION%-win-%target_arch%\ > nul
if errorlevel 1 echo Cannot copy node_perfctr_provider.man && goto package_error
)
echo Creating node-v%FULLVERSION%-win-%target_arch%.7z
del node-v%FULLVERSION%-win-%target_arch%.7z > nul 2> nul
7z a -r -mx9 -t7z node-v%FULLVERSION%-win-%target_arch%.7z node-v%FULLVERSION%-win-%target_arch% > nul
if errorlevel 1 echo Cannot create node-v%FULLVERSION%-win-%target_arch%.7z && goto package_error
echo Creating node-v%FULLVERSION%-win-%target_arch%.zip
del node-v%FULLVERSION%-win-%target_arch%.zip > nul 2> nul
7z a -r -mx9 -tzip node-v%FULLVERSION%-win-%target_arch%.zip node-v%FULLVERSION%-win-%target_arch% > nul
if errorlevel 1 echo Cannot create node-v%FULLVERSION%-win-%target_arch%.zip && goto package_error
echo Creating node_pdb.7z
del node_pdb.7z > nul 2> nul
7z a -mx9 -t7z node_pdb.7z node.pdb > nul
echo Creating node_pdb.zip
del node_pdb.zip > nul 2> nul
7z a -mx9 -tzip node_pdb.zip node.pdb > nul
cd ..
echo Package created!
goto package_done
:package_error
cd ..
return 1
}
function msi
{
# Skip msi generation if not r-eqested
if (not defined msi) {return run}
else {return msibuild}
}
function msibuild
{
echo Building node-v%FULLVERSION%-%target_arch%.msi
msbuild "%~dp0tools\msvs\msi\nodemsi.sln" /m /t:Clean,Build /p:PlatformToolset=%PLATFORM_TOOLSET% /p:GypMsvsVersion=%GYP_MSVS_VERSION% /p:Configuration=%config% /p:Platform=%target_arch% /p:NodeVersion=%NODE_VERSION% /p:FullVersion=%FULLVERSION% /p:DistTypeDir=%DISTTYPEDIR% %noetw_msi_arg% %noperfctr_msi_arg% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
if (errorlevel 1) {return}
if (not defined sign) { return upload }
call tools\sign.bat node-v%FULLVERSION%-%target_arch%.msi
if (errorlevel 1) {
echo Failed to sign msi
return
}
}
function upload
{
# Skip upload if not r-eqested
if (not defined upload) {return run}
if (not defined SSHCONFIG) {
echo SSHCONFIG is not set for upload
return 1
}
if (not defined STAGINGSERVER) { set STAGINGSERVER=node-www }
ssh -F %SSHCONFIG% %STAGINGSERVER% "mkdir -p nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%"
scp -F %SSHCONFIG% Release\node.exe %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.exe
scp -F %SSHCONFIG% Release\node.lib %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.lib
scp -F %SSHCONFIG% Release\node_pdb.zip %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node_pdb.zip
scp -F %SSHCONFIG% Release\node_pdb.7z %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node_pdb.7z
scp -F %SSHCONFIG% Release\node-v%FULLVERSION%-win-%target_arch%.7z %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-win-%target_arch%.7z
scp -F %SSHCONFIG% Release\node-v%FULLVERSION%-win-%target_arch%.zip %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-win-%target_arch%.zip
scp -F %SSHCONFIG% node-v%FULLVERSION%-%target_arch%.msi %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/
ssh -F %SSHCONFIG% %STAGINGSERVER% "touch nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-%target_arch%.msi.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-win-%target_arch%.zip.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-win-%target_arch%.7z.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%.done && chmod -R ug=rw-x+X,o=r+X nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-%target_arch%.* nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%*"
}
# Run tests if reqested.
function run
{
# Build test/gc add-on if r-eqired.
if ("%build_testgc_addon%" -eq "") { return build-addons }
"%config%\node" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%~dp0test\gc" --nodedir="%~dp0."
if (errorlevel 1) { build-testgc-addon-failed }
return build-addons
}
function build-testgc-addon-failed
{
echo "Failed to build test/gc add-on."
}
function build-addons
{
if (not defined build_addons) { return build-addons-napi }
if (not exist "%node_exe%") {
echo Failed to find node.exe
exit(1)
}
echo Building addons
# clear
for (/d %%F in (test\addons\??_*)) {
rd /s /q %%F
}
# generate
"%node_exe%" tools\doc\addon-verify.js
if ($? -ne 0) { return $? }
# building addons
setlocal EnableDelayedExpansion
for (/d %%F in (test\addons\*)) {
"%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%%F" --nodedir="%cd%"
if (!errorlevel! neq 0) { return !errorlevel! }
}
build-addons-napi
}
function build-addons-napi
{
if not defined build_addons_napi return run-tests
if not exist "%node_exe%" {
echo Failed to find node.exe
exit(1)
}
echo Building addons-napi
:: clear
for /d %%F in (test\addons-napi\??_*) do (
rd /s /q %%F
)
:: building addons-napi
for /d %%F in (test\addons-napi\*) do (
"%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild ^
--directory="%%F" ^
--nodedir="%cd%"
)
endlocal
return run-tests
}
function run-tests
{
if not defined test_node_inspect return node-tests
set USE_EMBEDDED_NODE_INSPECT=1
%config%\node tools\test-npm-package.js --install deps\node-inspect test
return node-tests
}
function node-tests
{
if "%test_args%" -eq "" return cpplint
if "%config%" -eq "Debug" set test_args=--mode=debug %test_args%
if "%config%" -eq "Release" set test_args=--mode=release %test_args%
echo running 'cctest %cctest_args%'
"%config%\cctest" %cctest_args%
echo running 'python tools\test.py %test_args%'
python tools\test.py %test_args%
return cpplint
}
function cpplint {
if not defined cpplint return jslint()
echo running cpplint
set cppfilelist=
setlocal enabledelayedexpansion
for /f "tokens=*" %%G in ('dir /b /s /a src\*.c src\*.cc src\*.h ^
test\addons\*.cc test\addons\*.h test\cctest\*.cc test\cctest\*.h ^
test\gc\binding.cc tools\icu\*.cc tools\icu\*.h') do (
set relpath=%%G
set relpath=!relpath:*%~dp0=!
add-to-list !relpath!
)
( endlocal
set cppfilelist=%localcppfilelist%
)
python tools/cpplint.py %cppfilelist%
python tools/check-imports.py
return jslint()
}
function add-to-list(p)
{
param( [string]$path-item )
$path-item | findstr /c:"src\node_root_certs.h"
if $? -eq 0 return
$path-item | findstr /c:"src\queue.h"
if $? -eq 0 return
$path-item | findstr /c:"src\tree.h"
if $? -eq 0 return
# skip subfolders under /src
$path-item | findstr /r /c:"src\\.*\\.*"
if $? -eq 0 return
$path-item | findstr /r /c:"test\\addons\\[0-9].*_.*\.h"
if $? -eq 0 return
$path-item | findstr /r /c:"test\\addons\\[0-9].*_.*\.cc"
if $? -eq 0 return
set "localcppfilelist=%localcppfilelist% %1"
return
}
function jslint
{
if defined jslint_ci & $jslint-ci
if not defined jslint return
if not exist tools\eslint\lib\eslint.js $ $no-lint
echo running jslint
%config%\node tools\eslint\bin\eslint.js --cache --rule "linebreak-style: 0" --rulesdir=tools\eslint-rules benchmark lib test tools
return
$jslint-ci = {
echo running jslint-ci
%config%\node tools\jslint.js -J -f tap -o test-eslint.tap benchmark lib test tools
return
}
$no-lint = {
echo Linting is not available through the source tarball.
echo Use the git repo instead: $ git clone https://github.com/nodejs/node.git
return
}
}
function create-msvs-files-failed
{
echo Failed to create vc project files.
exit(0)
}
function help
{
echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-inspector/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [small-icu/full-icu/without-intl] [nobuild] [sign] [x86/x64] [vc2015] [download-all] [enable-vtune] [lint/lint-ci]
echo Examples:
echo vcbuild.bat : builds release build
echo vcbuild.bat debug : builds debug build
echo vcbuild.bat release msi : builds release build and MSI installer package
echo vcbuild.bat test : builds debug build and runs tests
echo vcbuild.bat build-release : builds the release distribution as used by nodejs.org
echo vcbuild.bat enable-vtune : builds nodejs with Intel VTune profiling support to profile JavaScript
exit(0)
}
# ***************
# Subroutines
# ***************
function getnodeversion
{
$NODE_VERSION=
$TAG=
$FULLVERSION=
for /F "usebackq tokens=*" %%i in (`python "%~dp0tools\getnodeversion.py"`) do $NODE_VERSION=%%i
if not defined NODE_VERSION (
echo Cannot determine current version of Node.js
exit /b 1
)
if not defined DISTTYPE $DISTTYPE=release
if "%DISTTYPE%" -eq "release" (
$FULLVERSION=%NODE_VERSION%
return
)
if "%DISTTYPE%" -eq "custom" (
if not defined CUSTOMTAG (
echo "CUSTOMTAG is not set for DISTTYPE=custom"
exit /b 1
)
$TAG=%CUSTOMTAG%
)
if not "%DISTTYPE%" -eq "custom" (
if not defined DATESTRING (
echo "DATESTRING is not set for nightly"
exit /b 1
)
if not defined COMMIT (
echo "COMMIT is not set for nightly"
exit /b 1
)
if not "%DISTTYPE%" -eq "nightly" (
if not "%DISTTYPE%" -eq "next-nightly" (
echo "DISTTYPE is not release, custom, nightly or next-nightly"
exit /b 1
)
)
$TAG=%DISTTYPE%%DATESTRING%%COMMIT%
)
$FULLVERSION=%NODE_VERSION%-%TAG%
}
:exit
if not defined DISTTYPEDIR $DISTTYPEDIR=%DISTTYPE%
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment