Leaked source code of windows server 2003
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.

355 lines
10 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM CPLocation.cmd - JeremyD
  4. @REM Writes the file build_logs\CPLocation.txt with the location of
  5. @REM the x86 partner build.
  6. @REM
  7. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. @REM
  9. @REM -----------------------------------------------------------------
  10. @if defined _CPCMAGIC goto CPCBegin
  11. @perl -x "%~f0" %*
  12. @goto :EOF
  13. #!perl
  14. use strict;
  15. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  16. use lib $ENV{RAZZLETOOLPATH};
  17. use PbuildEnv;
  18. use ParseArgs;
  19. sub Usage { print<<USAGE; exit(1) }
  20. CPLocation [-l <language>]
  21. Writes the file build_logs\CPLocation.txt with the location of the
  22. x86 partner build. If OFFICIAL_BUILD_MACHINE is set will loop waiting
  23. for a matching build number. Otherwise, just wait for any x86 build
  24. of the same debug type.
  25. USAGE
  26. parseargs('?' => \&Usage);
  27. # *** TEMPLATE CODE ***
  28. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  29. __END__
  30. @:CPCBegin
  31. @set _CPCMAGIC=
  32. @setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  33. @if not defined DEBUG echo off
  34. @REM *** CMD SCRIPT BELOW ***
  35. REM
  36. REM CPLocation.cmd
  37. REM
  38. REM this script is intended to be purely a "helper" script. the idea is to
  39. REM just generate a txt file which lives in %_NTPOSTBLD%\build_logs which
  40. REM contains the location of an x86 machine, share, and dir from which to
  41. REM copy cross-platform files from.
  42. REM
  43. REM this eliminates the need for CopyWow64.cmd and CopyRemoteBoot.cmd to do
  44. REM this work on their own, and will allow further scripts to use the same
  45. REM logic and pull from a share guaranteed to be the same.
  46. REM
  47. REM IMPORTANT:
  48. REM
  49. REM the ordering of this script in pbuild.dat must have its END statement
  50. REM before any dependant scripts (CopyWow64 eg) have their BEGIN statements.
  51. REM this eliminates the timing issue that there might be an old location
  52. REM file that copywow would read instead of getting the new location if one
  53. REM is found.
  54. REM
  55. REM MAJOR CHANGE FROM OLD MECHANISM:
  56. REM
  57. REM i have modified the script so that all OFFICIAL build machines now wait
  58. REM for the current associated build, and that VBLs should NOT use old builds
  59. REM to copy bits from. devs will still do that though.
  60. REM
  61. REM i have also abstracted the release share name for a given branch into the
  62. REM .ini file under the heading AlternateReleaseDir. if not defined, we
  63. REM will use just 'release'.
  64. REM
  65. REM
  66. REM first, some sanity checks
  67. REM
  68. if /i "%_BuildArch%" == "x86" (
  69. REM right now, this is only for Win64 builds
  70. call logmsg.cmd "Skipping, running on an x86 machine ..."
  71. goto :End
  72. )
  73. REM
  74. REM next, delete the old CP Location file
  75. REM
  76. set CPFile=%_NTPOSTBLD%\build_logs\CPLocation.txt
  77. if exist %CPFile% del /f /q %CPFile%
  78. if exist %CPFile% (
  79. call errmsg.cmd "Unable to delete old %CPFile% exiting ..."
  80. goto :End
  81. )
  82. if defined VBL_RELEASE (
  83. for /f "tokens=1,2,3 delims=\" %%a in ("%VBL_RELEASE%") do (
  84. if /i "%%b" neq "" (
  85. set CPLocation=%VBL_RELEASE%
  86. if /i "%_BuildArch%" == "ia64" (
  87. call :UpdateCPLia642x86
  88. )
  89. GOTO PutCPLocationInFile
  90. )
  91. )
  92. )
  93. goto :PassCPLocationia642x86
  94. :UpdateCPLia642x86
  95. set CPLocation=%CPLocation:ia64=x86%
  96. goto :eof
  97. :PassCPLocationia642x86
  98. REM
  99. REM now find the "partner" x86 build machine for this build.
  100. REM we need to match the lab name, debug type, and potentially
  101. REM the language.
  102. REM
  103. REM
  104. REM BUGBUG: i am putting in a STUB for reading a copywow machine
  105. REM name for a given archtype in case intl needs it
  106. REM
  107. set inifile=%RazzleToolPath%\PostBuildScripts\%_BUILDBRANCH%.%lang%.ini
  108. call :CLEARSTAMPS
  109. call :HAVEFRESH %inifile%
  110. :TWITCH
  111. set CommandLine=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  112. set CommandLine=!CommandLine! -l:%lang%
  113. set CommandLine=!CommandLine! -f:CrossPlatformCopyMachine::%_BuildArch%%_BuildType%
  114. %CommandLine% >nul 2>nul
  115. if !ErrorLevel! NEQ 0 (
  116. REM there was an error reading the ini file, assume it's not a problem
  117. REM as the ini might not support CrossPlatformCopyMachine
  118. call logmsg.cmd "CrossPlatformCopyMachine not found in ini file ..."
  119. set CPMachine=
  120. set AltCPLocation=
  121. ) else (
  122. for /f %%a in ('!CommandLine!') do set CPMachine=%%a
  123. set AltCPLocation=
  124. )
  125. REM
  126. REM if no ini setting, read in from buildmachines.txt
  127. REM
  128. if defined CPMachine goto :FoundCPMachine
  129. set _ParamBranch=%_BuildBranch%
  130. if defined VBL_RELEASE (
  131. for /f "tokens=1,2,3 delims=\" %%a in ("%VBL_RELEASE%") do (
  132. if /i "%%b" == "" (
  133. set _ParamBranch=%%a
  134. ) else (
  135. set _ParamBranch=%_BuildBranch%
  136. )
  137. )
  138. )
  139. for /f "tokens=1,3,4,5,7,8 delims=," %%a in (%RazzleToolPath%\BuildMachines.txt) do (
  140. if /i "%%b" == "%_ParamBranch%" (
  141. if /i "%%c" == "x86" (
  142. if /i "%%d" == "%_BuildType%" (
  143. if /i "%%e" == "" (
  144. REM not a distributed machine, just pick this one
  145. set CPMachine=%%a
  146. set AltCPLocation=
  147. ) else (
  148. REM must be a distributed machine, check for the postbuild machine
  149. if /i "%%e" == "postbuild" (
  150. set CPMachine=%%a
  151. set AltCPLocation=%%f
  152. )
  153. )
  154. )
  155. )
  156. )
  157. )
  158. if not defined CPMachine (
  159. call errmsg.cmd "No eligible cross platform machine found, exiting."
  160. goto :End
  161. )
  162. REM
  163. REM at this point, we've found our foreign machine name,
  164. REM now we just need the latest build there
  165. REM
  166. :FoundCPMachine
  167. set LocBuildNum=
  168. REM
  169. REM make sure we can see the release share on the given machine
  170. REM
  171. REM If not an official build, use the alternate release point if available
  172. if not defined OFFICIAL_BUILD_MACHINE if not "" == "%AltCPLocation%" (
  173. set CPShare=%AltCPLocation%
  174. if not exist !CPShare! (
  175. call errmsg.cmd "Unable to see !CPShare! ..."
  176. )
  177. GOTO BeginSleepLoop
  178. )
  179. REM
  180. REM find the release share name for this branch
  181. REM
  182. set CommandLine=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  183. set CommandLine=!CommandLine! -l:%lang%
  184. set CommandLine=!CommandLine! -f:AlternateReleaseDir
  185. %CommandLine% >nul 2>nul
  186. if !ErrorLevel! NEQ 0 (
  187. REM there was an error reading the ini file, assume it's not a problem
  188. REM as the ini might not reference AlternateReleaseDir
  189. set ReleaseShareName=release
  190. ) else (
  191. for /f %%a in ('!CommandLine!') do set ReleaseShareName=%%a
  192. )
  193. if not defined ReleaseShareName (
  194. call logmsg.cmd "No release share name found, using default 'release'"
  195. set ReleaseShareName=release
  196. )
  197. set CPShare=\\%CPMachine%\%ReleaseShareName%
  198. if /i "%lang%" NEQ "usa" set CPShare=%CPShare%\%lang%
  199. REM here's where we loop back to for spooling
  200. :BeginSleepLoop
  201. call :HAVEFRESH %inifile%
  202. if defined Spoiled goto :TWITCH
  203. REM
  204. REM get the latest build name from the foreign machine
  205. REM
  206. REM If not an official build, use the alternate release point if available
  207. if not defined OFFICIAL_BUILD_MACHINE if not "" == "%AltCPLocation%" (
  208. set CPLocation=%CPShare%
  209. if not exist !CPLocation! (
  210. echo !CPLocation! not found, looping back ...
  211. sleep 20
  212. goto :BeginSleepLoop
  213. )
  214. GOTO :PutCPLocationInFile
  215. )
  216. REM else (
  217. REM If the build name matters, limit search
  218. set GetLatestOptions=
  219. if defined OFFICIAL_BUILD_MACHINE (
  220. if not defined LocBuildNum (
  221. for /f %%a in ('%RazzleToolPath%\PostBuildScripts\buildname.cmd build_number') do set LocBuildNum=%%a
  222. )
  223. set GetLatestOptions=-n:!LocBuildNum!
  224. )
  225. if defined OFFICIAL_BUILD_MACHINE (
  226. call logmsg.cmd "Issuing GetLatestRelease for %CPMachine% (build %LocBuildNum%)"
  227. ) else (
  228. call logmsg.cmd "Issuing GetLatestRelease for %CPMachine% ..."
  229. )
  230. for /f %%a in ('%RazzleToolPath%\PostBuildScripts\GetLatestRelease.cmd -m:%CPMachine% -p:x86 -l:%lang% %GetLatestOptions%') do set LatestName=%%a
  231. REM )
  232. :CheckGetLatestResults
  233. REM
  234. REM make sure there was a latest build there
  235. REM
  236. if /i "%LatestName%" == "none" (
  237. echo No latest build found, looping until one is seen ...
  238. sleep 20
  239. goto :BeginSleepLoop
  240. )
  241. REM
  242. REM see if the build number matters, i.e. if we should wait for a
  243. REM more recent build number
  244. REM
  245. call logmsg.cmd "Checking if found build is appropriate ..."
  246. if not defined OFFICIAL_BUILD_MACHINE (
  247. set CPLocation=%CPShare%\%LatestName%
  248. if not exist !CPLocation! (
  249. echo !CPLocation! not found, looping ...
  250. sleep 20
  251. goto :BeginSleepLoop
  252. )
  253. call logmsg.cmd "Found !CPLocation! as most recent build ..."
  254. goto :PutCPLocationInFile
  255. )
  256. REM
  257. REM if we're here, we're an OFFICIAL build machine, and we need builds
  258. REM with the same number at a minimum
  259. REM
  260. REM
  261. REM get the build number from the build name
  262. REM
  263. call logmsg.cmd "Checking build number ..."
  264. for /f "tokens=1 delims=." %%a in ('echo %LatestName%') do set LatestBuildNumber=%%a
  265. for /f %%a in ('%RazzleToolPath%\PostBuildScripts\buildname.cmd build_number') do set LocBuildNum=%%a
  266. if "%LocBuildNum%" NEQ "%LatestBuildNumber%" (
  267. echo Build with different number found, trying again ...
  268. sleep 20
  269. goto :BeginSleepLoop
  270. )
  271. REM otherwise, i think we're good!
  272. set CPLocation=%CPShare%\%LatestName%
  273. if not exist %CPLocation% (
  274. echo %CPLocation% not found, looping back ...
  275. sleep 20
  276. goto :BeginSleepLoop
  277. )
  278. call :CLEARSTAMPS
  279. :PutCPLocationInFile
  280. REM
  281. REM here's where we generate the file for the other scripts to read from
  282. REM
  283. echo %CPLocation%>%CPFile%
  284. call logmsg.cmd "%CPLocation% echoed to %CPFile% for later use ..."
  285. REM and we're done
  286. call logmsg.cmd "Finished."
  287. goto end
  288. :HAVEFRESH
  289. set iFileName=%~1
  290. set DEBUG=
  291. if not exist !iFileName! goto :EOF
  292. call logmsg.cmd "Checking if !iFileName! touched "
  293. set Spoiled=
  294. if defined NewTimeStamp set OldTimeStamp=%NewTimeStamp%
  295. for %%c in (%iFileName%) do set NewTimeStamp=%%~tc
  296. if not defined OldTimeStamp set OldTimeStamp=!NewTimeStamp!
  297. if defined DEBUG echo !OldTimeStamp!
  298. if defined DEBUG echo !NewTimeStamp!
  299. if /i NOT "!OldTimeStamp!"=="!NewTimeStamp!" set Spoiled=1
  300. if defined Spoiled call logmsg.cmd "!iFileName! updated"
  301. goto :EOF
  302. :CLEARSTAMPS
  303. set NewTimeStamp=
  304. set OldTimeStamp=
  305. goto :EOF
  306. :end
  307. seterror.exe "%errors%"& goto :EOF