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.

2041 lines
57 KiB

  1. @echo off
  2. setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  3. if DEFINED _echo echo on
  4. if DEFINED verbose echo on
  5. REM Check the command line for /? -? or ?
  6. for %%a in (./ .- .) do if ".%1." == "%%a?." goto Usage
  7. goto Main
  8. REM ******************************************************************
  9. REM Deletebuild.cmd
  10. REM
  11. REM This script is called to delete builds. It will delete from a
  12. REM build machine, release server, or symfarm. See Usage for details
  13. REM of what is does.
  14. REM
  15. REM ******************************************************************
  16. :BeginDeleteBuild
  17. REM Initialize the command to retrieve values from the ini file
  18. set CmdIni=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  19. REM Set defaults
  20. set OriginalDeleteTmpDir=%tmp%\deletebuildtmp
  21. set DefaultBuildsToKeep=3
  22. set DefaultFreeSpaceReq=10
  23. set DefaultSymbolServerBuildShare=\\symbols\build$
  24. set BuildName=
  25. set BuildsToKeep=
  26. set ConfiguredForIndexing=
  27. set CurArchType=%_BuildArch%%_BuildType%
  28. set DeleteType=FULL
  29. set ExcludeBuild=
  30. set ForceAuto=MANUAL
  31. set FreeSpaceReq=
  32. set IndexableReleaseServer=
  33. set Lang=usa
  34. set NTFSCompress=
  35. set ReleaseDir=
  36. set ReleaseServerExists=
  37. set SymbolServerBuildShare=
  38. set SymFarmExists=
  39. set ThisIsABuildMachine=
  40. set ThisIsAReleaseServer=
  41. set ThisIsASymFarm=
  42. REM Get Command line options
  43. for %%a in ( %cmdline% ) do (
  44. set found=no
  45. if /i "%%a" == "deletebuild" set found=yes
  46. if /i "%%a" == "deletebuild.cmd" set found=yes
  47. if /i "%%a" == "COMPRESS" (
  48. set NTFSCompress=yes
  49. set found=yes
  50. )
  51. if /i "%%a" == "PARTIAL" (
  52. set DeleteType=PARTIAL
  53. set found=yes
  54. )
  55. if /i "%%a" == "AUTO" (
  56. set ForceAuto=AUTO
  57. set found=yes
  58. )
  59. if /i "!param!" == "arch" (
  60. set found=no
  61. set param=no
  62. if /i "%%a" == "x86fre" (
  63. set CurArchType=x86fre
  64. set found=yes
  65. )
  66. if /i "%%a" == "x86chk" (
  67. set CurArchType=x86chk
  68. set found=yes
  69. )
  70. if /i "%%a" == "amd64fre" (
  71. set CurArchType=amd64fre
  72. set found=yes
  73. )
  74. if /i "%%a" == "amd64chk" (
  75. set CurArchType=amd64chk
  76. set found=yes
  77. )
  78. if /i "%%a" == "ia64fre" (
  79. set CurArchType=ia64fre
  80. set found=yes
  81. )
  82. if /i "%%a" == "ia64chk" (
  83. set CurArchType=ia64chk
  84. set found=yes
  85. )
  86. if /i "!found!" == "no" (
  87. call errmsg.cmd "Arch type is not valid"
  88. goto errend
  89. )
  90. )
  91. if /i "!param!" == "exclude" (
  92. set ExcludeBuild=%%a
  93. set found=yes
  94. set param=no
  95. )
  96. if /i "!param!" == "Rel" (
  97. set ReleaseDir=%%a
  98. if not exist !ReleaseDir! (
  99. call errmsg.cmd "!ReleaseDir! does not exist"
  100. goto errend
  101. )
  102. set found=yes
  103. set param=no
  104. )
  105. if /i "!param!" == "build" (
  106. set BuildName=%%a
  107. set found=yes
  108. set param=no
  109. )
  110. if /i "!param!" == "lang" (
  111. REM We already set this
  112. set Lang=%%a
  113. set found=yes
  114. set param=no
  115. )
  116. if /i "!param!" == "free" (
  117. set /a FreeSpaceReq=%%a
  118. if !FreeSpaceReq! LEQ 1 (
  119. call errmsg.cmd "Free space required must be greater than 1"
  120. goto errend
  121. )
  122. set found=yes
  123. set param=no
  124. )
  125. if /i "!param!" == "Keep" (
  126. set /a BuildsToKeep=%%a
  127. if NOT !BuildsToKeep! GEQ 0 (
  128. call errmsg.cmd "Builds to keep must be greater than or equal to 0"
  129. goto errend
  130. )
  131. set found=yes
  132. set param=no
  133. )
  134. if /i "%%a" == "/a" (
  135. set found=yes
  136. set param=arch
  137. )
  138. if /i "%%a" == "/b" (
  139. set found=yes
  140. set param=build
  141. )
  142. if /i "%%a" == "/e" (
  143. set found=yes
  144. set param=exclude
  145. )
  146. if /i "%%a" == "/f" (
  147. set found=yes
  148. set param=free
  149. )
  150. if /i "%%a" == "/k" (
  151. set found=yes
  152. set param=keep
  153. )
  154. if /i "%%a" == "/l" (
  155. set found=yes
  156. set param=lang
  157. )
  158. if /i "%%a" == "/r" (
  159. set found=yes
  160. set param=rel
  161. )
  162. if /i "!found!" == "no" (
  163. call errmsg.cmd "%%a is not a correct parameter"
  164. goto errend
  165. )
  166. )
  167. if defined COMPUTERNAME (
  168. call logmsg.cmd "Computer name = %COMPUTERNAME%"
  169. ) else (
  170. call errmsg.cmd "COMPUTERNAME environment variable is not set"
  171. goto errend
  172. )
  173. REM Initialize several global variables
  174. REM Decide if this is a build machine, release server, symbol farm
  175. call :WhatAmI %CurArchType%
  176. if defined ThereWereErrors (
  177. goto errend
  178. )
  179. call :GetArchsToDelete
  180. if defined ThereWereErrors (
  181. goto errend
  182. )
  183. set /a count=0
  184. for %%a in ( %ArchsToDelete% ) do (
  185. set /a count=!count!+1
  186. )
  187. set DeleteMultipleArchs=
  188. if !count! GTR 1 (
  189. set DeleteMultipleArchs=1
  190. )
  191. if not defined BuildsToKeep (
  192. call :GetBuildsToKeep %CurArchType%
  193. if defined ThereWereErrors (
  194. goto errend
  195. )
  196. )
  197. if not defined FreeSpaceReq (
  198. call :GetFreeSpaceReq
  199. if defined ThereWereErrors (
  200. goto errend
  201. )
  202. )
  203. REM Initialize this before we do anything
  204. call :AmIConfiguredForIndexing
  205. if defined ThereWereErrors (
  206. goto errend
  207. )
  208. REM Check the params
  209. if not defined ReleaseDir (
  210. call :GetReleaseDir
  211. if defined ThereWereErrors (
  212. if defined ThisIsASymFarm (
  213. call errmsg.cmd "A symfarm share does not exist"
  214. ) else (
  215. call errmsg.cmd "A release share does not exist"
  216. )
  217. goto errend
  218. )
  219. )
  220. if not exist %ReleaseDir% (
  221. call errmsg.cmd "%ReleaseDir% does not exist"
  222. goto errend
  223. )
  224. if defined BuildName (
  225. if not exist %ReleaseDir%\%BuildName% (
  226. call errmsg.cmd "%ReleaseDir%\%BuildName% does not exist"
  227. goto errend
  228. )
  229. )
  230. if defined ThisIsABuildMachine (
  231. call logmsg "This is a build machine"
  232. )
  233. if defined ThisIsAReleaseServer (
  234. call logmsg "This is a release server"
  235. ) else (
  236. if defined ReleaseServerExists (
  237. if not defined ThisIsASymFarm (
  238. call logmsg "A release server exists"
  239. )
  240. ) else (
  241. call logmsg "A release server does not exist"
  242. )
  243. )
  244. if defined ThisIsASymFarm (
  245. call logmsg "This is a symbol farm"
  246. )
  247. if defined SymFarmExists (
  248. call logmsg "A symbol farm exists"
  249. ) else (
  250. call logmsg "A symbol farm does not exist"
  251. )
  252. if defined ConfiguredForIndexing (
  253. call logmsg "This is configured for indexing"
  254. call logmsg "Indexing requests are sent to %SymbolServerBuildShare%"
  255. ) else (
  256. call logmsg "This is not configured for indexing"
  257. )
  258. call logmsg "Deleting these build types: %ArchsToDelete%"
  259. call logmsg "BuildsToKeep for %CurArchType% = %BuildsToKeep%"
  260. call logmsg "CurArchType = %CurArchType%"
  261. if /i %ForceAuto% == "MANUAL" (
  262. call logmsg "DeleteType = %DeleteType%"
  263. )
  264. if defined ExcludeBuild (
  265. call logmsg "Build to exclude = %ExcludeBuild%"
  266. )
  267. call logmsg "Delete mode = %ForceAuto%"
  268. call logmsg "Free Space Required = %FreeSpaceReq%"
  269. call logmsg "Lang = %Lang%"
  270. if defined NTFSCompress (
  271. call logmsg "Partially delete builds will be NTFS compressed"
  272. )
  273. call logmsg "Release Directory = %ReleaseDir%"
  274. if /i "%ForceAuto%" == "AUTO" (
  275. if not defined CurArchType (
  276. call errmsg.cmd "Arch must be defined for AUTO deletes"
  277. goto errend
  278. )
  279. goto AutoDelete
  280. )
  281. if /i "%ForceAuto%" == "MANUAL" (
  282. goto ForceDelete
  283. )
  284. call errmsg.cmd "ForceAuto variable is not equal to FoRCE or AUTO"
  285. goto :EOF
  286. REM *******************************************************************
  287. REM Automated delete
  288. REM This will delete builds, giving priority to delete partially
  289. REM first and then to delete fully. A partial delete deletes all of
  290. REM the non-indexed files.
  291. REM *******************************************************************
  292. :AutoDelete
  293. REM See if we have at least %FreeSpaceReq% of free space on the
  294. REM disk where %ReleaseDir% is.
  295. call :GetFreeSpace %ReleaseDir%
  296. if defined ThereWereErrors goto errend
  297. REM see if we need to delete
  298. if %FreeSpace% GEQ %FreeSpaceReq% (
  299. call logmsg.cmd "Current free space = %FreeSpace% GB ... No delete required"
  300. goto end
  301. )
  302. call logmsg.cmd "Delete required, deciding what to delete ..."
  303. REM Get the first delete directory and make that the place where
  304. REM we store the cumulative list.
  305. set found=no
  306. set first=yes
  307. for %%a in ( %ArchsToDelete% ) do (
  308. if "!first!" == "yes" (
  309. set DeleteTmpDir=%OriginalDeleteTmpDir%\%%a
  310. if exist %ReleaseDir%\*.%%a.%_BuildBranch%.* (
  311. set found=yes
  312. )
  313. set first=no
  314. )
  315. )
  316. if /i "!found!" == "no" (
  317. call logmsg.cmd "No builds exist in %ReleaseDir% for these types: %ArchsToDelete% "
  318. goto OutOfDiskSpaceError
  319. )
  320. for %%a in ( finaldelete.txt sorted.txt finaldelete.txt.tmp) do (
  321. if exist %DeleteTmpDir%\%%a (
  322. del /f /q %DeleteTmpDir%\%%a
  323. )
  324. )
  325. for %%a in ( %ArchsToDelete% ) do (
  326. if exist %ReleaseDir%\*.%%a.%_BuildBranch%.* (
  327. REM If we are deleting multiple archs, then get BuildsToKeep
  328. REM from the ini file for each architecture type
  329. if defined DeleteMultipleArchs (
  330. call :GetBuildsToKeep %%a
  331. if defined ThereWereErrors (
  332. goto errend
  333. )
  334. )
  335. call :CreateDeleteTmpDir %OriginalDeleteTmpDir%\%%a
  336. if defined ThereWereErrors goto errend
  337. REM Create an ordered list of possible builds to delete.
  338. REM The final list is in %OriginalDeleteTmpDir%\%%a\delete.txt
  339. call :CreateListOfPossibleBuildsToDelete %OriginalDeleteTmpDir%\%%a %%a
  340. if defined ThereWereErrors goto errend
  341. REM Create a cumulative list of builds we can delete
  342. if exist %OriginalDeleteTmpDir%\%%a\delete.txt (
  343. type %OriginalDeleteTmpDir%\%%a\delete.txt >> %DeleteTmpDir%\finaldelete.txt.tmp
  344. )
  345. ) else (
  346. call logmsg "No %%a builds exist in %ReleaseDir%"
  347. )
  348. )
  349. if not exist %DeleteTmpDir%\finaldelete.txt.tmp (
  350. goto OutOfDiskSpaceError
  351. )
  352. REM This returns the sorted list in %DeleteTmpDir%\sorted.txt
  353. call :SortBuildList %DeleteTmpDir% %DeleteTmpDir%\finaldelete.txt.tmp
  354. copy %DeleteTmpDir%\sorted.txt %DeleteTmpDir%\finaldelete.txt
  355. REM If this machine is not configured for indexing then
  356. REM partial deletes have no meaning -- only do full deletes
  357. call logmsg "%DeleteTmpDir%\finaldelete.txt lists the builds that can be deleted"
  358. if not defined ConfiguredForIndexing (
  359. call logmsg.cmd "%COMPUTERNAME% is not indexed -- only perform full deletes"
  360. goto AutoDelete_Full
  361. )
  362. if defined ThisIsASymFarm (
  363. call logmsg.cmd "Symbol farm - Will not perform partial deletes"
  364. goto AutoDelete_Full
  365. )
  366. REM First do cleanup -- if we tried to delete some builds before but they didn't
  367. REM finish, clean them up
  368. :AutoDelete_CleanUp
  369. call logmsg.cmd "Clean up old release directories that should be gone"
  370. for /f %%a in (%DeleteTmpDir%\finaldelete.txt) do (
  371. REM If this build doesn't have a partiallydeleted.qly file
  372. REM and there are no indexing files then do a full delete
  373. REM This could happen if we tried to remove a build before but
  374. REM it didn't finish.
  375. if not exist %ReleaseDir%\%%a\symsrv\%Lang%\PartiallyDeleted.qly (
  376. call :AreThereFilesIndexed %%a
  377. if not defined ThereAreFilesIndexed (
  378. REM Perform a full delete
  379. call :PerformFullDelete %%a
  380. if defined ThereWereErrors goto errend
  381. )
  382. )
  383. REM Calculate the new free space
  384. call :GetFreeSpace %ReleaseDir%
  385. if defined ThereWereErrors goto errend
  386. REM see if we need to delete
  387. if !FreeSpace! GEQ %FreeSpaceReq% (
  388. call logmsg.cmd "No more cleanup required ..."
  389. goto EndAutoDelete
  390. )
  391. )
  392. REM Now, go through and partially delete until there is enough space
  393. :AutoDelete_Partial
  394. call logmsg.cmd "FreeSpace = %FreeSpace%"
  395. call logmsg.cmd "Start partial deletes to get more free disk space"
  396. REM Perform partial deletes until there is enough free disk space
  397. for /f %%a in (%DeleteTmpDir%\finaldelete.txt) do (
  398. if exist %ReleaseDir%\%%a (
  399. call :PerformPartialDelete %%a
  400. if defined ThereWereErrors goto errend
  401. REM Calculate the new free space
  402. call :GetFreeSpace %ReleaseDir%
  403. if defined ThereWereErrors goto errend
  404. REM see if we need to delete
  405. if !FreeSpace! GEQ %FreeSpaceReq% (
  406. call logmsg.cmd "No more partial deletes required ..."
  407. goto EndAutoDelete
  408. )
  409. )
  410. )
  411. REM Now perform full deletes until there is enough disk space
  412. :AutoDelete_Full
  413. call logmsg.cmd "Free space = %FreeSpace%"
  414. call logmsg.cmd "Start full deletes to get more free disk space"
  415. for /f %%a in (%DeleteTmpDir%\finaldelete.txt) do (
  416. if exist %ReleaseDir%\%%a (
  417. call :PerformFullDelete %%a
  418. if defined ThereWereErrors goto errend
  419. REM Calculate the new free space
  420. call :GetFreeSpace %ReleaseDir%
  421. if defined ThereWereErrors goto errend
  422. REM see if we need to delete
  423. if !FreeSpace! GEQ %FreeSpaceReq% (
  424. call logmsg.cmd "No more full deletes required ..."
  425. goto EndAutoDelete
  426. )
  427. )
  428. )
  429. goto OutOfDiskSpaceError
  430. :EndAutoDelete
  431. call logmsg.cmd "Deleting is done -- FreeSpace = !FreeSpace! GB"
  432. goto end
  433. :OutOfDiskSpaceError
  434. call logmsg.cmd "Current free space = %FreeSpace% GB"
  435. call errmsg.cmd "Cannot free %FreeSpaceReq% GB. You may not have enough disk space for the next build."
  436. call errmsg.cmd "Check your ini settings - the remaining builds are not supposed to be deleted."
  437. goto errend
  438. REM *******************************************************************
  439. REM This forces a particular build to be deleted
  440. REM
  441. REM Params:
  442. REM %1 - BuildName
  443. REM
  444. REM *******************************************************************
  445. :ForceDelete
  446. REM If delete type is Partial, see if a partial delete is possible
  447. if /i "%DeleteType%" == "Partial" (
  448. set DeleteTmpDir=%OriginalDeleteTmpDir%\%BuildName%
  449. REM Create the temp directory
  450. call :CreateDeleteTmpDir !DeleteTmpDir!
  451. if defined ThereWereErrors goto errend
  452. call :PerformPartialDelete %BuildName%
  453. if defined ThereWereErrors goto errend
  454. )
  455. if /i "%DeleteType%" == "FULL" (
  456. call :PerformFullDelete %BuildName%
  457. if defined ThereWereErrors goto errend
  458. )
  459. :EndForceDelete
  460. goto end
  461. REM ******************************************************************************
  462. REM AreThereFilesIndexed
  463. REM
  464. REM Decide if there are any files indexed.
  465. REM
  466. REM Params:
  467. REM %1 - BuildName
  468. REM
  469. REM
  470. REM
  471. REM ******************************************************************************
  472. :AreThereFilesIndexed %1
  473. set ThereWereErrors=
  474. set ThereAreFilesIndexed=
  475. for %%a in ( bin pri pub ssi ) do (
  476. dir /b %ReleaseDir%\%1\symsrv\%Lang%\add_finished\*.%%a >nul 2>nul
  477. if !ERRORLEVEL! EQU 0 (
  478. set ThereAreFilesIndexed=yes
  479. goto EndAreThereFilesIndexed
  480. )
  481. )
  482. :EndAreThereFilesIndexed
  483. goto :EOF
  484. REM ******************************************************************************
  485. REM PerformFullDelete
  486. REM
  487. REM Decides if there is anything to send to the symbol server's delete requests
  488. REM directory. If so, it unindexes the symbols and then removes the directory.
  489. REM
  490. REM Params:
  491. REM %1 Build Name
  492. REM
  493. REM ******************************************************************************
  494. :PerformFullDelete %1
  495. set ThereWereErrors=
  496. if "%1" == "" (
  497. call errmsg.cmd "PerformFullDelete needs a parameter passed in"
  498. set ThereWereErrors=yes
  499. goto :EOF
  500. )
  501. if not exist %ReleaseDir%\%1 (
  502. call logmsg.cmd "Performing full delete - %1 does not exist"
  503. goto :EOF
  504. )
  505. if defined ConfiguredForIndexing (
  506. call :UnindexSymbols %1
  507. if defined ThereWereErrors goto EndPerformFullDelete
  508. )
  509. call :DeleteTrivia %1
  510. REM Now, remove the build directory
  511. call logmsg.cmd "Removing %ReleaseDir%\%1 ..."
  512. rd /s /q %ReleaseDir%\%1
  513. if exist %ReleaseDir%\%1 (
  514. call logmsg.cmd "Could not remove %ReleaseDir%\%1"
  515. echotime /t > %ReleaseDir%\%1\000_Not_A_Full_Build
  516. )
  517. :EndPerformFullDelete
  518. goto :EOF
  519. REM ****************************************************************************
  520. REM Perform PartialDelete
  521. REM
  522. REM First, this checks to make sure that a partial delete is OK to do
  523. REM
  524. REM Return Values -
  525. REM BuildWasAlreadyPartiallyDeleted -- yes if build was already partially
  526. REM deleted
  527. REM
  528. REM Assumes ConfiguredForIndexing is already set if this machine communicates
  529. REM with the symbol server.
  530. REM
  531. REM This performs a partial delete of %ReleaseDir%\%1. This routine does the
  532. REM following:
  533. REM 1. Check for bin, pri, pub files in %AddFinished%. If any of them
  534. REM exist then it creates a list of all the files that are not indexed
  535. REM on the symbol server
  536. REM 2. Deletes all the files in the list
  537. REM 3. The %ReleaseDir%\%1\symsrv directory is not deleted.
  538. REM
  539. REM ****************************************************************************
  540. :PerformPartialDelete %1
  541. call logmsg.cmd "Starting partial delete of %ReleaseDir%\%1"
  542. set ThereWereErrors=
  543. set ThisDeleteTmpDir=%DeleteTmpDir%\Partial
  544. if not defined ConfiguredForIndexing (
  545. call logmsg.cmd "%COMPUTERNAME% is not configured for indexing"
  546. call logmsg.cmd "%ReleaseDir%\%1 has no files to unindex"
  547. call logmsg.cmd "Partial delete cannot be done"
  548. goto :EndPerformPartialDelete
  549. )
  550. if exist %ReleaseDir%\%1\symsrv\%Lang%\PartiallyDeleted.qly (
  551. call logmsg.cmd "%ReleaseDir%\%1 is already partially deleted"
  552. set BuildWasAlreadyPartiallyDeleted=yes
  553. goto :EndPerformPartialDelete
  554. )
  555. call :AreThereFilesIndexed %1
  556. if not defined ThereAreFilesIndexed (
  557. call logmsg.cmd "There are no symbols to unindex"
  558. goto :EndPerformPartialDelete
  559. )
  560. call :DeleteTrivia %1
  561. if not exist %DeleteTmpDir% (
  562. call errmsg.cmd "ASSERT: %DeleteTmpDir% does not exist"
  563. set ThereWereErrors=yes
  564. goto :EOF
  565. )
  566. if exist %ThisDeleteTmpDir% (
  567. rd /s /q %ThisDeleteTmpDir%
  568. if exist %ThisDeleteTmpDir% (
  569. call errmsg.cmd "Could not remove %ThisDeleteTmpDir%"
  570. set ThereWereErrors=yes
  571. goto :EOF
  572. )
  573. )
  574. md %ThisDeleteTmpDir%
  575. if not exist %ThisDeleteTmpDir% (
  576. call errmsg.cmd "Could not create %ThisDeleteTmpDir%
  577. set ThereWereErrors=yes
  578. goto :EOF
  579. )
  580. set AddFinished=%ReleaseDir%\%1\symsrv\%Lang%\add_finished
  581. REM Create three lists --
  582. REM %ThisDeleteTmpDir%\indexed.txt -- all the indexed files
  583. REM %ThisDeleteTmpDir%\nonindexed.txt -- all the nonindexed files
  584. REM %ThisDeleteTmpDir%\all.txt -- all the files
  585. call logmsg.cmd "Creating a list of all the indexed files"
  586. if exist %AddFinished%\*.pri (
  587. for /f %%a in ( 'dir /b /s %AddFinished%\*.pri' ) do (
  588. for /f "tokens=1 delims=," %%b in ( %%a ) do (
  589. echo %ReleaseDir%\%1\symbols.pri\%%b>>%ThisDeleteTmpDir%\indexed.txt
  590. )
  591. )
  592. )
  593. if exist %AddFinished%\*.pub (
  594. for /f %%a in ( 'dir /b /s %AddFinished%\*.pub' ) do (
  595. for /f "tokens=1 delims=," %%b in ( %%a ) do (
  596. echo %ReleaseDir%\%1\symbols\%%b>>%ThisDeleteTmpDir%\indexed.txt
  597. )
  598. )
  599. )
  600. if exist %AddFinished%\*.bin (
  601. for /f %%a in ( 'dir /b /s %AddFinished%\*.bin' ) do (
  602. for /f "tokens=1 delims=," %%b in ( %%a ) do (
  603. echo %ReleaseDir%\%1\%%b>>%ThisDeleteTmpDir%\indexed.txt
  604. )
  605. )
  606. )
  607. REM Also, put the files in the symsrv directory and build_logs
  608. REM into the indexed list
  609. dir /s /b /a-d %ReleaseDir%\%1\symsrv >> %ThisDeleteTmpDir%\indexed.txt
  610. dir /s /b /a-d %ReleaseDir%\%1\build_logs >> %ThisDeleteTmpDir%\indexed.txt
  611. call logmsg.cmd "Removing directories in %ReleaseDir%\%1 that are not indexed"
  612. REM Next, remove the directories that are not referenced in indexed.txt
  613. if exist %ThisDeleteTmpDir%\dirs.txt del /q %ThisDeleteTmpDir%\dirs.txt
  614. for /f %%a in ( 'dir /b /ad %ReleaseDir%\%1' ) do (
  615. findstr /il %ReleaseDir%\%1\%%a\ %ThisDeleteTmpDir%\indexed.txt >nul 2>nul
  616. if !ERRORLEVEL! NEQ 0 (
  617. echo %ReleaseDir%\%1\%%a >> %ThisDeleteTmpDir%\dirs.txt
  618. )
  619. )
  620. REM Before removing these, do a sanity check
  621. if exist %ThisDeleteTmpDir%\dirs.txt (
  622. findstr /il %ReleaseDir%\%1\symsrv %ThisDeleteTmpDir%\dirs.txt >nul 2>nul
  623. if !ERRORLEVEL! EQU 0 (
  624. call errmsg.cmd "symsrv is in the list of directories to delete"
  625. goto :EOF
  626. )
  627. )
  628. REM Now, remove all the directories that aren't mentioned in indexed.txt
  629. if exist %ThisDeleteTmpDir%\dirs.txt (
  630. for /f %%a in ( %ThisDeleteTmpDir%\dirs.txt ) do (
  631. call logmsg.cmd "Removing %%a"
  632. rd /s /q %%a
  633. )
  634. )
  635. REM Create a list of all the files
  636. call logmsg.cmd "Creating a list of all the files"
  637. dir /s /b /a-d %ReleaseDir%\%1 > %ThisDeleteTmpDir%\all.txt
  638. REM Subtract the indexed files from all the files
  639. call logmsg.cmd "Subtracting indexed files from all the files"
  640. perl %RazzleToolpath%\makelist.pl -d %ThisDeleteTmpDir%\all.txt %ThisDeleteTmpDir%\indexed.txt -o %ThisDeleteTmpDir%\delete.tmp
  641. REM If there is nothing to delete, we're done
  642. if not exist %ThisDeleteTmpDir%\delete.tmp (
  643. call logmsg.cmd "There are no files to delete"
  644. goto :EndPerformPartialDelete
  645. )
  646. REM Sort and get a list of all the files that can be deleted
  647. sort %ThisDeleteTmpDir%\delete.tmp > %ThisDeleteTmpDir%\nonindexed.txt
  648. if !ERRORLEVEL! NEQ 0 (
  649. call errmsg.cmd "Sort failed for %ThisDeleteTmpDir%\nonindexed.txt
  650. set ThereWereErrors=yes
  651. goto :EOF
  652. )
  653. del /q %ThisDeleteTmpDir%\delete.tmp
  654. call logmsg.cmd "List of non-indexed files is in %ThisDeleteTmpDir%\nonindexed.txt"
  655. REM Now, remove the files
  656. call logmsg.cmd "Removing non-indexed files from %ReleaseDir%\%1"
  657. for /f %%a in ( %ThisDeleteTmpDir%\nonindexed.txt ) do (
  658. del /q %%a
  659. if exist %%a (
  660. call logmsg.cmd "Cannot delete %%a"
  661. REM set ThereWereErrors=yes
  662. REM Continue, dont stop because of a delete error
  663. )
  664. )
  665. REM Clean up the remaining directories
  666. REM Make a list of all the directories
  667. dir /b /s /ad %ReleaseDir%\%1 > %ThisDeleteTmpDir%\dirs.tmp.txt
  668. sort /r %ThisDeleteTmpDir%\dirs.tmp.txt > %ThisDeleteTmpDir%\dirs.txt
  669. del /q %ThisDeleteTmpDir%\dirs.tmp.txt
  670. REM Delete the directories that do not have any files
  671. call logmsg.cmd "Removing the empty directories"
  672. for /f %%a in ( %ThisDeleteTmpDir%\dirs.txt ) do (
  673. REM if directory is empty, the findstr will fail and
  674. REM then it will remove the directory
  675. if exist %%a (
  676. dir /s /b %%a | findstr /il %ReleaseDir% >nul 2>nul
  677. if !ERRORLEVEL! NEQ 0 (
  678. rd /s /q %%a
  679. )
  680. )
  681. )
  682. call logmsg.cmd "Finished deleting non-indexed files"
  683. if not exist %ReleaseDir%\%1\symsrv\%Lang% (
  684. call errmsg.cmd "Partial delete removed %ReleaseDir%\%1\symsrv\%Lang%
  685. set ThereWereErrors=yes
  686. goto :EOF
  687. )
  688. REM Compact the rest of the files
  689. if defined NTFSCompress (
  690. call logmsg.cmd "Using compact.exe to compress %ReleaseDir%\%1 ..."
  691. compact.exe /c /s /q %ReleaseDir%\%1 >nul 2>nul
  692. if !ERRORLEVEL! NEQ 0 (
  693. call errmsg.cmd "Errors in compact.exe /c /s /q %ReleaseDir%\%1
  694. )
  695. )
  696. echotime /t > %ReleaseDir%\%1\symsrv\%Lang%\PartiallyDeleted.qly
  697. echotime /t > %ReleaseDir%\%1\000_Not_A_Full_Build
  698. echotime /t > %ReleaseDir%\%1\000_Symbols_Are_Still_Indexed
  699. call logmsg.cmd "Partial delete finished successfully"
  700. set PartialDeleteCompleted=yes
  701. :EndPerformPartialDelete
  702. goto :EOF
  703. REM ****************************************************************************
  704. REM AmIConfiguredForIndexing
  705. REM
  706. REM This determines if the current machine is configured for indexing.
  707. REM If it is, then it may have some files that are indexed on the symbol
  708. REM server.
  709. REM
  710. REM Return values:
  711. REM
  712. REM ConfiguredForIndexing=yes
  713. REM 1. This is a symbol farm, or
  714. REM 2. THis is a release server or build machine and no symbol farm exists
  715. REM
  716. REM ConfiguredForIndexing=
  717. REM 1. Symbol farm exists and this is a release server
  718. REM 2. Symbol farm exists and this is a build machine
  719. REM
  720. REM Global variables that must be set before this is called
  721. REM SymFarmExists undefined if it does not exist
  722. REM =yes if it does exist
  723. REM
  724. REM ReleaseServerExists undefined if it does not exist
  725. REM =yes if it does exist
  726. REM
  727. REM ThisIsASymFarm undefined if it is not a symbol farm
  728. REM =yes if it is a symbol farm
  729. REM
  730. REM ThisIsABuildMachine undefined if it is not a build machine
  731. REM =yes if it is a build machine
  732. REM
  733. REM ThisIsAReleaseServer undefined if it is a release server
  734. REM =yes if it is a release server
  735. REM
  736. REM IndexableReleaseServer undefined if it we should not let symbol server
  737. REM indexes point to here.
  738. REM =yes if it is the first release server in the list
  739. REM
  740. REM SymbolServerBuildShare undefined if it SymIndexServer doesn't exist
  741. REM in the ini file
  742. REM Location for submitting indexing requests
  743. REM
  744. REM ****************************************************************************
  745. :AmIConfiguredForIndexing
  746. set ThereWereErrors=
  747. set ConfiguredForIndexing=
  748. if defined ThisIsABuildMachine (
  749. if defined OFFICIAL_BUILD_MACHINE (
  750. if not defined ReleaseServerExists (
  751. if not defined SymFarmExists (
  752. set ConfiguredForIndexing=yes
  753. goto EndAmIConfiguredForIndexing
  754. )
  755. )
  756. ) else (
  757. call logmsg "OFFICIAL_BUILD_MACHINE is not defined in environment."
  758. )
  759. goto EndAmIConfiguredForIndexing
  760. )
  761. if defined ThisIsAReleaseServer (
  762. if defined IndexableReleaseServer (
  763. if not defined SymFarmExists (
  764. set ConfiguredForIndexing=yes
  765. goto EndAmIConfiguredForIndexing
  766. )
  767. )
  768. goto EndAmIConfiguredForIndexing
  769. )
  770. REM Decide if this is a symbol farm
  771. if defined ThisIsASymFarm (
  772. set ConfiguredForIndexing=yes
  773. goto EndAmIConfiguredForIndexing
  774. )
  775. REM If we get here the variables have not been initialized correctly
  776. call errmsg "Check your ini file: %COMPUTERNAME% is not defined as a build machine, release server, or sym farm"
  777. set ThereWereErrors=yes
  778. goto :EOF
  779. :EndAmIConfiguredForIndexing
  780. REM If this is configured for indexing, get the SymbolServerBuildShare
  781. if defined ConfiguredForIndexing (
  782. set ThisCommandLine=!CmdIni! -l:!Lang! -f:SymIndexServer
  783. !ThisCommandLine! >nul 2>nul
  784. if !ERRORLEVEL! NEQ 0 (
  785. call logmsg.cmd "SymIndexServer is not defined in the ini file"
  786. call logmsg.cmd "Will use default: !DefaultSymbolServerBuildShare!"
  787. set SymbolServerBuildShare=!DefaultSymbolServerBuildShare!
  788. ) else (
  789. for /f %%a in ('!ThisCommandLine!') do (
  790. set SymbolServerBuildShare=%%a
  791. )
  792. )
  793. REM
  794. REM Retrieve DFS alternate branch name for IDX builds only; it changes idx01 to main.
  795. REM
  796. set ThisCommandLine=!CmdIni! -l:!Lang! -f:DFSAlternateBranchName
  797. !ThisCommandLine! >nul 2>nul
  798. if !ERRORLEVEL! NEQ 0 (
  799. set SymbolServerBuildShare=!SymbolServerBuildShare!\Win%_BuildBranch%
  800. ) else (
  801. for /f %%b in ('!ThisCommandLine!') do (
  802. set SymbolServerBuildShare=!SymbolServerBuildShare!\Win%%b
  803. )
  804. )
  805. REM
  806. REM Replace Lab01_N to Lab01
  807. REM
  808. for /f %%c in ('perl -e "$ARGV[0]=~s/\_[\w\d]+//;print $ARGV[0]" !SymbolServerBuildShare!') do (
  809. set SymbolServerBuildShare=%%c
  810. )
  811. )
  812. REM
  813. REM If symbol server build share is still pointed to \\symbols\build$, point it to \\symbols\projects
  814. REM
  815. set SymbolServerBuildShare=%SymbolServerBuildShare:build$=projects%
  816. call logmsg.cmd "SymbolServerBuildShare is %SymbolServerBuildShare%"
  817. goto :EOF
  818. REM *********************************************************************
  819. REM UnindexSymbols
  820. REM
  821. REM This submits either *.ssi or all the *.pri *.bin *.pub files in the
  822. REM %ReleaseDir%\%1\symsrv\%Lang%\add_finished directory to the
  823. REM del_requests directory on the symbol server, and then deletes them.
  824. REM
  825. REM *********************************************************************
  826. :UnindexSymbols %1
  827. set ThereWereErrors=
  828. set DelReq=%SymbolServerBuildShare%\del_requests
  829. REM Get the folder with the requests that need to be deleted
  830. set AddFinished=%ReleaseDir%\%1\symsrv\%Lang%\add_finished
  831. REM This should have already been checked, but we'll double-check here
  832. if not exist %AddFinished% (
  833. goto EndUnindexSymbols
  834. )
  835. REM
  836. REM See if the symbol server (eg. \\symbols\projects\winmain\del_requests for main lab) is there
  837. REM
  838. dir /b %DelReq% >nul 2>nul
  839. if !ERRORLEVEL! NEQ 0 (
  840. call logmsg.cmd "Cannot access %DelReq% to unindex symbols"
  841. REM set ThereWereErrors=yes
  842. goto :EOF
  843. )
  844. REM
  845. REM Copy the .ssi files to delete requests if they exist
  846. REM
  847. for %%a in ( ssi ) do (
  848. if exist %AddFinished%\*.%%a (
  849. for /f %%b in ( 'dir /b /s %AddFinished%\*.%%a' ) do (
  850. call logmsg.cmd "Sending delete for %%b to symbols server"
  851. xcopy /qcdehikr %%b %DelReq%
  852. if !ERRORLEVEL! NEQ 0 (
  853. call logmsg.cmd "Failed to Copy %%b to %DelReq%"
  854. REM set ThereWereErrors=yes
  855. goto :EOF
  856. )
  857. call logmsg.cmd "%%b submitted to %DelReq%"
  858. del /q %%b
  859. if exist %%b (
  860. call logmsg.cmd "Delete %%b failed"
  861. REM set ThereWereErrors=yes
  862. goto :EOF
  863. )
  864. )
  865. )
  866. )
  867. :EndUnindexSymbols
  868. goto :EOF
  869. REM **********************************************************************
  870. REM CreateListOfPossibleBuildsToDelete
  871. REM
  872. REM %1 DeleteTmpDir
  873. REM
  874. REM %2 CurArchType
  875. REM
  876. REM This creates a list of the builds that can be partially deleted
  877. REM
  878. REM Result - %DeleteTmpDir%\Delete.txt -- this is a sorted list, the ones
  879. REM that should be deleted first are at the top of the list.
  880. REM If there are no builds to delete %DeleteTmpDir%\Delete.txt
  881. REM does not exist when this call is over, and ThereWereErrors=yes
  882. REM
  883. REM **********************************************************************
  884. :CreateListOfPossibleBuildsToDelete
  885. set ThereWereErrors=
  886. set ThisDeleteTmpDir=%1\CreateList
  887. if "%1"=="" (
  888. call errmsg.cmd "ASSERT: DeleteTmpDir not defined"
  889. set ThereWereErrors=yes
  890. goto :EOF
  891. )
  892. if "%2"=="" (
  893. call errmsg.cmd "ASSERT: CurArchType not defined"
  894. set ThereWereErrors=yes
  895. goto :EOF
  896. )
  897. if not exist %1 (
  898. call errmsg.cmd "ASSERT: %1 does not exist"
  899. set ThereWereErrors=yes
  900. goto :EOF
  901. )
  902. if exist %1\delete.txt (
  903. del /q %1\delete.txt
  904. if exist %1\delete.txt (
  905. call errmsg.cmd "Could not delete %1\delete.txt"
  906. set ThereWereErrors=yes
  907. goto :EOF
  908. )
  909. )
  910. if exist %ThisDeleteTmpDir% (
  911. rd /s /q %ThisDeleteTmpDir%
  912. if exist %ThisDeleteTmpDir% (
  913. call errmsg.cmd "Could not remove %ThisDeleteTmpDir%
  914. set ThereWereErrors=yes
  915. goto :EOF
  916. )
  917. )
  918. md %ThisDeleteTmpDir%
  919. if not exist %ThisDeleteTmpDir% (
  920. call errmsg.cmd "Could not create %ThisDeleteTmpDir%"
  921. set ThereWereErrors=yes
  922. goto :EOF
  923. )
  924. REM Put the date, time, and build name into %1\possible.txt
  925. REM so that we can sort according date first, then time
  926. if not exist %ReleaseDir%\*.%2.%_BuildBranch%.* (
  927. call logmsg "No %2 builds for %_BuildBranch% exist in %ReleaseDir%"
  928. goto :EOF
  929. )
  930. for /f %%a in ('dir /b /ad %ReleaseDir%\*.%2.%_BuildBranch%.*') do (
  931. set BuildNameCmd=%RazzleToolPath%\postbuildscripts\buildname.cmd
  932. for /f "tokens=1,2 delims=-" %%b in ('!BuildNameCmd! -name %%a build_date') do (
  933. set ThisBuild=%%a
  934. set ThisDate=%%b
  935. set ThisTime=%%c
  936. )
  937. REM make sure the build we're looking at isn't sav, idw, ids, or idc
  938. set ThisQly=UNKNOWN
  939. if exist %ReleaseDir%\%%a\build_logs\*.qly (
  940. for /f %%n in ('dir /b %ReleaseDir%\%%a\build_logs\*.qly') do (
  941. if /i "%%n" == "sav.qly" set ThisQly=SAV
  942. if /i "%%n" == "idw.qly" set ThisQly=IDW
  943. if /i "%%n" == "ids.qly" set ThisQly=IDS
  944. if /i "%%n" == "idc.qly" set ThisQly=IDC
  945. )
  946. )
  947. if /i "!ExcludeBuild!" == "%%a" (
  948. call logmsg "Will not delete %%a because its on the exclusion list"
  949. set ThisQly=SAV
  950. )
  951. if exist %ReleaseDir%\%%a\build_logs\*.intl (
  952. set ThisQly=INTL
  953. )
  954. REM Write the date, time, quality, build name to possible.txt
  955. REM By doing this, we can use sort to sort them by date, and then time
  956. echo !ThisDate!,!ThisTime!,!ThisQly!,%%a >> %ThisDeleteTmpDir%\possible.txt
  957. )
  958. if not exist %ThisDeleteTmpDir%\possible.txt (
  959. call errmsg.cmd "Cannot write to possible.txt"
  960. goto :EOF
  961. )
  962. REM First sort so the most recent builds are first and then
  963. REM its easy to remove the first %BuildsToKeep% from the file.
  964. sort /R %ThisDeleteTmpDir%\possible.txt > %ThisDeleteTmpDir%\list2.txt
  965. if not exist %ThisDeleteTmpDir%\list2.txt (
  966. call errmsg.cmd "Error in sort -- %ThisDeleteTmpDir%\list2.txt not created"
  967. set ThereWereErrors=yes
  968. goto :EOF
  969. )
  970. REM Remove the builds that need to stay as full builds
  971. set /a num=0
  972. REM The skip doesn't work if %BuildsToKeep% is equal to 0
  973. if %BuildsToKeep% GTR 0 (
  974. for /f "tokens=1,2,3,4 skip=%BuildsToKeep% delims=," %%a in (%ThisDeleteTmpDir%\list2.txt) do (
  975. REM Skip Qly builds
  976. set ThisDate=%%a
  977. set ThisTime=%%b
  978. set ThisQly=%%c
  979. set ThisBuild=%%d
  980. if /i "!ThisQly!" == "UNKNOWN" (
  981. echo !ThisDate!,!ThisTime!,!ThisBuild! >> %ThisDeleteTmpDir%\list3.txt
  982. set /a num=!num!+1
  983. ) else (
  984. REM we can't delete this build
  985. call logmsg.cmd "Must keep !ThisBuild! because it is !ThisQly! quality"
  986. )
  987. )
  988. ) else (
  989. for /f "tokens=1,2,3,* delims=," %%a in (%ThisDeleteTmpDir%\list2.txt) do (
  990. REM Skip Qly builds
  991. set ThisDate=%%a
  992. set ThisTime=%%b
  993. set ThisQly=%%c
  994. set ThisBuild=%d
  995. if /i "!ThisQly!" == "UNKNOWN" (
  996. echo !ThisDate!,!ThisTime!,!ThisBuild! >> %ThisDeleteTmpDir%\list3.txt
  997. set /a num=!num!+1
  998. ) else (
  999. REM we can't delete this build
  1000. call logmsg.cmd "Must keep !ThisBuild! because it is !ThisQly! quality"
  1001. )
  1002. )
  1003. )
  1004. if not exist %ThisDeleteTmpDir%\list3.txt (
  1005. call logmsg.cmd "No %2 builds can be deleted, keeping minimum of %BuildsToKeep% builds."
  1006. goto :EOF
  1007. )
  1008. REM Sort, putting the oldest builds first
  1009. sort %ThisDeleteTmpDir%\list3.txt > %ThisDeleteTmpDir%\list4.txt
  1010. REM now, remove the time and date tokens from the beginning
  1011. REM Create delete.txt which is a sorted list of the builds that could be deleted
  1012. if exist %1\delete.txt del /q %1\delete.txt
  1013. for /f "tokens=3 delims=," %%a in (%ThisDeleteTmpDir%\list4.txt) do (
  1014. echo %%a >> %1\delete.txt
  1015. )
  1016. if not exist %1\delete.txt (
  1017. call errmsg.cmd "Error creating the %CurArchType% delete list: %DeleteTmpDir%\delete.txt"
  1018. set ThereWereErrors=yes
  1019. goto :EOF
  1020. )
  1021. :EndCreateListOfPossibleBuildsToDelete
  1022. goto :EOF
  1023. REM **********************************************************************
  1024. REM DeleteTrivia
  1025. REM
  1026. REM Things that need to be done for a delete.
  1027. REM %1 is the build name
  1028. REM
  1029. REM **********************************************************************
  1030. :DeleteTrivia %1
  1031. set ThereWereErrors=
  1032. if not exist %ReleaseDir%\%1 (
  1033. call errmsg.cmd "ASSERT: %ReleaseDir%\%1 does not exist!
  1034. set TherewereErrors=yes
  1035. goto :EOF
  1036. )
  1037. if defined MAIN_BUILD_LAB_MACHINE (
  1038. set BuildNameCmd=%RazzleToolPath%\postbuildscripts\buildname.cmd
  1039. for /f "tokens=1,2,3" %%b in ('!BuildNameCmd! -name %1 build_number build_flavor build_date') do (
  1040. set MyBuildNum=%%b
  1041. set MyBuildPlatType=%%c
  1042. for /f "tokens=1,2 delims=-" %%e in ('echo %%d') do (
  1043. set MyDate=%%e
  1044. set MyTime=%%f
  1045. )
  1046. )
  1047. set MyBuildPlatform=!MyBuildPlatType:~0,-3!
  1048. set MyBuildType=!MyBuildPlatType:~-3!
  1049. if defined ThisIsASymFarm (
  1050. set ThisCommandLine=!CmdIni! -l:!Lang! -f:ReleaseServers::!MyBuildPlatType!
  1051. !ThisCommandLine! >nul 2>nul
  1052. if !ERRORLEVEL! NEQ 0 (
  1053. set ThereWereErrors=yes
  1054. goto :EOF
  1055. )
  1056. for /f "tokens=1 delims=" %%a in ('!ThisCommandLine!') do (
  1057. for %%b in (%%a) do (
  1058. call logmsg.cmd "Lowering Build share from DFS for %%a"
  1059. set RaiseallCommand=perl raiseall.pl -n:!MyBuildNum! -lower -a:!MyBuildPlatform! -t:!MyBuildType! -time:!MyDate!-!MyTime! -l:!Lang!
  1060. call logmsg "!RaiseallCommand!"
  1061. call logmsg "Piped to remote /c %%b release /l 1"
  1062. echo !RaiseallCommand! | remote /c %%b release /l 1
  1063. )
  1064. )
  1065. )
  1066. if defined ThisIsAReleaseServer (
  1067. call logmsg.cmd "Lowering Build share from DFS"
  1068. perl raiseall.pl -n:!MyBuildNum! -lower -a:!MyBuildPlatform! -t:!MyBuildType! -time:!MyDate!-!MyTime! -l:%Lang%
  1069. REM delete the symbolCD associated with the build to be deleted
  1070. REM we need the build number from the build name
  1071. if exist %ReleaseDir%\%1\%Lang%\SymbolCD\!MyBuildNum! (
  1072. rd /s /q %ReleaseDir%\%1\%Lang%\SymbolCD\!MyBuildNum!
  1073. if exist %ReleaseDir%\%1\%Lang%\SymbolCD\!MyBuildNum! (
  1074. call errmsg.cmd "Failed to delete symbol CD for build !MyBuildNum!"
  1075. set ThereWereErrors=yes
  1076. goto :EOF
  1077. )
  1078. )
  1079. )
  1080. )
  1081. :EndDeleteTrivia
  1082. goto :EOF
  1083. REM ************************************************************************
  1084. REM GetFreeSpace
  1085. REM
  1086. REM Set %FreeSpace% equal to the amount of free disk for the drive for the
  1087. REM path passed in as %1. The free space is reported in GB. If the
  1088. REM number of bytes free is less than 1 GB, %FreeSpace% is set to 0.
  1089. REM
  1090. REM Result - %ThereWereErrors% is set to "yes" if there are errors in the function.
  1091. REM %ThereWereErrors% is not defined if the function finishes
  1092. REM successfully.
  1093. REM
  1094. REM ************************************************************************
  1095. :GetFreeSpace %1
  1096. set ThereWereErrors=
  1097. set FreeSpace=
  1098. if not exist %1 (
  1099. call errmsg.cmd "Cannot determine free disk space for %1"
  1100. set ThereWereErrors=yes
  1101. goto :EOF
  1102. )
  1103. REM This is cheesey, but the third token of the last line of the dir command
  1104. REM is the free disk space
  1105. for /f "tokens=3 delims= " %%a in ('dir %1') do (
  1106. set DiskSpace=%%a
  1107. )
  1108. REM Now, make it a number in gigabytes
  1109. set /a FreeSpace=0
  1110. for /f "tokens=1,2,3,4,5 delims=," %%a in ("%DiskSpace%") do (
  1111. if /i not "%%d" == "" set /a FreeSpace=%%a
  1112. if /i not "%%e" == "" set /a FreeSpace="!FreeSpace!*1000+%%b"
  1113. )
  1114. :EndGetFreeSpace
  1115. goto :EOF
  1116. REM **************************************************************************
  1117. REM CreateDeleteTmpDir
  1118. REM
  1119. REM %1 Name of the temporary directory to create
  1120. REM
  1121. REM Creates the temporary directory %1
  1122. REm
  1123. REM **************************************************************************
  1124. :CreateDeleteTmpDir
  1125. set ThereWereErrors=
  1126. REM Make sure the temp directory is empty
  1127. if exist %1 (
  1128. rd /s /q %1
  1129. if exist %1 (
  1130. call errmsg.cmd "Cannot remove temp directory %DeleteTmpDir%
  1131. set ThereWereErrors=yes
  1132. goto :EOF
  1133. )
  1134. )
  1135. md %1
  1136. if not exist %1 (
  1137. call errmsg.cmd "Cannot create temp directory %DeleteTmpDir%"
  1138. set ThereWereErrors=yes
  1139. goto :EOF
  1140. )
  1141. :EndCreateDeleteTmpDir
  1142. goto :EOF
  1143. REM *************************************************************************
  1144. REM GetReleaseDir
  1145. REM
  1146. REM Gets the release directory from the "release" share on the local computer.
  1147. REM If this is a symbol farm, it gets the "symfarm" share on the local computer.
  1148. REM
  1149. REM Results:
  1150. REM
  1151. REM ReleaseDir is set to the release point via "net share release"
  1152. REM or "net share symfarm"
  1153. REM
  1154. REM *************************************************************************
  1155. :GetReleaseDir
  1156. set ThereWereErrors=
  1157. if defined ThisIsASymFarm goto GetReleaseDirSymFarm
  1158. REM Oddly enough, AlternateReleaseDir does not apply to release servers
  1159. REM release servers always use the 'release' share.
  1160. if defined ThisIsAReleaseServer goto GetReleaseDirReleaseServer
  1161. REM Take into account the release share for fork builds
  1162. REM The fork release share name will be stored in the ini file as AlternateReleaseDir
  1163. set CommandLine=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  1164. set CommandLine=!CommandLine! -l:%lang%
  1165. set CommandLine=!CommandLine! -f:AlternateReleaseDir
  1166. %CommandLine% >nul 2>nul
  1167. if !ErrorLevel! NEQ 0 (
  1168. REM there was an error reading the ini file, assume it's not a problem
  1169. REM as the ini might not reference AlternateReleaseDir
  1170. set ReleaseShareName=release
  1171. ) else (
  1172. for /f %%a in ('!CommandLine!') do set ReleaseShareName=%%a
  1173. )
  1174. if not defined ReleaseShareName (
  1175. call logmsg.cmd "No release share name found, using default 'release'"
  1176. set ReleaseShareName=release
  1177. )
  1178. net share %ReleaseShareName% >nul 2>nul
  1179. if !ERRORLEVEL! NEQ 0 (
  1180. set ThereWereErrors=yes
  1181. goto :EOF
  1182. )
  1183. set ReleaseDir=
  1184. for /f "tokens=1,2" %%a in ('net share !ReleaseShareName!') do (
  1185. if /i "%%a" == "Path" (
  1186. REM at this point, %%b is the local path to the default release directory
  1187. call logmsg.cmd "Using 'net share !ReleaseShareName!' to find the release directory"
  1188. set ReleaseDir=%%b
  1189. )
  1190. )
  1191. if not defined ReleaseDir (
  1192. set ThereWereErrors=yes
  1193. goto :EOF
  1194. )
  1195. REM For some reason it was decided early on that build machines that
  1196. REM were building the language usa would not append a usa subdirectory
  1197. REM after their release directory, but all other languages would do so on
  1198. REM their build machines. Also, every language including usa would
  1199. REM append it on release directory of release servers. These exceptions
  1200. REM abound throughout our scripts!
  1201. if /i "%lang%" neq "usa" (
  1202. set ReleaseDir=!ReleaseDir!\%Lang%
  1203. )
  1204. goto EndReleaseDir
  1205. :GetReleaseDirSymFarm
  1206. net share symfarm >nul 2>nul
  1207. if !ERRORLEVEL! NEQ 0 (
  1208. set ThereWereErrors=yes
  1209. goto :EOF
  1210. )
  1211. set ReleaseDir=
  1212. for /f "tokens=1,2" %%a in ('net share symfarm') do (
  1213. if /i "%%a" == "Path" (
  1214. REM at this point, %%b is the local path to the default release directory
  1215. set ReleaseDir=%%b
  1216. )
  1217. )
  1218. if not defined ReleaseDir (
  1219. set ThereWereErrors=yes
  1220. goto :EOF
  1221. )
  1222. call logmsg.cmd "Adding %Lang% to the symfarm path"
  1223. set ReleaseDir=!ReleaseDir!\%Lang%
  1224. goto EndReleaseDir
  1225. :GetReleaseDirReleaseServer
  1226. net share release >nul 2>nul
  1227. if !ERRORLEVEL! NEQ 0 (
  1228. set ThereWereErrors=yes
  1229. goto :EOF
  1230. )
  1231. set ReleaseDir=
  1232. for /f "tokens=1,2" %%a in ('net share release') do (
  1233. if /i "%%a" == "Path" (
  1234. REM at this point, %%b is the local path to the default release directory
  1235. call logmsg.cmd "Using 'net share release' to find the release directory"
  1236. set ReleaseDir=%%b
  1237. )
  1238. )
  1239. if not defined ReleaseDir (
  1240. set ThereWereErrors=yes
  1241. goto :EOF
  1242. )
  1243. set ReleaseDir=!ReleaseDir!\%Lang%
  1244. :EndReleaseDir
  1245. goto :EOF
  1246. REM **************************************************************************
  1247. REM
  1248. REM WhatAmI %1
  1249. REM
  1250. REM %1 is the Current Architecture type (x86fre x86chk amd64fre amd64chk ia64fre ia64chk)
  1251. REM
  1252. REM Decides if this is a build machine
  1253. REM
  1254. REM Results:
  1255. REM ThisIsABuildMachine undefined if this is not a build machine
  1256. REM yes - if this is a build machine
  1257. REM
  1258. REM ThisIsAReleaseServer undefined if this is not a release server
  1259. REM yes - if this is a release server
  1260. REM
  1261. REM ThisIsASymFarm undefined if this is not a symbol farm
  1262. REM yes - if this is a symbol farm
  1263. REM
  1264. REM SymFarmExists undefined if there is no symbol farm
  1265. REM yes - if a symbol farm exists
  1266. REM
  1267. REM ReleaseServerExists undefined if there are no releas servers
  1268. REM yes - if there is a release server
  1269. REM
  1270. REM IndexableReleaseServer undefined if the symbol server should not
  1271. REM have indexes point to this server.
  1272. REM yes - if indexes can point to this server.
  1273. REM
  1274. REM **************************************************************************
  1275. :WhatAmI
  1276. set ThereWereErrors=
  1277. set ThisIsABuildMachine=
  1278. set ThisIsAReleaseServer=
  1279. set ThisIsASymFarm=
  1280. set SymFarmExists=
  1281. set ReleaseServerExists=
  1282. set IndexableReleaseServer=
  1283. set SymbolServerBuildShare=
  1284. set ThisCommandLine=%CmdIni% -l:%Lang% -f:BuildMachines::%1
  1285. %ThisCommandLine% >nul 2>nul
  1286. if !ERRORLEVEL! EQU 0 (
  1287. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1288. for %%b in ( %%a ) do (
  1289. if /i "%%b" == "%COMPUTERNAME%" (
  1290. set ThisIsABuildMachine=yes
  1291. )
  1292. )
  1293. )
  1294. )
  1295. set ThisCommandLine=%CmdIni% -l:%Lang% -f:ReleaseServers::%1
  1296. %ThisCommandLine% >nul 2>nul
  1297. if !ERRORLEVEL! EQU 0 (
  1298. set ReleaseServerExists=yes
  1299. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1300. set first=yes
  1301. for %%b in ( %%a ) do (
  1302. if /i "%%b" == "%COMPUTERNAME%" (
  1303. set ThisIsAReleaseServer=yes
  1304. if /i "!first!" == "yes" (
  1305. set IndexableReleaseServer=yes
  1306. )
  1307. goto WhatAmI2
  1308. )
  1309. set first=no
  1310. )
  1311. )
  1312. )
  1313. :WhatAmI2
  1314. set ThisCommandLine=%CmdIni% -l:%Lang% -f:SymFarm
  1315. %ThisCommandLine% >nul 2>nul
  1316. if !ERRORLEVEL! EQU 0 (
  1317. set SymFarmExists=yes
  1318. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1319. echo %%a | findstr /i %COMPUTERNAME% >nul 2>nul
  1320. if !ERRORLEVEL! EQU 0 (
  1321. set ThisIsASymFarm=yes
  1322. goto EndWhatAmI
  1323. )
  1324. )
  1325. )
  1326. if not defined ThisIsABuildMachine (
  1327. if not defined ThisIsAReleaseServer (
  1328. if not defined ThisIsASymFarm (
  1329. call errmsg "%COMPUTERNAME% and %1 is not a defined combination in the ini file"
  1330. set ThereWereErrors=yes
  1331. )))
  1332. :EndWhatAmI
  1333. goto :EOF
  1334. REM **************************************************************************
  1335. REM
  1336. REM GetBuildsToKeep %1
  1337. REM
  1338. REM %1 - Archtype (x86fre, x86chk, etc.)
  1339. REm
  1340. REM Get how many builds to keep from the ini file.
  1341. REM
  1342. REM Return values
  1343. REM
  1344. REM BuildsToKeep undefined if not in the ini file
  1345. REM number of builds to keep if defined in ini file
  1346. REM
  1347. REM
  1348. REM ***************************************************************************
  1349. :GetBuildsToKeep %1
  1350. set ThereWereErrors=
  1351. if defined ThisIsABuildMachine (
  1352. set param=BuildMachineBuildsToKeep::%COMPUTERNAME%
  1353. )
  1354. if defined ThisIsAReleaseServer (
  1355. set param=ReleaseServerBuildsToKeep::%COMPUTERNAME%::%1
  1356. )
  1357. if defined ThisIsASymFarm (
  1358. set param=SymFarmBuildsToKeep::%COMPUTERNAME%::%1
  1359. )
  1360. set ThisCommandLine=%CmdIni% -l:%Lang% -f:%param%
  1361. %ThisCommandLine% >nul 2>nul
  1362. if !ERRORLEVEL! NEQ 0 (
  1363. call logmsg.cmd "%param% is not defined in the ini file, reverting to default"
  1364. set BuildsToKeep=%DefaultBuildsToKeep%
  1365. ) else (
  1366. for /f %%a in ('%ThisCommandLine%') do (
  1367. set BuildsToKeep=%%a
  1368. )
  1369. )
  1370. goto :EOF
  1371. REM **************************************************************************
  1372. REM
  1373. REM GetArchsToDelete
  1374. REM
  1375. REM Get a list of the architectures that we are supposed to delete
  1376. REM
  1377. REM Right now this only gets called if this is a SymFarm
  1378. REM
  1379. REM Return values
  1380. REM
  1381. REM ArchsToDelete %CurArchType% if there is no list of archs to delete
  1382. REM if this is in the ini file, then it is a list of archs
  1383. REM to delete
  1384. REM
  1385. REM **************************************************************************
  1386. :GetArchsToDelete
  1387. set ThereWereErrors=
  1388. set ArchsToDelete=
  1389. set ArchsToDelete=%CurArchType%
  1390. if not defined ThisIsASymFarm goto :EOF
  1391. set param=SymFarmArchsToDelete::%COMPUTERNAME%
  1392. set ThisCommandLine=%CmdIni% -l:%Lang% -f:%param%
  1393. %ThisCommandLine% >nul 2>nul
  1394. if !ERRORLEVEL! NEQ 0 (
  1395. call logmsg.cmd "%param% is not defined in the ini file"
  1396. ) else (
  1397. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1398. set ArchsToDelete=%%a
  1399. )
  1400. )
  1401. goto :EOF
  1402. REM **************************************************************************
  1403. REM
  1404. REM GetFreeSpaceReq %1
  1405. REM
  1406. REM %1 - Archtype (x86fre, x86chk, etc.)
  1407. REm
  1408. REM Get how much free space is required from the ini file.
  1409. REM
  1410. REM Return values
  1411. REM
  1412. REM FreeSpaceReq undefined if not in the ini file
  1413. REM number of builds to keep if defined in ini file
  1414. REM
  1415. REM
  1416. REM ***************************************************************************
  1417. :GetFreeSpaceReq %1
  1418. set ThereWereErrors=
  1419. if defined ThisIsABuildMachine (
  1420. set param=BuildMachineFreeSpace::%COMPUTERNAME%
  1421. )
  1422. if defined ThisIsAReleaseServer (
  1423. set param=ReleaseServerFreeSpace::%COMPUTERNAME%
  1424. )
  1425. if defined ThisIsASymFarm (
  1426. set param=SymFarmFreeSpace::%COMPUTERNAME%
  1427. )
  1428. set ThisCommandLine=%CmdIni% -l:%Lang% -f:%param%
  1429. %ThisCommandLine% >nul 2>nul
  1430. if !ERRORLEVEL! NEQ 0 (
  1431. call logmsg.cmd "%param% is not defined in the ini file"
  1432. set FreeSpaceReq=%DefaultFreeSpaceReq%
  1433. ) else (
  1434. for /f %%a in ('%ThisCommandLine%') do (
  1435. set FreeSpaceReq=%%a
  1436. )
  1437. )
  1438. goto :EOF
  1439. REM **************************************************************************
  1440. REM
  1441. REM SortBuildList %1 %2
  1442. REM
  1443. REM %1 Temporary deleteDirectory
  1444. REM
  1445. REM %2 List to sort
  1446. REM
  1447. REM This sorts a list of builds, putting the oldest first
  1448. REM
  1449. REM Return value:
  1450. REM The sorted list is returned in %1\sorted.txt
  1451. REM
  1452. REM **************************************************************************
  1453. :SortBuildList %1 %2
  1454. set ThereWereErrors=
  1455. set ThisDeleteTmpDir=%1\sortbuildlist
  1456. if exist %ThisDeleteTmpDir% rd /s /q %ThisDeleteTmpDir%
  1457. if exist %ThisDeleteTmpDir% (
  1458. call errmsg "Could not remove %ThisDeleteTmpDir%"
  1459. set ThereWereErrors=yes
  1460. goto :EOF
  1461. )
  1462. call :CreateDeleteTmpDir %ThisDeleteTmpDir%
  1463. if defined ThereWereErrors (
  1464. call errmsg "Could not create %ThisDeleteTmpDir%"
  1465. goto :EOF
  1466. )
  1467. REM Put the date, time, and build name into %1\possible.txt
  1468. REM so that we can sort according to date first, then time
  1469. for /f %%a in ( %2 ) do (
  1470. set BuildNameCmd=%RazzleToolPath%\postbuildscripts\buildname.cmd
  1471. for /f "tokens=1,2 delims=-" %%b in ('!BuildNameCmd! -name %%a build_date') do (
  1472. set ThisBuild=%%a
  1473. set ThisDate=%%b
  1474. set ThisTime=%%c
  1475. )
  1476. REM Write the date, time, build name to possible.txt
  1477. REM By doing this, we can use sort to sort them by date, and then time
  1478. echo !ThisDate!,!ThisTime!,%%a >> %ThisDeleteTmpDir%\possible.txt
  1479. )
  1480. if not exist %ThisDeleteTmpDir%\possible.txt (
  1481. call errmsg.cmd "All builds have a sav, idw, ids, or idc qly file in build_logs"
  1482. call errmsg.cmd "or they are on the exclusion list"
  1483. call errmsg.cmd "No builds can be deleted from %ReleaseDir%"
  1484. set ThereWereErrors=yes
  1485. goto :EOF
  1486. )
  1487. sort %ThisDeleteTmpDir%\possible.txt > %ThisDeleteTmpDir%\sorted.txt
  1488. if not exist %ThisDeleteTmpDir%\sorted.txt (
  1489. call errmsg.cmd "Error in sort -- %ThisDeleteTmpDir%\sorted.txt not created"
  1490. set ThereWereErrors=yes
  1491. goto :EOF
  1492. )
  1493. if exist %1\sorted.txt (
  1494. del /f /q %1\sorted.txt
  1495. )
  1496. for /f "tokens=3 delims=," %%a in (%ThisDeleteTmpDir%\sorted.txt) do (
  1497. echo %%a>> %1\sorted.txt
  1498. )
  1499. if not exist %1\sorted.txt (
  1500. call errmsg.cmd "Error creating %1\sorted.txt"
  1501. set ThereWereErrors=yes
  1502. goto :EOF
  1503. )
  1504. goto :EOF
  1505. REM **************************************************************************
  1506. REM Usage
  1507. REM
  1508. REM **************************************************************************
  1509. :Usage
  1510. echo.
  1511. echo Usage:
  1512. echo deletebuild.cmd /b ^<Bld^> /a ^<ArchType^> ^[/r ^<RelDir^>^] ^[PARTIAL ^[Compress^]^] ^[/l ^<lang^>^]
  1513. echo ^[/e ^<Bld^>^]
  1514. echo.
  1515. echo deletebuild.cmd AUTO /a ^<ArchType^> ^[/r ^<RelDir^>^] ^[Compress^] ^[/f ^<FreeReq^>^]
  1516. echo ^[/k ^<BuildsToKeep^>^] ^[/l ^<lang^>^] ^[/e ^<Bld^>^]
  1517. echo.
  1518. echo Arch: x86fre ^| x86chk ^| ia64fre ^| ia64chk ^| amd64fre ^| amd64chk
  1519. echo.
  1520. echo AUTO "AUTO" delete builds based on the following priorities:
  1521. echo 1. Always delete from oldest to newest
  1522. echo 2. Never delete the newest ^<BuildsToKeep^> builds
  1523. echo 3. Delete until ^<FreeReq^> bytes are free, or until
  1524. echo no more builds can be deleted.
  1525. echo 4. Perform partial deletes first.
  1526. echo 4. Perform full deletes only if all eligible builds are
  1527. echo partially deleted.
  1528. echo.
  1529. echo /r Release directory that has the individual builds as
  1530. echo subdirectories. Default is to use the release directory
  1531. echo that is shared on the current computer.
  1532. echo.
  1533. echo /b Name of build.
  1534. echo.
  1535. echo Compress Enables NTFS compression on the remaining files. Normally not
  1536. echo necessary.
  1537. echo.
  1538. echo PARTIAL Only delete files not indexed on the symbol server.
  1539. echo Indexed files will remain. Default is to do a full delete.
  1540. echo.
  1541. echo /f Number of free Gigabytes required. Default is 10.
  1542. echo.
  1543. echo /a Architecture type for the build(s) to be deleted.
  1544. echo.
  1545. echo /k Number of builds to keep no matter what. Default is 3.
  1546. echo.
  1547. echo /l language. Default is USA.
  1548. echo.
  1549. echo /e Build to exclude from deleting
  1550. echo.
  1551. goto errend
  1552. :errend
  1553. endlocal
  1554. REM Set errorlevel to 1 in case of errors during execution.
  1555. seterror.exe 1
  1556. goto :EOF
  1557. :end
  1558. endlocal
  1559. REM Set errorlevel to 0 when the script finishes successfully.
  1560. seterror.exe 0
  1561. goto :EOF
  1562. REM **********************************************************
  1563. REM
  1564. REM Template
  1565. REM
  1566. REM **********************************************************
  1567. :MAIN
  1568. REM
  1569. REM Define SCRIPT_NAME. Used by the logging scripts.
  1570. REM
  1571. for %%i in (%0) do set script_name=%%~ni.cmd
  1572. REM
  1573. REM Save the command line.
  1574. REM
  1575. set cmdline=%script_name% %*
  1576. REM
  1577. REM Define LOGFILE, to be used by the logging scripts.
  1578. REM As the build rule scripts are typically invoked from wrappers (congeal.cmd),
  1579. REM LOGFILE is already defined.
  1580. REM
  1581. REM Do not redefine LOGFILE if already defined.
  1582. REM
  1583. if defined LOGFILE goto logfile_defined
  1584. if not exist %tmp% md %tmp%
  1585. for %%i in (%script_name%) do (
  1586. set LOGFILE=%tmp%\%%~ni.log
  1587. )
  1588. if exist %LOGFILE% del /f %LOGFILE%
  1589. :logfile_defined
  1590. REM
  1591. REM Create a temporary file, to be deleted when the script finishes its execution.
  1592. REM The existence of the temporary file tells congeal.cmd that this script is still running.
  1593. REM Before the temporary file is deleted, its contents are appended to LOGFILE.
  1594. REM International builds define tmpfile based on language prior to calling the US build
  1595. REM rule script, so that multiple languages can run the same build rule script concurrently.
  1596. REM
  1597. REM Do not redefine tmpfile if already defined.
  1598. REM
  1599. if defined tmpfile goto tmpfile_defined
  1600. if not exist %tmp% md %tmp%
  1601. for %%i in (%script_name%) do (
  1602. set tmpfile=%tmp%\%%~ni.tmp
  1603. )
  1604. if exist %tmpfile% del /f %tmpfile%
  1605. :tmpfile_defined
  1606. set LOGFILE_BAK=%LOGFILE%
  1607. set LOGFILE=%tmpfile%
  1608. REM
  1609. REM Mark the beginning of script's execution.
  1610. REM
  1611. call logmsg.cmd /t "START %cmdline%"
  1612. REM
  1613. REM Execute the build rule option.
  1614. REM
  1615. call :BeginDeleteBuild
  1616. if errorlevel 1 (set /A ERRORS=%errorlevel%) else (set /A ERRORS=0)
  1617. REM
  1618. REM Mark the end of script's execution.
  1619. REM
  1620. call logmsg.cmd /t "END %cmdline% (%ERRORS% errors)"
  1621. set LOGFILE=%LOGFILE_BAK%
  1622. REM
  1623. REM Append the contents of tmpfile to logfile, then delete tmpfile.
  1624. REM
  1625. type %tmpfile% >> %LOGFILE%
  1626. del /f %tmpfile%
  1627. echo.& echo %script_name% : %ERRORS% errors : see %LOGFILE%.
  1628. if "%ERRORS%" == "0" goto end_main
  1629. goto errend_main
  1630. :end_main
  1631. endlocal
  1632. goto end
  1633. :errend_main
  1634. endlocal
  1635. goto errend
  1636. :ExecuteCmd
  1637. REM Do not use setlocal/endlocal:
  1638. REM for ex., if the command itself is "pushd",
  1639. REM a "popd" will be executed automatically at the end.
  1640. set cmd_bak=cmd
  1641. set cmd=%1
  1642. REM Remove the quotes
  1643. set cmd=%cmd:~1,-1%
  1644. if "%cmd%" == "" (
  1645. call errmsg.cmd "internal error: no parameters for ExecuteCmd %1."
  1646. set cmd=cmd_bak& goto errend
  1647. )
  1648. REM Run the command.
  1649. call logmsg.cmd "Running %cmd%."
  1650. %cmd%
  1651. if not "%errorlevel%" == "0" (
  1652. call errmsg.cmd "%cmd% failed."
  1653. set cmd=%cmd_bak%& goto errend
  1654. )
  1655. set cmd=cmd_bak
  1656. goto end
  1657. :errend
  1658. seterror.exe 1
  1659. goto :EOF
  1660. :end
  1661. seterror.exe 0
  1662. goto :EOF
  1663. REM END