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.

337 lines
9.1 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM CPLocation.cmd
  5. REM Writes the file build_logs\CPLocation.txt with the location of
  6. REM the x86 partner build.
  7. REM
  8. REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. REM
  10. REM ------------------------------------------------------------------
  11. if defined _CPCMAGIC goto CPCBegin
  12. perl -x "%~f0" %*
  13. goto :EOF
  14. #!perl
  15. use strict;
  16. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  17. use lib $ENV{RAZZLETOOLPATH};
  18. use PbuildEnv;
  19. use ParseArgs;
  20. sub Usage { print<<USAGE; exit(1) }
  21. CPLocation [-l <language>]
  22. Writes the file build_logs\CPLocation.txt with the location of the
  23. x86 partner build. If OFFICIAL_BUILD_MACHINE is set will loop waiting
  24. for a matching build number. Otherwise, just wait for any x86 build
  25. of the same debug type.
  26. USAGE
  27. parseargs('?' => \&Usage);
  28. # *** NEXT FEW LINES ARE TEMPLATE ***
  29. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  30. __END__
  31. :CPCBegin
  32. set _CPCMAGIC=
  33. setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  34. REM *** BEGIN YOUR 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 CommandLine=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  108. set CommandLine=!CommandLine! -l:%lang%
  109. set CommandLine=!CommandLine! -f:CrossPlatformCopyMachine::%_BuildArch%%_BuildType%
  110. %CommandLine% >nul 2>nul
  111. if !ErrorLevel! NEQ 0 (
  112. REM there was an error reading the ini file, assume it's not a problem
  113. REM as the ini might not support CrossPlatformCopyMachine
  114. call logmsg.cmd "CrossPlatformCopyMachine not found in ini file ..."
  115. set CPMachine=
  116. set AltCPLocation=
  117. ) else (
  118. for /f %%a in ('!CommandLine!') do set CPMachine=%%a
  119. set AltCPLocation=
  120. )
  121. REM
  122. REM if no ini setting, read in from buildmachines.txt
  123. REM
  124. if defined CPMachine goto :FoundCPMachine
  125. set _ParamBranch=%_BuildBranch%
  126. if defined VBL_RELEASE (
  127. for /f "tokens=1,2,3 delims=\" %%a in ("%VBL_RELEASE%") do (
  128. if /i "%%b" == "" (
  129. set _ParamBranch=%%a
  130. ) else (
  131. set _ParamBranch=%_BuildBranch%
  132. )
  133. )
  134. )
  135. for /f "tokens=1,3,4,5,7,8 delims=," %%a in (%RazzleToolPath%\BuildMachines.txt) do (
  136. if /i "%%b" == "%_ParamBranch%" (
  137. if /i "%%c" == "x86" (
  138. if /i "%%d" == "%_BuildType%" (
  139. if /i "%%e" == "" (
  140. REM not a distributed machine, just pick this one
  141. set CPMachine=%%a
  142. set AltCPLocation=
  143. ) else (
  144. REM must be a distributed machine, check for the postbuild machine
  145. if /i "%%e" == "postbuild" (
  146. set CPMachine=%%a
  147. set AltCPLocation=%%f
  148. )
  149. )
  150. )
  151. )
  152. )
  153. )
  154. if not defined CPMachine (
  155. call errmsg.cmd "No eligible cross platform machine found, exiting."
  156. goto :End
  157. )
  158. REM
  159. REM at this point, we've found our foreign machine name,
  160. REM now we just need the latest build there
  161. REM
  162. :FoundCPMachine
  163. set LocBuildNum=
  164. REM
  165. REM make sure we can see the release share on the given machine
  166. REM
  167. REM If not an official build, use the alternate release point if available
  168. if not defined OFFICIAL_BUILD_MACHINE if not "" == "%AltCPLocation%" (
  169. set CPShare=%AltCPLocation%
  170. if not exist !CPShare! (
  171. call errmsg.cmd "Unable to see !CPShare! ..."
  172. )
  173. GOTO BeginSleepLoop
  174. )
  175. REM
  176. REM find the release share name for this branch
  177. REM
  178. set CommandLine=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  179. set CommandLine=!CommandLine! -l:%lang%
  180. set CommandLine=!CommandLine! -f:AlternateReleaseDir
  181. %CommandLine% >nul 2>nul
  182. if !ErrorLevel! NEQ 0 (
  183. REM there was an error reading the ini file, assume it's not a problem
  184. REM as the ini might not reference AlternateReleaseDir
  185. set ReleaseShareName=release
  186. ) else (
  187. for /f %%a in ('!CommandLine!') do set ReleaseShareName=%%a
  188. )
  189. if not defined ReleaseShareName (
  190. call logmsg.cmd "No release share name found, using default 'release'"
  191. set ReleaseShareName=release
  192. )
  193. REM
  194. REM check the foreign build location
  195. REM
  196. set CPShare=\\%CPMachine%\%ReleaseShareName%
  197. if /i "%lang%" NEQ "usa" set CPShare=%CPShare%\%lang%
  198. if not exist %CPShare% (
  199. call errmsg.cmd "No %ReleaseShareName% share on %CPMachine%, exiting ..."
  200. )
  201. REM here's where we loop back to for spooling
  202. :BeginSleepLoop
  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\build_number.cmd') 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. if %LocBuildNum% NEQ %LatestBuildNumber% (
  266. echo Build with different number found, trying again ...
  267. sleep 20
  268. goto :BeginSleepLoop
  269. )
  270. REM otherwise, i think we're good!
  271. set CPLocation=%CPShare%\%LatestName%
  272. if not exist %CPLocation% (
  273. echo %CPLocation% not found, looping back ...
  274. sleep 20
  275. goto :BeginSleepLoop
  276. )
  277. :PutCPLocationInFile
  278. REM
  279. REM here's where we generate the file for the other scripts to read from
  280. REM
  281. echo %CPLocation%>%CPFile%
  282. call logmsg.cmd "%CPLocation% echoed to %CPFile% for later use ..."
  283. REM and we're done
  284. call logmsg.cmd "Finished."
  285. goto end
  286. :end
  287. seterror.exe "%errors%"& goto :EOF