windows: improve Visual Studio Express build support
[platform/upstream/nodejs.git] / vcbuild.bat
1 @echo off
2
3 cd %~dp0
4
5 if /i "%1"=="help" goto help
6 if /i "%1"=="--help" goto help
7 if /i "%1"=="-help" goto help
8 if /i "%1"=="/help" goto help
9 if /i "%1"=="?" goto help
10 if /i "%1"=="-?" goto help
11 if /i "%1"=="--?" goto help
12 if /i "%1"=="/?" goto help
13
14 @rem Process arguments.
15 set config=Release
16 set msiplatform=x86
17 set target=Build
18 set target_arch=ia32
19 set debug_arg=
20 set nosnapshot_arg=
21 set noprojgen=
22 set nobuild=
23 set nosign=
24 set nosnapshot=
25 set test=
26 set test_args=
27 set msi=
28 set licensertf=
29 set upload=
30 set jslint=
31 set buildnodeweak=
32 set noetw=
33 set noetw_arg=
34 set noetw_msi_arg=
35 set noperfctr=
36 set noperfctr_arg=
37 set noperfctr_msi_arg=
38
39 :next-arg
40 if "%1"=="" goto args-done
41 if /i "%1"=="debug"         set config=Debug&goto arg-ok
42 if /i "%1"=="release"       set config=Release&goto arg-ok
43 if /i "%1"=="clean"         set target=Clean&goto arg-ok
44 if /i "%1"=="ia32"          set target_arch=ia32&goto arg-ok
45 if /i "%1"=="x86"           set target_arch=ia32&goto arg-ok
46 if /i "%1"=="x64"           set target_arch=x64&goto arg-ok
47 if /i "%1"=="noprojgen"     set noprojgen=1&goto arg-ok
48 if /i "%1"=="nobuild"       set nobuild=1&goto arg-ok
49 if /i "%1"=="nosign"        set nosign=1&goto arg-ok
50 if /i "%1"=="nosnapshot"    set nosnapshot=1&goto arg-ok
51 if /i "%1"=="noetw"         set noetw=1&goto arg-ok
52 if /i "%1"=="noperfctr"     set noperfctr=1&goto arg-ok
53 if /i "%1"=="licensertf"    set licensertf=1&goto arg-ok
54 if /i "%1"=="test-uv"       set test=test-uv&goto arg-ok
55 if /i "%1"=="test-internet" set test=test-internet&goto arg-ok
56 if /i "%1"=="test-pummel"   set test=test-pummel&goto arg-ok
57 if /i "%1"=="test-simple"   set test=test-simple&goto arg-ok
58 if /i "%1"=="test-message"  set test=test-message&goto arg-ok
59 if /i "%1"=="test-gc"       set test=test-gc&set buildnodeweak=1&goto arg-ok
60 if /i "%1"=="test-all"      set test=test-all&set buildnodeweak=1&goto arg-ok
61 if /i "%1"=="test"          set test=test&goto arg-ok
62 if /i "%1"=="msi"           set msi=1&set licensertf=1&goto arg-ok
63 if /i "%1"=="upload"        set upload=1&goto arg-ok
64 if /i "%1"=="jslint"        set jslint=1&goto arg-ok
65
66 echo Warning: ignoring invalid command line option `%1`.
67
68 :arg-ok
69 :arg-ok
70 shift
71 goto next-arg
72
73 :args-done
74 if defined upload goto upload
75 if defined jslint goto jslint
76
77 if "%config%"=="Debug" set debug_arg=--debug
78 if "%target_arch%"=="x64" set msiplatform=x64
79 if defined nosnapshot set nosnapshot_arg=--without-snapshot
80 if defined noetw set noetw_arg=--without-etw& set noetw_msi_arg=/p:NoETW=1
81 if defined noperfctr set noperfctr_arg=--without-perfctr& set noperfctr_msi_arg=/p:NoPerfCtr=1
82
83 :project-gen
84 @rem Skip project generation if requested.
85 if defined noprojgen goto msbuild
86
87 @rem Generate the VS project.
88 SETLOCAL
89   if defined VS100COMNTOOLS call "%VS100COMNTOOLS%\VCVarsQueryRegistry.bat"
90   python configure %debug_arg% %nosnapshot_arg% %noetw_arg% %noperfctr_arg% --dest-cpu=%target_arch%
91   if errorlevel 1 goto create-msvs-files-failed
92   if not exist node.sln goto create-msvs-files-failed
93   echo Project files generated.
94 ENDLOCAL
95
96 :msbuild
97 @rem Skip project generation if requested.
98 if defined nobuild goto sign
99
100 @rem Bail out early if not running in VS build env.
101 if defined VCINSTALLDIR goto msbuild-found
102 if not defined VS100COMNTOOLS goto msbuild-not-found
103 if not exist "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" goto msbuild-not-found
104 call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat"
105 if not defined VCINSTALLDIR goto msbuild-not-found
106 goto msbuild-found
107
108 :msbuild-not-found
109 echo Build skipped. To build, this file needs to run from VS cmd prompt.
110 goto run
111
112 :msbuild-found
113 @rem Build the sln with msbuild.
114 msbuild node.sln /m /t:%target% /p:Configuration=%config% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
115 if errorlevel 1 goto exit
116
117 :sign
118 @rem Skip signing if the `nosign` option was specified.
119 if defined nosign goto licensertf
120
121 signtool sign /a Release\node.exe
122
123 :licensertf
124 @rem Skip license.rtf generation if not requested.
125 if not defined licensertf goto msi
126
127 %config%\node tools\license2rtf.js < LICENSE > %config%\license.rtf
128 if errorlevel 1 echo Failed to generate license.rtf&goto exit
129
130 :msi
131 @rem Skip msi generation if not requested
132 if not defined msi goto run
133 python "%~dp0tools\getnodeversion.py" > "%temp%\node_version.txt"
134 if not errorlevel 0 echo Cannot determine current version of node.js & goto exit
135 for /F "tokens=*" %%i in (%temp%\node_version.txt) do set NODE_VERSION=%%i
136 msbuild "%~dp0tools\msvs\msi\nodemsi.sln" /m /t:Clean,Build /p:Configuration=%config% /p:Platform=%msiplatform% /p:NodeVersion=%NODE_VERSION% %noetw_msi_arg% %noperfctr_msi_arg% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
137 if errorlevel 1 goto exit
138
139 if defined nosign goto run
140 signtool sign /a Release\node-v%NODE_VERSION%-%msiplatform%.msi
141
142 :run
143 @rem Run tests if requested.
144 if "%test%"=="" goto exit
145
146 if "%config%"=="Debug" set test_args=--mode=debug
147 if "%config%"=="Release" set test_args=--mode=release
148
149 if "%test%"=="test" set test_args=%test_args% simple message
150 if "%test%"=="test-internet" set test_args=%test_args% internet
151 if "%test%"=="test-pummel" set test_args=%test_args% pummel
152 if "%test%"=="test-simple" set test_args=%test_args% simple
153 if "%test%"=="test-message" set test_args=%test_args% message
154 if "%test%"=="test-gc" set test_args=%test_args% gc
155 if "%test%"=="test-all" set test_args=%test_args%
156
157 :build-node-weak
158 @rem Build node-weak if required
159 if "%buildnodeweak%"=="" goto run-tests
160 "%config%\node" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%~dp0test\gc\node_modules\weak" --nodedir="%~dp0."
161 if errorlevel 1 goto build-node-weak-failed
162 goto run-tests
163
164 :build-node-weak-failed
165 echo Failed to build node-weak.
166 goto exit
167
168 :run-tests
169 echo running 'python tools/test.py %test_args%'
170 python tools/test.py %test_args%
171 if "%test%"=="test" goto jslint
172 goto exit
173
174 :create-msvs-files-failed
175 echo Failed to create vc project files. 
176 goto exit
177
178 :upload
179 echo uploading .exe .msi .pdb to nodejs.org
180 python "%~dp0tools\getnodeversion.py" > "%temp%\node_version.txt"
181 if not errorlevel 0 echo Cannot determine current version of node.js & goto exit
182 for /F "tokens=*" %%i in (%temp%\node_version.txt) do set NODE_VERSION=%%i
183 @echo on
184 ssh node@nodejs.org mkdir -p web/nodejs.org/dist/v%NODE_VERSION%
185 scp Release\node.msi node@nodejs.org:~/web/nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%.msi
186 scp Release\node.exe node@nodejs.org:~/web/nodejs.org/dist/v%NODE_VERSION%/node.exe
187 scp Release\node.pdb node@nodejs.org:~/web/nodejs.org/dist/v%NODE_VERSION%/node.pdb
188 @echo off
189 goto exit
190
191 :jslint
192 echo running jslint
193 set PYTHONPATH=tools/closure_linter/
194 python tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
195 goto exit
196
197 :help
198 echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [nobuild] [nosign] [x86/x64]
199 echo Examples:
200 echo   vcbuild.bat                : builds release build
201 echo   vcbuild.bat debug          : builds debug build
202 echo   vcbuild.bat release msi    : builds release build and MSI installer package
203 echo   vcbuild.bat test           : builds debug build and runs tests
204 goto exit
205
206 :exit