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.

269 lines
8.0 KiB

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