build: windows signing should include timestamps
[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 if defined NIGHTLY set TAG=nightly-%NIGHTLY%
88
89 @rem Generate the VS project.
90 SETLOCAL
91   if defined VS100COMNTOOLS call "%VS100COMNTOOLS%\VCVarsQueryRegistry.bat"
92   python configure %debug_arg% %nosnapshot_arg% %noetw_arg% %noperfctr_arg% --dest-cpu=%target_arch% --tag=%TAG%
93   if errorlevel 1 goto create-msvs-files-failed
94   if not exist node.sln goto create-msvs-files-failed
95   echo Project files generated.
96 ENDLOCAL
97
98 :msbuild
99 @rem Skip project generation if requested.
100 if defined nobuild goto sign
101
102 @rem Look for Visual Studio 2013
103 if not defined VS120COMNTOOLS goto vc-set-2012
104 if not exist "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2012
105 call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat"
106 if not defined VCINSTALLDIR goto msbuild-not-found
107 set GYP_MSVS_VERSION=2013
108 goto msbuild-found
109
110 :vc-set-2012
111 @rem Look for Visual Studio 2012
112 if not defined VS110COMNTOOLS goto vc-set-2010
113 if not exist "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2010
114 call "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat"
115 if not defined VCINSTALLDIR goto msbuild-not-found
116 set GYP_MSVS_VERSION=2012
117 goto msbuild-found
118
119 :vc-set-2010
120 if not defined VS100COMNTOOLS goto msbuild-not-found
121 if not exist "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" goto msbuild-not-found
122 call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat"
123 if not defined VCINSTALLDIR goto msbuild-not-found
124 goto msbuild-found
125
126 :msbuild-not-found
127 echo Build skipped. To build, this file needs to run from VS cmd prompt.
128 goto run
129
130 :msbuild-found
131 @rem Build the sln with msbuild.
132 msbuild node.sln /m /t:%target% /p:Configuration=%config% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
133 if errorlevel 1 goto exit
134
135 :sign
136 @rem Skip signing if the `nosign` option was specified.
137 if defined nosign goto licensertf
138
139 signtool sign /a /d "Node.js" /t http://timestamp.globalsign.com/scripts/timestamp.dll Release\node.exe
140 if errorlevel 1 echo Failed to sign exe&goto exit
141
142 :licensertf
143 @rem Skip license.rtf generation if not requested.
144 if not defined licensertf goto msi
145
146 %config%\node tools\license2rtf.js < LICENSE > %config%\license.rtf
147 if errorlevel 1 echo Failed to generate license.rtf&goto exit
148
149 :msi
150 @rem Skip msi generation if not requested
151 if not defined msi goto run
152 call :getnodeversion
153
154 if not defined NIGHTLY goto msibuild
155 set NODE_VERSION=%NODE_VERSION%.%NIGHTLY%
156
157 :msibuild
158 echo Building node-%NODE_VERSION%
159 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
160 if errorlevel 1 goto exit
161
162 if defined nosign goto run
163 signtool sign /a /d "Node.js" /t http://timestamp.globalsign.com/scripts/timestamp.dll Release\node-v%NODE_VERSION%-%msiplatform%.msi
164 if errorlevel 1 echo Failed to sign msi&goto exit
165
166 :run
167 @rem Run tests if requested.
168 if "%test%"=="" goto exit
169
170 if "%config%"=="Debug" set test_args=--mode=debug
171 if "%config%"=="Release" set test_args=--mode=release
172
173 if "%test%"=="test" set test_args=%test_args% simple message
174 if "%test%"=="test-internet" set test_args=%test_args% internet
175 if "%test%"=="test-pummel" set test_args=%test_args% pummel
176 if "%test%"=="test-simple" set test_args=%test_args% simple
177 if "%test%"=="test-message" set test_args=%test_args% message
178 if "%test%"=="test-gc" set test_args=%test_args% gc
179 if "%test%"=="test-all" set test_args=%test_args%
180
181 :build-node-weak
182 @rem Build node-weak if required
183 if "%buildnodeweak%"=="" goto run-tests
184 "%config%\node" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%~dp0test\gc\node_modules\weak" --nodedir="%~dp0."
185 if errorlevel 1 goto build-node-weak-failed
186 goto run-tests
187
188 :build-node-weak-failed
189 echo Failed to build node-weak.
190 goto exit
191
192 :run-tests
193 echo running 'python tools/test.py %test_args%'
194 python tools/test.py %test_args%
195 if "%test%"=="test" goto jslint
196 goto exit
197
198 :create-msvs-files-failed
199 echo Failed to create vc project files. 
200 goto exit
201
202 :upload
203 echo uploading .exe .msi .pdb to nodejs.org
204 call :getnodeversion
205 @echo on
206 ssh node@nodejs.org mkdir -p web/nodejs.org/dist/v%NODE_VERSION%
207 scp Release\node.msi node@nodejs.org:~/web/nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%.msi
208 scp Release\node.exe node@nodejs.org:~/web/nodejs.org/dist/v%NODE_VERSION%/node.exe
209 scp Release\node.pdb node@nodejs.org:~/web/nodejs.org/dist/v%NODE_VERSION%/node.pdb
210 @echo off
211 goto exit
212
213 :jslint
214 echo running jslint
215 set PYTHONPATH=tools/closure_linter/
216 python tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
217 goto exit
218
219 :help
220 echo vcbuild.bat [debug/release] [msi] [test-all/test-uv/test-internet/test-pummel/test-simple/test-message] [clean] [noprojgen] [nobuild] [nosign] [x86/x64]
221 echo Examples:
222 echo   vcbuild.bat                : builds release build
223 echo   vcbuild.bat debug          : builds debug build
224 echo   vcbuild.bat release msi    : builds release build and MSI installer package
225 echo   vcbuild.bat test           : builds debug build and runs tests
226 goto exit
227
228 :exit
229 goto :EOF
230
231 rem ***************
232 rem   Subroutines
233 rem ***************
234
235 :getnodeversion
236 set NODE_VERSION=
237 for /F "usebackq tokens=*" %%i in (`python "%~dp0tools\getnodeversion.py"`) do set NODE_VERSION=%%i
238 if not defined NODE_VERSION echo Cannot determine current version of node.js & exit /b 1
239 goto :EOF