Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

426 lines
12 KiB

  1. @echo off
  2. if defined _echo echo on
  3. if defined verbose echo on
  4. setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  5. REM -------------------------------------------------------------------------------------------
  6. REM Template for the postbuild scripts:
  7. REM SD Location: %sdxroot%\tools\postbuildscripts
  8. REM
  9. REM (1) Code section description:
  10. REM PreMain - Developer adaptable code. Use this model and add your script params
  11. REM Main - Developer code section. This is where your work gets done.
  12. REM PostMain - Logging support code. No changes should be made here.
  13. REM
  14. REM (2) GetParams.pm - Usage
  15. REM run perl.exe GetParams.pm /? for complete usage
  16. REM
  17. REM (3) Reserved Variables -
  18. REM lang - The specified language. Defaults to USA.
  19. REM logfile - The path and filename of the logs file.
  20. REM logfile_bak - The path and filename of the logfile.
  21. REM errfile - The path and filename of the error file.
  22. REM tmpfile - The path and filename of the temp file.
  23. REM errors - The scripts errorlevel.
  24. REM script_name - The script name.
  25. REM script_args - The arguments passed to the script.
  26. REM CMD_LINE - The script name plus arguments passed to the script.
  27. REM _NTPostBld - Abstracts the language from the files path that
  28. REM postbuild operates on.
  29. REM
  30. REM (4) Reserved Subs -
  31. REM Usage - Use this sub to discribe the scripts usage.
  32. REM ValidateParams - Use this sub to verify the parameters passed to the script.
  33. REM
  34. REM
  35. REM (8) Do not turn echo off, copy the 3 lines from the beginning of the template
  36. REM instead.
  37. REM
  38. REM (9) Use setlocal/endlocal as in this template.
  39. REM
  40. REM (10)Have your changes reviewed by a member of the US build team (ntbusa) and
  41. REM by a member of the international build team (ntbintl).
  42. REM
  43. REM -------------------------------------------------------------------------------------------
  44. REM PreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMain
  45. REM Begin PreProcessing Section - Adapt this section but do not remove support
  46. REM scripts or reorder section.
  47. REM PreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMain
  48. :PreMain
  49. REM
  50. REM Define SCRIPT_NAME. Used by the logging scripts.
  51. REM Define CMD_LINE. Used by the logging scripts.
  52. REM Define SCRIPT_ARGS. Used by the logging scripts.
  53. REM
  54. for %%i in (%0) do set SCRIPT_NAME=%%~ni.cmd
  55. set CMD_LINE=%script_name% %*
  56. set SCRIPT_ARGS=%*
  57. REM
  58. REM Parse the command line arguments - Add your scripts command line arguments
  59. REM as indicated by brackets.
  60. REM For complete usage run: perl.exe GetParams.pm /?
  61. REM
  62. for %%h in (./ .- .) do if ".%SCRIPT_ARGS%." == "%%h?." goto Usage
  63. REM call :GetParams -n <add required prams> -o l:<add optional params> -p "lang <add variable names>" %SCRIPT_ARGS%
  64. call :GetParams -o l: -p "lang" %SCRIPT_ARGS%
  65. if errorlevel 1 goto :End
  66. REM
  67. REM Set up the local enviroment extensions.
  68. REM
  69. call :LocalEnvEx -i
  70. if errorlevel 1 goto :End
  71. REM
  72. REM Validate the command line parameters.
  73. REM
  74. call :ValidateParams
  75. if errorlevel 1 goto :End
  76. REM
  77. REM Execute Main
  78. REM
  79. call :Main
  80. :End_PreMain
  81. goto PostMain
  82. REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  83. REM Begin Main code section
  84. REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  85. REM (5) Call other executables or command scripts by using:
  86. REM call ExecuteCmd.cmd "<command>"
  87. REM Check for errors by using:
  88. REM if errorlevel 1 ...
  89. REM Note that the executable/script you're calling with ExecuteCmd must return a
  90. REM non-zero value on errors to make the error checking mechanism work.
  91. REM
  92. REM Example
  93. REM call ExecuteCmd.cmd "xcopy /f foo1 foo2"
  94. REM if errorlevel 1 (
  95. REM set errors=%errorlevel%
  96. REM goto end
  97. REM )
  98. REM
  99. REM (6) Log non-error information by using:
  100. REM call logmsg.cmd "<log message>"
  101. REM and log error information by using:
  102. REM call errmsg.cmd "<error message>"
  103. REM
  104. REM (7) Exit from the option routines with
  105. REM set errors=%errorlevel%
  106. REM goto end
  107. REM if errors found during execution and with
  108. REM goto end
  109. REM otherwise.
  110. :Main
  111. REM Main code section
  112. REM <Start your script's code here>
  113. if NOT defined OFFICIAL_BUILD_MACHINE (
  114. call logmsg.cmd "Skipping submit_public"
  115. goto end
  116. )
  117. if /i "%__BUILDMACHINE__%" == "LB6RI" (
  118. call logmsg.cmd "Skipping submit_public"
  119. goto end
  120. )
  121. if NOT "%lang%"=="usa" (
  122. call logmsg.cmd "No submit_public for %lang%"
  123. goto end
  124. )
  125. @rem
  126. @rem Build up the list of files we should checkin.
  127. @rem
  128. set _Arch_Submit_Rules=%temp%\SubmitRules%RANDOM%
  129. set _Arch_Submit_Files=%temp%\SubmitFiles%RANDOM%
  130. set _Arch_Submit_Reopen=%temp%\SubmitReopen%RANDOM%
  131. set _sdresults=%TEMP%\sdresults_%RANDOM%
  132. set _Arch_Submit_ChangeNum_Name=SubmitChangeOrder%RANDOM%
  133. set _Arch_Submit_ChangeNum=%_NTDRIVE%%_NTROOT%\public\%_Arch_Submit_ChangeNum_Name%
  134. if NOT defined _BUILDARCH echo Error: Unknown Build architecture&&goto end
  135. if NOT defined _BUILDTYPE echo Error: Unknown Build type&&goto end
  136. if "%_BUILDARCH%" == "x86" set _LIBARCH=i386&& goto LibArchSet
  137. set _LIBARCH=%_BUILDARCH%
  138. :LibArchSet
  139. set ConvertMacro=
  140. @rem First eliminate comments
  141. set ConvertMacro=s/\;.*//g
  142. @rem Then build architecture rules
  143. set ConvertMacro=%ConvertMacro%;s/_BUILDARCH/%_BUILDARCH%/;s/_LIBARCH/%_LIBARCH%/
  144. @rem If this is the primary machine, whack the primary tag
  145. if "%OFFICIAL_BUILD_MACHINE%" == "PRIMARY" set ConvertMacro=%ConvertMacro%;s/PRIMARY/%_BUILDARCH%%_BUILDTYPE%/
  146. @rem and print out the results.
  147. set ConvertMacro=%ConvertMacro%;print $_;
  148. @rem run the results over the rules file to get the rules for this architecture.
  149. perl -n -e "%ConvertMacro%" < %RazzleToolPath%\PostBuildScripts\submit_rules.txt > %_Arch_Submit_rules%
  150. @rem
  151. @rem Now, based on the submit rules for this architecture, let's see what files
  152. @rem we have checked out that need to be updated.
  153. @rem
  154. pushd %_NTDRIVE%%_NTROOT%\public
  155. @rem
  156. @rem Check for old edit_public turds. Make sure they're handled first.
  157. @rem
  158. if exist publish.log_* do (
  159. for %%x in (publish.log_*) do (
  160. type %%x >> publish.log
  161. del %%x
  162. )
  163. call edit_public.cmd
  164. )
  165. if not exist %_NTDRIVE%%_NTROOT%\public\PUBLIC_CHANGENUM.SD (
  166. call errmsg.cmd "%_NTDRIVE%%_NTROOT%\public\PUBLIC_CHANGENUM.SD is missing."
  167. call errmsg.cmd "Open a new razzle window and redo your build."
  168. goto TheEnd
  169. )
  170. set sderror=FALSE
  171. for /f "tokens=2" %%i in (PUBLIC_CHANGENUM.SD) do (
  172. @for /f "tokens=2 delims=," %%j in ('findstr %_BUILDARCH%%_BUILDTYPE% %_Arch_Submit_Rules%') do (
  173. sd opened -l -c %%i %%j >> %_Arch_Submit_Files%
  174. if %errorlevel% GEQ 1 set sderror=TRUE
  175. )
  176. )
  177. if not exist %_Arch_Submit_Files% goto RevertLeftovers
  178. for /f %%x in ('findstr /c:"error:" %_Arch_Submit_Files%') do (
  179. set sderror=TRUE
  180. )
  181. if NOT "%sderror%" == "FALSE" (
  182. call errmsg.cmd "Error talking to SD depot - Try again later"
  183. goto TheEnd
  184. )
  185. @rem
  186. @rem We have a list of files that this machine s/b checking in.
  187. @rem See if it's non-zero. While we're at it, create a stripped flavor
  188. @rem of the file list that has the #ver goo removed from each line.
  189. @rem
  190. set FilesToSubmit=
  191. for /f "delims=#" %%i in (%_Arch_Submit_Files%) do (
  192. set FilesToSubmit=1
  193. echo %%i>> %_Arch_Submit_Reopen%
  194. )
  195. if not defined FilesToSubmit goto RevertLeftovers
  196. @rem
  197. @rem Fetch the build date info.
  198. @rem
  199. if not exist %_NTBINDIR%\__blddate__ goto TheEnd
  200. for /f "tokens=2 delims==" %%i in (%_NTBINDIR%\__blddate__) do (
  201. set __BuildDate=%%i
  202. )
  203. if not defined __BuildDate (
  204. call errmsg.cmd "Unable to get build date for the public changes."
  205. goto TheEnd
  206. )
  207. @rem
  208. @rem Get a new changenum for the checkin.
  209. @rem
  210. call get_change_num.cmd PUBLIC %_Arch_Submit_ChangeNum_Name% "Public Changes for %__BuildDate%/%_BUILDARCH%%_BUILDTYPE%"
  211. if not exist %_Arch_Submit_ChangeNum% (
  212. call errmsg.cmd "Unable to get a changenum for the public changes."
  213. goto TheEnd
  214. )
  215. set ReopenChangenum=
  216. for /f "tokens=2" %%i in (%_Arch_Submit_ChangeNum%) do (
  217. set ReopenChangenum=%%i
  218. )
  219. @rem
  220. @rem Reopen the public files with the new changenum
  221. @rem
  222. set sderror=FALSE
  223. sd -x %_Arch_Submit_Reopen% reopen -c %ReopenChangenum% > %_sdresults%
  224. if %errorlevel% GEQ 1 set sderror=TRUE
  225. for /f %%x in ('findstr /c:"error:" %_sdresults%') do (
  226. set sderror=TRUE
  227. )
  228. if NOT "%sderror%" == "FALSE" (
  229. call errmsg.cmd "Error talking to SD depot - Try again later"
  230. goto TheEnd
  231. )
  232. @rem
  233. @rem And submit the changes.
  234. @rem
  235. set sderror=FALSE
  236. set _RetrySubmit_=
  237. :RetrySubmit
  238. sd submit -c %ReopenChangenum% > %_sdresults%
  239. @rem If there's a resolve conflict - force it to accept this one and retry.
  240. if NOT "%_RetrySubmit_%" == "" goto CheckSdSubmitErrors
  241. for /f %%x in ('findstr /c:"resolve" %_sdresults%') do (
  242. set _RetrySubmit_=1
  243. sd resolve -ay
  244. )
  245. if NOT "%_RetrySubmit_%" == "" goto RetrySubmit
  246. :CheckSdSubmitErrors
  247. if %errorlevel% GEQ 1 set sderror=TRUE
  248. for /f %%x in ('findstr /c:"error:" %_sdresults%') do (
  249. set sderror=TRUE
  250. )
  251. if NOT "%sderror%" == "FALSE" (
  252. call errmsg.cmd "Unable to access SD depot - Submit change %ReopenChangenum% manually"
  253. goto TheEnd
  254. )
  255. @echo Files submitted for this build
  256. @echo ==============================
  257. @type %_Arch_Submit_Reopen%
  258. :TheEnd
  259. if exist %_Arch_Submit_Rules% del %_Arch_Submit_Rules%
  260. if exist %_Arch_Submit_Files% del %_Arch_Submit_Files%
  261. if exist %_Arch_Submit_Reopen% del %_Arch_Submit_Reopen%
  262. if exist %_Arch_Submit_ChangeNum% del %_Arch_Submit_ChangeNum%
  263. if exist %_sdresults% del %_sdresults%
  264. popd
  265. goto end
  266. :RevertLeftovers
  267. echo Nothing to submit
  268. goto TheEnd
  269. goto end
  270. :ValidateParams
  271. REM
  272. REM Validate the option given as parameter.
  273. REM
  274. goto end
  275. :Usage
  276. REM Usage of the script
  277. REM If errors, goto errend
  278. echo Usage: %script_name% [-l lang][-?]
  279. echo -l lang 2-3 letter language identifier
  280. echo -? Displays usage
  281. set ERRORS=1
  282. goto end
  283. REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  284. REM End Main code section
  285. REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  286. :End_Main
  287. goto PostMain
  288. REM SupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubs
  289. REM Support Subs - Do not touch this section!
  290. REM SupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubs
  291. :GetParams
  292. REM
  293. REM Parse the command line arguments
  294. REM
  295. set ERRORS=0
  296. for %%h in (./ .- .) do if ".%SCRIPT_ARGS%." == "%%h?." goto Usage
  297. pushd %RazzleToolPath%\PostBuildScripts
  298. set ERRORS=0
  299. for /f "tokens=1 delims=;" %%c in ('perl.exe GetParams.pm %*') do (
  300. set commandline=%%c
  301. set commandtest=!commandline:~0,3!
  302. if /i "!commandtest!" neq "set" (
  303. if /i "!commandtest!" neq "ech" (
  304. echo %%c
  305. ) else (
  306. %%c
  307. )
  308. ) else (
  309. %%c
  310. )
  311. )
  312. if "%errorlevel%" neq "0" (
  313. set ERRORS=%errorlevel%
  314. goto end
  315. )
  316. popd
  317. goto end
  318. :LocalEnvEx
  319. REM
  320. REM Manage local script environment extensions
  321. REM
  322. pushd %RazzleToolPath%\PostBuildScripts
  323. for /f "tokens=1 delims=;" %%c in ('perl.exe LocalEnvEx.pm %1') do (
  324. set commandline=%%c
  325. set commandtest=!commandline:~0,3!
  326. if /i "!commandtest!" neq "set" (
  327. if /i "!commandtest!" neq "ech" (
  328. echo %%c
  329. ) else (
  330. %%c
  331. )
  332. ) else (
  333. %%c
  334. )
  335. )
  336. if "%errorlevel%" neq "0" (
  337. set errors=%errorlevel%
  338. goto end
  339. )
  340. popd
  341. goto end
  342. :end
  343. seterror.exe "%errors%"& goto :EOF
  344. REM PostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMain
  345. REM Begin PostProcessing - Do not touch this section!
  346. REM PostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMain
  347. :PostMain
  348. REM
  349. REM End the local environment extensions.
  350. REM
  351. call :LocalEnvEx -e
  352. REM
  353. REM Check for errors
  354. REM
  355. endlocal& seterror.exe "%errors%"