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.

213 lines
6.6 KiB

  1. @REM usual cmd script header stuff
  2. @echo off
  3. setlocal EnableDelayedExpansion
  4. REM Parse the command line
  5. REM set initial vars
  6. set BuildNumber=
  7. set BuildMachine=
  8. set FullReleasePath=
  9. set BuildPlatform=
  10. set BuildLanguage=
  11. set Force=FALSE
  12. set SELF=%0
  13. :SwitchLoop
  14. for %%a in (./ .- .) do if ".%1." == "%%a?." goto :Usage
  15. if "%1"=="" goto :EndSwitchLoop
  16. for /f "tokens=1,2 delims=:" %%a in ('echo %1') do (
  17. set Switch=%%a
  18. set Arg=%%b
  19. for %%c in (./ .-) do (
  20. if ".!Switch!." == "%%cn." (set BuildNumber=!Arg!&&goto :ShiftArg)
  21. if ".!Switch!." == "%%cm." (set BuildMachine=!Arg!&&goto :ShiftArg)
  22. if ".!Switch!." == "%%cf." (set FullReleasePath=!Arg!&&goto :ShiftArg)
  23. if ".!Switch!." == "%%cp." (set BuildPlatform=!Arg!&&goto :ShiftArg)
  24. if ".!Switch!." == "%%cl." (set BuildLanguage=!Arg!&&goto :ShiftArg)
  25. if ".!Switch!." == "%%cr." (set Force=TRUE&&goto :ShiftArg)
  26. )
  27. if not ".!Switch!." == "%%cn." (
  28. if not ".!Switch!." == "%%cm." (
  29. if not ".!Switch!." == "%%cf." (
  30. if not ".!Switch!." == "%%cp." (
  31. if not ".!Switch!." == "%%cl." (
  32. if not "!Switch!." == "%%cr." goto :Usage
  33. )
  34. )
  35. )
  36. )
  37. )
  38. )
  39. :ShiftArg
  40. shift
  41. goto :SwitchLoop
  42. :EndSwitchLoop
  43. if not defined BuildLanguage set BuildLanguage=usa
  44. perl %RazzleToolPath%\CkLang.pm -l:%BuildLanguage%
  45. if errorlevel 1 (call errmsg.cmd "Invalid language %BuildLanguage%."& goto Errend)
  46. REM here we need to find the latest build in the release dir
  47. REM set BuildPlatform to default if not given on command line
  48. if not defined BuildPlatform set BuildPlatform=%_BuildArch%
  49. REM If the full path was specified on the command-line, use it
  50. if defined FullReleasePath (
  51. if defined BuildMachine (
  52. call logmsg.cmd "WARNING: Both -f and -m specified, using %FullReleasePath%"
  53. )
  54. set ReleaseDir=%FullReleasePath%
  55. GOTO HaveReleaseDir
  56. )
  57. set MyReleaseShareName=release
  58. set ThisRelDir=
  59. set IniCmd=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  60. set IniCmd=!IniCmd! -l:%BuildLanguage%
  61. set IniCmd=!IniCmd! -b:%_BuildBranch%
  62. set IniCmd=!IniCmd! -f:AlternateReleaseDir
  63. for /f %%a in ('!IniCmd!') do (
  64. set ThisRelDir=%%a
  65. )
  66. if defined ThisRelDir set MyReleaseShareName=%ThisRelDir%
  67. REM first, get a list of all the dirs in the release dir
  68. set ReleaseDir=
  69. if not defined BuildMachine (
  70. for /f "tokens=1,2" %%a in ('net share') do if /i "%%a" == "%MyReleaseShareName%" set ReleaseDir=%%b
  71. if not defined ReleaseDir (
  72. echo None -- no release share defined.
  73. goto :ErrEnd
  74. )
  75. ) else (
  76. set ReleaseDir=\\%BuildMachine%\%MyReleaseShareName%
  77. )
  78. if /i "!BuildLanguage!" NEQ "usa" (
  79. set ReleaseDir=%ReleaseDir%\%BuildLanguage%
  80. )
  81. if /i "%Force%"=="TRUE" (
  82. REM force get full build number
  83. set ReleaseDir=%ReleaseDir%\%BuildLanguage%
  84. )
  85. :HaveReleaseDir
  86. if not exist %ReleaseDir% (
  87. echo None -- Release path '%ReleaseDir%' does not exist. Exiting.
  88. goto :ErrEnd
  89. )
  90. set OldReleases=
  91. dir /ad /b %ReleaseDir%\%BuildNumber%*.%BuildPlatform%%_BuildType%.* >nul 2>nul
  92. if "%ErrorLevel%" neq "0" (
  93. echo None -- no old releases found, exiting.
  94. goto :ErrEnd
  95. )
  96. set OldReleases=%Tmp%\OldReleases.tmp
  97. if exist %OldReleases% del /f %OldReleases%
  98. for /f %%a in ('dir /ad /b %ReleaseDir%\%BuildNumber%*.%BuildPlatform%%_BuildType%.*') do echo %%a >> %OldReleases%
  99. if not exist %OldReleases% (
  100. echo None -- no old releases found. Exiting.
  101. goto :ErrEnd
  102. )
  103. REM i think we can get by without actually checking the branch or anything here
  104. REM and if somebody gets hit, we can change it then.
  105. set OldLatestDate=
  106. set OldLatestTime=
  107. for /f %%z in (%OldReleases%) do (
  108. for /f "tokens=4 delims=." %%a in ('echo %%z') do (
  109. REM extract date and time, compare to current oldest, and update if required
  110. for /f "tokens=1,2 delims=-" %%b in ('echo %%a') do (
  111. set ThisBuildDate=%%b
  112. set ThisBuildTime=%%c
  113. if "!ThisBuildDate:~0,2!" == "99" (
  114. REM yes, i'm aware i hardcoded 1999 in here and it will break in 2099
  115. REM but i'll be dead in 2099. sue me then.
  116. set ThisBuildDate=19!ThisBuildDate!
  117. ) else (
  118. set ThisBuildDate=20!ThisBuildDate!
  119. )
  120. REM note that in the case where OldLatest are not defined,
  121. REM the GTR case will succeed, and we'll default to ThisBuildDate
  122. if "!ThisBuildDate!" GTR "!OldLatestDate!" (
  123. set OldLatestDate=!ThisBuildDate!
  124. set OldLatestTime=!ThisBuildTime!
  125. )
  126. if "!ThisBuildDate!" == "!OldLatestDate!" (
  127. if "!ThisBuildTime!" GTR "!OldLatestTime!" (
  128. set OldLatestDate=!ThisBuildDate!
  129. set OldLatestTime=!ThisBuildTime!
  130. )
  131. )
  132. )
  133. )
  134. )
  135. REM at this point, OldLatestDate and OldLatestTime, if defined, contain
  136. REM the build date-time stamp that we need to use to create our "latest"
  137. REM build name
  138. if not defined OldLatestDate (
  139. echo None -- no oldest build found, exiting.
  140. goto :ErrEnd
  141. )
  142. if not defined OldLatestTime (
  143. echo None -- no oldest build found. Exiting.
  144. goto :ErrEnd
  145. )
  146. REM now find the name of the latest build after ripping the 20 or 19 off of
  147. REM OldLatestDate
  148. set OldLatestDate=%OldLatestDate:~2%
  149. Rem Check fot dash builds
  150. set OldReleases=%Tmp%\OldReleases.tmp
  151. if exist %OldReleases% del /f %OldReleases%
  152. dir /ad /b /o-n %ReleaseDir%\%BuildNumber%*-*.%BuildPlatform%%_BuildType%.*.%OldLatestDate%-%OldLatestTime% 2>nul >> %OldReleases%
  153. for /f %%z in (%OldReleases%) do (
  154. for /f "tokens=1 delims=." %%a in ('echo %%z') do (
  155. set DashBld=%%a
  156. goto :EndDash
  157. )
  158. )
  159. :EndDash
  160. for /f %%a in ('dir /ad /b %ReleaseDir%\%DashBld%*.%BuildPlatform%%_BuildType%.*.%OldLatestDate%-%OldLatestTime%') do set LatestReleaseName=%%a
  161. echo %LatestReleaseName%
  162. goto :End
  163. :Usage
  164. echo %SELF% [-n:#] [-m:^<machine name^> ^| -f:^<release path^>] [-l:^<language^>] [-r]
  165. echo -n:# only consider builds numbered #
  166. echo -m:^<machine name^> look at given machine's release share.
  167. echo -f:^<release path^> used to specify the exact location to look for builds
  168. echo -p:^<build architecture^> specify a platform ^<x86,ia64,amd64^>
  169. echo Debug type will be the same as the calling razzle
  170. echo -l:language specified; default is usa
  171. echo -r treat "usa" language the way international builds do
  172. echo.
  173. echo %SELF% will examine all builds on a machine and return the name
  174. echo of the latest build according to the _BuildArch and _BuildType
  175. echo environment variables.
  176. echo.
  177. goto :ErrEnd
  178. :ErrEnd
  179. call :End
  180. seterror.exe 1
  181. goto :EOF
  182. :End
  183. endlocal
  184. goto :EOF