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.

264 lines
8.1 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM localrel.cmd - SuemiaoR
  4. @REM Move the build to the shared release directory locally.
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @perl -x "%~f0" %*
  10. @goto :EOF
  11. #!perl
  12. use strict;
  13. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  14. use lib $ENV{RAZZLETOOLPATH};
  15. use PbuildEnv;
  16. use Logmsg;
  17. use ParseArgs;
  18. use File::Basename;
  19. use BuildName;
  20. use GetIniSetting;
  21. use comlib;
  22. my $scriptname = basename( $0 );
  23. sub Usage {
  24. print<<USAGE;
  25. Move the build from %_ntpostbld% to the release share locally.
  26. Usage:
  27. $scriptname: -l:<language> [-b:<BuildName>] [-p]
  28. -l Language.
  29. Default is "usa".
  30. -b Build Name.
  31. Default is defined in %_ntpostbld%\\build_logs\\buildname.txt.
  32. -p Powerless.
  33. Display key variables only.
  34. -? Display Usage.
  35. Example:
  36. $scriptname -b:2415.x86fre.main.001222-1745 -p
  37. $scriptname -l:ger
  38. USAGE
  39. exit(1)
  40. }
  41. my ( $buildName, $powerLess, $buildBranch, $buildArch, $buildType, $iniFile );
  42. my ( $releaseShareName, $releaseShareRootDir, $releaseResDir, @releaseAccess);
  43. my ( $lang, $latestReleaseShareName, $freeSpaceReq, $numBuildToKeep );
  44. my ( $localReleaseDrive );
  45. if( !&GetParams() ) { exit(1); }
  46. if( !&InitVars() ) { exit(1); }
  47. #if( !$powerLess && !&VerifyDiskSpace() ) { exit(1); }
  48. if( !$powerLess && !&LowerShare) { exit(1); }
  49. if( !$powerLess && !&MoveBuild ){ exit(1); }
  50. if( !$powerLess && !&RaiseShare ) { exit(1); }
  51. exit(0);
  52. #-----------------------------------------------------------------------------
  53. sub GetParams
  54. {
  55. parseargs('?' => \&Usage, 'b:' => \$buildName, 'p' =>\$powerLess );
  56. $lang = $ENV{lang};
  57. #####Verify %_ntpostbld% exists
  58. if( !( -e $ENV{_ntpostbld} ) )
  59. {
  60. errmsg( "[$ENV{_ntpostbld}] not exists, exit.");
  61. return 0;
  62. }
  63. return 1;
  64. }
  65. #-----------------------------------------------------------------------------
  66. sub InitVars
  67. {
  68. my( @iniRequest );
  69. #####Set build name, buildbranch, buildArch, buildType and ini file
  70. if( !$buildName )
  71. {
  72. if( ! ($buildName = build_name() ))
  73. {
  74. errmsg( "[$ENV{_ntpostbld}\\build_logs\\buildname.txt] not found, exit." );
  75. return 0;
  76. }
  77. }
  78. chomp( $buildName );
  79. $buildBranch = build_branch($buildName);
  80. $buildArch = build_arch($buildName);
  81. $buildType = build_type($buildName);
  82. $iniFile = "$buildBranch.$lang.ini";
  83. #####Set release Share Drive
  84. @iniRequest = ("LocalReleaseDrive::$ENV{computerName}");
  85. $localReleaseDrive = &GetIniSetting::GetSettingEx( $buildBranch,$lang,@iniRequest );
  86. if ( !$localReleaseDrive )
  87. {
  88. $ENV{_ntdrive} =~ /(.*)\:/;
  89. $localReleaseDrive = $1;
  90. }
  91. #####Set <ReleaseShareName> & <ReleaseShareRootDir> & <ReleaseResDir>
  92. $releaseShareName = &comlib::GetReleaseShareName( $ENV{_BuildBranch}, $lang );
  93. #####Set release root path different ways if it is not Offcial_build_machine
  94. if( $ENV{Official_build_machine} )
  95. {
  96. $releaseShareRootDir = "$localReleaseDrive:\\$releaseShareName";
  97. }
  98. else
  99. {
  100. $releaseShareRootDir = &comlib::ParseNetShare( "release", "Path" );
  101. }
  102. if( !$releaseShareRootDir )
  103. {
  104. errmsg( "[release] share undefined" );
  105. return 0;
  106. }
  107. my $releaseResRootDir = $releaseShareRootDir;
  108. $releaseResRootDir .= "\\$lang" if ( lc($lang) ne "usa" );
  109. &comlib::ExecuteSystem("md $releaseResRootDir") if( !( -e $releaseResRootDir) );
  110. #####Set the final resource dir
  111. $releaseResDir = "$releaseResRootDir\\$buildName";
  112. if( -e $releaseResDir )
  113. {
  114. errmsg("Found [$releaseResDir] exists already, exit.");
  115. return 0;
  116. }
  117. #####Set latest share name
  118. $latestReleaseShareName = "latest";
  119. if( lc ($lang) ne "usa" )
  120. {
  121. $latestReleaseShareName .= "_$lang"
  122. }
  123. #####Set access user to the release share build machine
  124. if( $ENV{ReleaseAccess} )
  125. {
  126. @releaseAccess = split( /\;/, $ENV{ReleaseAccess} );
  127. }
  128. else
  129. {
  130. @iniRequest = ( "BuildMachineReleaseAccess", "ReleaseAccess" );
  131. for my $access( @iniRequest )
  132. {
  133. my $iniAccess = &GetIniSetting::GetSetting( $access );
  134. @releaseAccess = split ( /\s+/, $iniAccess );
  135. last if( @releaseAccess );
  136. }
  137. if ( !@releaseAccess || !$ENV{Official_Build_Machine} )
  138. {
  139. @releaseAccess = "$ENV{userDomain}\\$ENV{UserName}" ;
  140. }
  141. }
  142. #####Set free space required & number builds to keep for the local build machine
  143. @iniRequest = ("BuildMachineFreeSpace::$ENV{computername}");
  144. $freeSpaceReq = &GetIniSetting::GetSettingEx( $buildBranch,$lang,@iniRequest );
  145. $freeSpaceReq = 10 if( !$freeSpaceReq );
  146. @iniRequest = ("BuildMachineBuildsToKeep::$ENV{computername}");
  147. $numBuildToKeep = &GetIniSetting::GetSettingEx( $buildBranch,$lang,@iniRequest );
  148. $numBuildToKeep = 2 if( !$numBuildToKeep );
  149. logmsg( "Lauguage .................[$lang]" );
  150. logmsg( "Build name ...............[$buildName]" );
  151. logmsg( "Ini file .................[$iniFile]" );
  152. logmsg( "Postbuild dir ............[$ENV{_ntpostbld}]" );
  153. logmsg( "Release share name .......[$releaseShareName]" );
  154. logmsg( "Release share resource ...[$releaseResDir]" );
  155. logmsg( "Latest Release Access.....[@releaseAccess]" );
  156. logmsg( "Latest release share name [$latestReleaseShareName]" );
  157. logmsg( "Free space required ......[$freeSpaceReq G]" );
  158. logmsg( "Number builds to keep.....[$numBuildToKeep]" );
  159. logmsg( "Temp Log file ............[$ENV{LOGFILE}]" );
  160. logmsg( "Temp Error file ..........[$ENV{ERRFILE}]" );
  161. return 1;
  162. }
  163. #-----------------------------------------------------------------------------
  164. sub MoveBuild
  165. {
  166. return ( &comlib::ExecuteSystem( "move $ENV{_ntpostbld} $releaseResDir" ) );
  167. }
  168. #-----------------------------------------------------------------------------
  169. sub RaiseShare
  170. {
  171. my ( $cmdLine );
  172. #####Set release root share.
  173. #####Verify release root share exists first.
  174. if( system( "net share $releaseShareName >nul 2>nul" ) )
  175. {
  176. $cmdLine = "rmtshare \\\\$ENV{computerName}\\$releaseShareName=$releaseShareRootDir";
  177. }
  178. else
  179. {
  180. $cmdLine = "rmtshare \\\\$ENV{computerName}\\$releaseShareName";
  181. }
  182. for my $ID ( @releaseAccess )
  183. {
  184. $cmdLine .= " /grant $ID:read";
  185. }
  186. return 0 if( !&comlib::ExecuteSystem( $cmdLine ) );
  187. #####Set individual build share
  188. $cmdLine = "rmtshare \\\\$ENV{computerName}\\$latestReleaseShareName=$releaseResDir";
  189. for my $ID ( @releaseAccess )
  190. {
  191. $cmdLine .= " /grant $ID:read";
  192. }
  193. return 0 if( !&comlib::ExecuteSystem( $cmdLine ) );
  194. return 1;
  195. }
  196. #-----------------------------------------------------------------------------
  197. sub LowerShare
  198. {
  199. if( !system( "net share $latestReleaseShareName >nul 2>nul" ) )
  200. {
  201. return 0 if( !&comlib::ExecuteSystem( "net share $latestReleaseShareName /d /y" ) );
  202. }
  203. return 1;
  204. }
  205. #-----------------------------------------------------------------------------
  206. sub VerifyDiskSpace
  207. {
  208. my ($retry, $reqSpace ) = (0, 1000000000);
  209. my $tmpFile = "$ENV{_ntdrive}\\freeSize";
  210. my @freeSize;
  211. $reqSpace *= $freeSpaceReq;
  212. while( $retry < 2)
  213. {
  214. system( "freedisk>$tmpFile" );
  215. @freeSize = &comlib::ReadFile( $tmpFile );
  216. unlink( $tmpFile );
  217. if( ($freeSize[0] - $reqSpace) > 0 )
  218. {
  219. logmsg( "Available disk space [$freeSize[0]], delete builds is not required." );
  220. return 1;
  221. }
  222. logmsg( "Available disk space [$freeSize[0]], Need to free disk space now.");
  223. my ( $cmdLine ) = "deletebuild.cmd AUTO /l $lang /a $buildArch$buildType /f $freeSpaceReq /k $numBuildToKeep";
  224. return 1 if( &comlib::ExecuteSystem( $cmdLine ) );
  225. ++$retry;
  226. }
  227. return 0;
  228. }
  229. #-----------------------------------------------------------------------------
  230. 1;