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.

2013 lines
54 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 ) 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. =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. )
  794. goto :EOF
  795. REM *********************************************************************
  796. REM UnindexSymbols
  797. REM
  798. REM This submits all the *.pri *.bin *.pub files in the
  799. REM %ReleaseDir%\%1\symsrv\%Lang%\add_finished directory to the
  800. REM del_requests directory on the symbol server, and then deletes them.
  801. REM
  802. REM *********************************************************************
  803. :UnindexSymbols %1
  804. set ThereWereErrors=
  805. set DelReq=%SymbolServerBuildShare%\del_requests
  806. REM Get the folder with the requests that need to be deleted
  807. set AddFinished=%ReleaseDir%\%1\symsrv\%Lang%\add_finished
  808. REM This should have already been checked, but we'll double-check here
  809. if not exist %AddFinished% (
  810. goto EndUnindexSymbols
  811. )
  812. REM See if the symbol server is there
  813. dir /b %DelReq% >nul 2>nul
  814. if !ERRORLEVEL! NEQ 0 (
  815. call logmsg.cmd "Cannot access %DelReq% to unindex symbols"
  816. REM set ThereWereErrors=yes
  817. goto :EOF
  818. )
  819. REM Copy the .bin .pri and .pub files to delete requests if they exist
  820. for %%a in ( bin pri pub ) do (
  821. if exist %AddFinished%\*.%%a (
  822. for /f %%b in ( 'dir /b /s %AddFinished%\*.%%a' ) do (
  823. call logmsg.cmd "Sending delete for %%b to symbols server"
  824. xcopy /qcdehikr %%b %DelReq%
  825. if !ERRORLEVEL! NEQ 0 (
  826. call logmsg.cmd "Failed to Copy %%b to %DelReq%"
  827. REM set ThereWereErrors=yes
  828. goto :EOF
  829. )
  830. call logmsg.cmd "%%b submitted to %DelReq%"
  831. del /q %%b
  832. if exist %%b (
  833. call logmsg.cmd "Delete %%b failed"
  834. REM set ThereWereErrors=yes
  835. goto :EOF
  836. )
  837. )
  838. )
  839. )
  840. :EndUnindexSymbols
  841. goto :EOF
  842. REM **********************************************************************
  843. REM CreateListOfPossibleBuildsToDelete
  844. REM
  845. REM %1 DeleteTmpDir
  846. REM
  847. REM %2 CurArchType
  848. REM
  849. REM This creates a list of the builds that can be partially deleted
  850. REM
  851. REM Result - %DeleteTmpDir%\Delete.txt -- this is a sorted list, the ones
  852. REM that should be deleted first are at the top of the list.
  853. REM If there are no builds to delete %DeleteTmpDir%\Delete.txt
  854. REM does not exist when this call is over, and ThereWereErrors=yes
  855. REM
  856. REM **********************************************************************
  857. :CreateListOfPossibleBuildsToDelete
  858. set ThereWereErrors=
  859. set ThisDeleteTmpDir=%1\CreateList
  860. if "%1"=="" (
  861. call errmsg.cmd "ASSERT: DeleteTmpDir not defined"
  862. set ThereWereErrors=yes
  863. goto :EOF
  864. )
  865. if "%2"=="" (
  866. call errmsg.cmd "ASSERT: CurArchType not defined"
  867. set ThereWereErrors=yes
  868. goto :EOF
  869. )
  870. if not exist %1 (
  871. call errmsg.cmd "ASSERT: %1 does not exist"
  872. set ThereWereErrors=yes
  873. goto :EOF
  874. )
  875. if exist %1\delete.txt (
  876. del /q %1\delete.txt
  877. if exist %1\delete.txt (
  878. call errmsg.cmd "Could not delete %1\delete.txt"
  879. set ThereWereErrors=yes
  880. goto :EOF
  881. )
  882. )
  883. if exist %ThisDeleteTmpDir% (
  884. rd /s /q %ThisDeleteTmpDir%
  885. if exist %ThisDeleteTmpDir% (
  886. call errmsg.cmd "Could not remove %ThisDeleteTmpDir%
  887. set ThereWereErrors=yes
  888. goto :EOF
  889. )
  890. )
  891. md %ThisDeleteTmpDir%
  892. if not exist %ThisDeleteTmpDir% (
  893. call errmsg.cmd "Could not create %ThisDeleteTmpDir%"
  894. set ThereWereErrors=yes
  895. goto :EOF
  896. )
  897. REM Put the date, time, and build name into %1\possible.txt
  898. REM so that we can sort according date first, then time
  899. if not exist %ReleaseDir%\*.%2.%_BuildBranch%.* (
  900. call logmsg "No %2 builds for %_BuildBranch% exist in %ReleaseDir%"
  901. goto :EOF
  902. )
  903. for /f %%a in ('dir /b /ad %ReleaseDir%\*.%2.%_BuildBranch%.*') do (
  904. set BuildNameCmd=%RazzleToolPath%\postbuildscripts\buildname.cmd
  905. for /f "tokens=1,2 delims=-" %%b in ('!BuildNameCmd! -name %%a build_date') do (
  906. set ThisBuild=%%a
  907. set ThisDate=%%b
  908. set ThisTime=%%c
  909. )
  910. REM make sure the build we're looking at isn't sav, idw, ids, or idc
  911. set ThisQly=UNKNOWN
  912. if exist %ReleaseDir%\%%a\build_logs\*.qly (
  913. for /f %%n in ('dir /b %ReleaseDir%\%%a\build_logs\*.qly') do (
  914. if /i "%%n" == "sav.qly" set ThisQly=SAV
  915. if /i "%%n" == "idw.qly" set ThisQly=IDW
  916. if /i "%%n" == "ids.qly" set ThisQly=IDS
  917. if /i "%%n" == "idc.qly" set ThisQly=IDC
  918. )
  919. )
  920. if /i "!ExcludeBuild!" == "%%a" (
  921. call logmsg "Will not delete %%a because its on the exclusion list"
  922. set ThisQly=SAV
  923. )
  924. if exist %ReleaseDir%\%%a\build_logs\*.intl (
  925. set ThisQly=INTL
  926. )
  927. REM Write the date, time, quality, build name to possible.txt
  928. REM By doing this, we can use sort to sort them by date, and then time
  929. echo !ThisDate!,!ThisTime!,!ThisQly!,%%a >> %ThisDeleteTmpDir%\possible.txt
  930. )
  931. if not exist %ThisDeleteTmpDir%\possible.txt (
  932. call errmsg.cmd "Cannot write to possible.txt"
  933. goto :EOF
  934. )
  935. REM First sort so the most recent builds are first and then
  936. REM its easy to remove the first %BuildsToKeep% from the file.
  937. sort /R %ThisDeleteTmpDir%\possible.txt > %ThisDeleteTmpDir%\list2.txt
  938. if not exist %ThisDeleteTmpDir%\list2.txt (
  939. call errmsg.cmd "Error in sort -- %ThisDeleteTmpDir%\list2.txt not created"
  940. set ThereWereErrors=yes
  941. goto :EOF
  942. )
  943. REM Remove the builds that need to stay as full builds
  944. set /a num=0
  945. REM The skip doesn't work if %BuildsToKeep% is equal to 0
  946. if %BuildsToKeep% GTR 0 (
  947. for /f "tokens=1,2,3,4 skip=%BuildsToKeep% delims=," %%a in (%ThisDeleteTmpDir%\list2.txt) do (
  948. REM Skip Qly builds
  949. set ThisDate=%%a
  950. set ThisTime=%%b
  951. set ThisQly=%%c
  952. set ThisBuild=%%d
  953. if /i "!ThisQly!" == "UNKNOWN" (
  954. echo !ThisDate!,!ThisTime!,!ThisBuild! >> %ThisDeleteTmpDir%\list3.txt
  955. set /a num=!num!+1
  956. ) else (
  957. REM we can't delete this build
  958. call logmsg.cmd "Must keep !ThisBuild! because it is !ThisQly! quality"
  959. )
  960. )
  961. ) else (
  962. for /f "tokens=1,2,3,* delims=," %%a in (%ThisDeleteTmpDir%\list2.txt) do (
  963. REM Skip Qly builds
  964. set ThisDate=%%a
  965. set ThisTime=%%b
  966. set ThisQly=%%c
  967. set ThisBuild=%d
  968. if /i "!ThisQly!" == "UNKNOWN" (
  969. echo !ThisDate!,!ThisTime!,!ThisBuild! >> %ThisDeleteTmpDir%\list3.txt
  970. set /a num=!num!+1
  971. ) else (
  972. REM we can't delete this build
  973. call logmsg.cmd "Must keep !ThisBuild! because it is !ThisQly! quality"
  974. )
  975. )
  976. )
  977. if not exist %ThisDeleteTmpDir%\list3.txt (
  978. call logmsg.cmd "No %2 builds can be deleted, keeping minimum of %BuildsToKeep% builds."
  979. goto :EOF
  980. )
  981. REM Sort, putting the oldest builds first
  982. sort %ThisDeleteTmpDir%\list3.txt > %ThisDeleteTmpDir%\list4.txt
  983. REM now, remove the time and date tokens from the beginning
  984. REM Create delete.txt which is a sorted list of the builds that could be deleted
  985. if exist %1\delete.txt del /q %1\delete.txt
  986. for /f "tokens=3 delims=," %%a in (%ThisDeleteTmpDir%\list4.txt) do (
  987. echo %%a >> %1\delete.txt
  988. )
  989. if not exist %1\delete.txt (
  990. call errmsg.cmd "Error creating the %CurArchType% delete list: %DeleteTmpDir%\delete.txt"
  991. set ThereWereErrors=yes
  992. goto :EOF
  993. )
  994. :EndCreateListOfPossibleBuildsToDelete
  995. goto :EOF
  996. REM **********************************************************************
  997. REM DeleteTrivia
  998. REM
  999. REM Things that need to be done for a delete.
  1000. REM %1 is the build name
  1001. REM
  1002. REM **********************************************************************
  1003. :DeleteTrivia %1
  1004. set ThereWereErrors=
  1005. if not exist %ReleaseDir%\%1 (
  1006. call errmsg.cmd "ASSERT: %ReleaseDir%\%1 does not exist!
  1007. set TherewereErrors=yes
  1008. goto :EOF
  1009. )
  1010. if defined MAIN_BUILD_LAB_MACHINE (
  1011. set BuildNameCmd=%RazzleToolPath%\postbuildscripts\buildname.cmd
  1012. for /f "tokens=1,2,3" %%b in ('!BuildNameCmd! -name %1 build_number build_flavor build_date') do (
  1013. set MyBuildNum=%%b
  1014. set MyBuildPlatType=%%c
  1015. for /f "tokens=1,2 delims=-" %%e in ('echo %%d') do (
  1016. set MyDate=%%e
  1017. set MyTime=%%f
  1018. )
  1019. )
  1020. set MyBuildPlatform=!MyBuildPlatType:~0,-3!
  1021. set MyBuildType=!MyBuildPlatType:~-3!
  1022. if defined ThisIsASymFarm (
  1023. set ThisCommandLine=!CmdIni! -l:!Lang! -f:ReleaseServers::!MyBuildPlatType!
  1024. !ThisCommandLine! >nul 2>nul
  1025. if !ERRORLEVEL! NEQ 0 (
  1026. set ThereWereErrors=yes
  1027. goto :EOF
  1028. )
  1029. for /f "tokens=1 delims=" %%a in ('!ThisCommandLine!') do (
  1030. for %%b in (%%a) do (
  1031. call logmsg.cmd "Lowering Build share from DFS for %%a"
  1032. set RaiseallCommand=perl raiseall.pl -n:!MyBuildNum! -lower -a:!MyBuildPlatform! -t:!MyBuildType! -time:!MyDate!-!MyTime! -l:!Lang!
  1033. call logmsg "!RaiseallCommand!"
  1034. call logmsg "Piped to remote /c %%b release /l 1"
  1035. echo !RaiseallCommand! | remote /c %%b release /l 1
  1036. )
  1037. )
  1038. )
  1039. if defined ThisIsAReleaseServer (
  1040. call logmsg.cmd "Lowering Build share from DFS"
  1041. perl raiseall.pl -n:!MyBuildNum! -lower -a:!MyBuildPlatform! -t:!MyBuildType! -time:!MyDate!-!MyTime! -l:%Lang%
  1042. REM delete the symbolCD associated with the build to be deleted
  1043. REM we need the build number from the build name
  1044. if exist %ReleaseDir%\%1\%Lang%\SymbolCD\!MyBuildNum! (
  1045. rd /s /q %ReleaseDir%\%1\%Lang%\SymbolCD\!MyBuildNum!
  1046. if exist %ReleaseDir%\%1\%Lang%\SymbolCD\!MyBuildNum! (
  1047. call errmsg.cmd "Failed to delete symbol CD for build !MyBuildNum!"
  1048. set ThereWereErrors=yes
  1049. goto :EOF
  1050. )
  1051. )
  1052. )
  1053. )
  1054. :EndDeleteTrivia
  1055. goto :EOF
  1056. REM ************************************************************************
  1057. REM GetFreeSpace
  1058. REM
  1059. REM Set %FreeSpace% equal to the amount of free disk for the drive for the
  1060. REM path passed in as %1. The free space is reported in GB. If the
  1061. REM number of bytes free is less than 1 GB, %FreeSpace% is set to 0.
  1062. REM
  1063. REM Result - %ThereWereErrors% is set to "yes" if there are errors in the function.
  1064. REM %ThereWereErrors% is not defined if the function finishes
  1065. REM successfully.
  1066. REM
  1067. REM ************************************************************************
  1068. :GetFreeSpace %1
  1069. set ThereWereErrors=
  1070. set FreeSpace=
  1071. if not exist %1 (
  1072. call errmsg.cmd "Cannot determine free disk space for %1"
  1073. set ThereWereErrors=yes
  1074. goto :EOF
  1075. )
  1076. REM This is cheesey, but the third token of the last line of the dir command
  1077. REM is the free disk space
  1078. for /f "tokens=3 delims= " %%a in ('dir %1') do (
  1079. set DiskSpace=%%a
  1080. )
  1081. REM Now, make it a number in gigabytes
  1082. set /a FreeSpace=0
  1083. for /f "tokens=1,2,3,4,5 delims=," %%a in ("%DiskSpace%") do (
  1084. if /i not "%%d" == "" set /a FreeSpace=%%a
  1085. if /i not "%%e" == "" set /a FreeSpace="!FreeSpace!*1000+%%b"
  1086. )
  1087. :EndGetFreeSpace
  1088. goto :EOF
  1089. REM **************************************************************************
  1090. REM CreateDeleteTmpDir
  1091. REM
  1092. REM %1 Name of the temporary directory to create
  1093. REM
  1094. REM Creates the temporary directory %1
  1095. REm
  1096. REM **************************************************************************
  1097. :CreateDeleteTmpDir
  1098. set ThereWereErrors=
  1099. REM Make sure the temp directory is empty
  1100. if exist %1 (
  1101. rd /s /q %1
  1102. if exist %1 (
  1103. call errmsg.cmd "Cannot remove temp directory %DeleteTmpDir%
  1104. set ThereWereErrors=yes
  1105. goto :EOF
  1106. )
  1107. )
  1108. md %1
  1109. if not exist %1 (
  1110. call errmsg.cmd "Cannot create temp directory %DeleteTmpDir%"
  1111. set ThereWereErrors=yes
  1112. goto :EOF
  1113. )
  1114. :EndCreateDeleteTmpDir
  1115. goto :EOF
  1116. REM *************************************************************************
  1117. REM GetReleaseDir
  1118. REM
  1119. REM Gets the release directory from the "release" share on the local computer.
  1120. REM If this is a symbol farm, it gets the "symfarm" share on the local computer.
  1121. REM
  1122. REM Results:
  1123. REM
  1124. REM ReleaseDir is set to the release point via "net share release"
  1125. REM or "net share symfarm"
  1126. REM
  1127. REM *************************************************************************
  1128. :GetReleaseDir
  1129. set ThereWereErrors=
  1130. if defined ThisIsASymFarm goto GetReleaseDirSymFarm
  1131. REM Oddly enough, AlternateReleaseDir does not apply to release servers
  1132. REM release servers always use the 'release' share.
  1133. if defined ThisIsAReleaseServer goto GetReleaseDirReleaseServer
  1134. REM Take into account the release share for fork builds
  1135. REM The fork release share name will be stored in the ini file as AlternateReleaseDir
  1136. set CommandLine=perl %RazzleToolPath%\PostBuildScripts\CmdIniSetting.pl
  1137. set CommandLine=!CommandLine! -l:%lang%
  1138. set CommandLine=!CommandLine! -f:AlternateReleaseDir
  1139. %CommandLine% >nul 2>nul
  1140. if !ErrorLevel! NEQ 0 (
  1141. REM there was an error reading the ini file, assume it's not a problem
  1142. REM as the ini might not reference AlternateReleaseDir
  1143. set ReleaseShareName=release
  1144. ) else (
  1145. for /f %%a in ('!CommandLine!') do set ReleaseShareName=%%a
  1146. )
  1147. if not defined ReleaseShareName (
  1148. call logmsg.cmd "No release share name found, using default 'release'"
  1149. set ReleaseShareName=release
  1150. )
  1151. net share %ReleaseShareName% >nul 2>nul
  1152. if !ERRORLEVEL! NEQ 0 (
  1153. set ThereWereErrors=yes
  1154. goto :EOF
  1155. )
  1156. set ReleaseDir=
  1157. for /f "tokens=1,2" %%a in ('net share !ReleaseShareName!') do (
  1158. if /i "%%a" == "Path" (
  1159. REM at this point, %%b is the local path to the default release directory
  1160. call logmsg.cmd "Using 'net share !ReleaseShareName!' to find the release directory"
  1161. set ReleaseDir=%%b
  1162. )
  1163. )
  1164. if not defined ReleaseDir (
  1165. set ThereWereErrors=yes
  1166. goto :EOF
  1167. )
  1168. REM For some reason it was decided early on that build machines that
  1169. REM were building the language usa would not append a usa subdirectory
  1170. REM after their release directory, but all other languages would do so on
  1171. REM their build machines. Also, every language including usa would
  1172. REM append it on release directory of release servers. These exceptions
  1173. REM abound throughout our scripts!
  1174. if /i "%lang%" neq "usa" (
  1175. set ReleaseDir=!ReleaseDir!\%Lang%
  1176. )
  1177. goto EndReleaseDir
  1178. :GetReleaseDirSymFarm
  1179. net share symfarm >nul 2>nul
  1180. if !ERRORLEVEL! NEQ 0 (
  1181. set ThereWereErrors=yes
  1182. goto :EOF
  1183. )
  1184. set ReleaseDir=
  1185. for /f "tokens=1,2" %%a in ('net share symfarm') do (
  1186. if /i "%%a" == "Path" (
  1187. REM at this point, %%b is the local path to the default release directory
  1188. set ReleaseDir=%%b
  1189. )
  1190. )
  1191. if not defined ReleaseDir (
  1192. set ThereWereErrors=yes
  1193. goto :EOF
  1194. )
  1195. call logmsg.cmd "Adding %Lang% to the symfarm path"
  1196. set ReleaseDir=!ReleaseDir!\%Lang%
  1197. goto EndReleaseDir
  1198. :GetReleaseDirReleaseServer
  1199. net share release >nul 2>nul
  1200. if !ERRORLEVEL! NEQ 0 (
  1201. set ThereWereErrors=yes
  1202. goto :EOF
  1203. )
  1204. set ReleaseDir=
  1205. for /f "tokens=1,2" %%a in ('net share release') do (
  1206. if /i "%%a" == "Path" (
  1207. REM at this point, %%b is the local path to the default release directory
  1208. call logmsg.cmd "Using 'net share release' to find the release directory"
  1209. set ReleaseDir=%%b
  1210. )
  1211. )
  1212. if not defined ReleaseDir (
  1213. set ThereWereErrors=yes
  1214. goto :EOF
  1215. )
  1216. set ReleaseDir=!ReleaseDir!\%Lang%
  1217. :EndReleaseDir
  1218. goto :EOF
  1219. REM **************************************************************************
  1220. REM
  1221. REM WhatAmI %1
  1222. REM
  1223. REM %1 is the Current Architecture type (x86fre x86chk amd64fre amd64chk ia64fre ia64chk)
  1224. REM
  1225. REM Decides if this is a build machine
  1226. REM
  1227. REM Results:
  1228. REM ThisIsABuildMachine undefined if this is not a build machine
  1229. REM yes - if this is a build machine
  1230. REM
  1231. REM ThisIsAReleaseServer undefined if this is not a release server
  1232. REM yes - if this is a release server
  1233. REM
  1234. REM ThisIsASymFarm undefined if this is not a symbol farm
  1235. REM yes - if this is a symbol farm
  1236. REM
  1237. REM SymFarmExists undefined if there is no symbol farm
  1238. REM yes - if a symbol farm exists
  1239. REM
  1240. REM ReleaseServerExists undefined if there are no releas servers
  1241. REM yes - if there is a release server
  1242. REM
  1243. REM IndexableReleaseServer undefined if the symbol server should not
  1244. REM have indexes point to this server.
  1245. REM yes - if indexes can point to this server.
  1246. REM
  1247. REM **************************************************************************
  1248. :WhatAmI
  1249. set ThereWereErrors=
  1250. set ThisIsABuildMachine=
  1251. set ThisIsAReleaseServer=
  1252. set ThisIsASymFarm=
  1253. set SymFarmExists=
  1254. set ReleaseServerExists=
  1255. set IndexableReleaseServer=
  1256. set SymbolServerBuildShare=
  1257. set ThisCommandLine=%CmdIni% -l:%Lang% -f:BuildMachines::%1
  1258. %ThisCommandLine% >nul 2>nul
  1259. if !ERRORLEVEL! EQU 0 (
  1260. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1261. for %%b in ( %%a ) do (
  1262. if /i "%%b" == "%COMPUTERNAME%" (
  1263. set ThisIsABuildMachine=yes
  1264. )
  1265. )
  1266. )
  1267. )
  1268. set ThisCommandLine=%CmdIni% -l:%Lang% -f:ReleaseServers::%1
  1269. %ThisCommandLine% >nul 2>nul
  1270. if !ERRORLEVEL! EQU 0 (
  1271. set ReleaseServerExists=yes
  1272. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1273. set first=yes
  1274. for %%b in ( %%a ) do (
  1275. if /i "%%b" == "%COMPUTERNAME%" (
  1276. set ThisIsAReleaseServer=yes
  1277. if /i "!first!" == "yes" (
  1278. set IndexableReleaseServer=yes
  1279. )
  1280. goto WhatAmI2
  1281. )
  1282. set first=no
  1283. )
  1284. )
  1285. )
  1286. :WhatAmI2
  1287. set ThisCommandLine=%CmdIni% -l:%Lang% -f:SymFarm
  1288. %ThisCommandLine% >nul 2>nul
  1289. if !ERRORLEVEL! EQU 0 (
  1290. set SymFarmExists=yes
  1291. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1292. echo %%a | findstr /i %COMPUTERNAME% >nul 2>nul
  1293. if !ERRORLEVEL! EQU 0 (
  1294. set ThisIsASymFarm=yes
  1295. goto EndWhatAmI
  1296. )
  1297. )
  1298. )
  1299. if not defined ThisIsABuildMachine (
  1300. if not defined ThisIsAReleaseServer (
  1301. if not defined ThisIsASymFarm (
  1302. call errmsg "%COMPUTERNAME% and %1 is not a defined combination in the ini file"
  1303. set ThereWereErrors=yes
  1304. )))
  1305. :EndWhatAmI
  1306. goto :EOF
  1307. REM **************************************************************************
  1308. REM
  1309. REM GetBuildsToKeep %1
  1310. REM
  1311. REM %1 - Archtype (x86fre, x86chk, etc.)
  1312. REm
  1313. REM Get how many builds to keep from the ini file.
  1314. REM
  1315. REM Return values
  1316. REM
  1317. REM BuildsToKeep undefined if not in the ini file
  1318. REM number of builds to keep if defined in ini file
  1319. REM
  1320. REM
  1321. REM ***************************************************************************
  1322. :GetBuildsToKeep %1
  1323. set ThereWereErrors=
  1324. if defined ThisIsABuildMachine (
  1325. set param=BuildMachineBuildsToKeep::%COMPUTERNAME%
  1326. )
  1327. if defined ThisIsAReleaseServer (
  1328. set param=ReleaseServerBuildsToKeep::%COMPUTERNAME%::%1
  1329. )
  1330. if defined ThisIsASymFarm (
  1331. set param=SymFarmBuildsToKeep::%COMPUTERNAME%::%1
  1332. )
  1333. set ThisCommandLine=%CmdIni% -l:%Lang% -f:%param%
  1334. %ThisCommandLine% >nul 2>nul
  1335. if !ERRORLEVEL! NEQ 0 (
  1336. call logmsg.cmd "%param% is not defined in the ini file, reverting to default"
  1337. set BuildsToKeep=%DefaultBuildsToKeep%
  1338. ) else (
  1339. for /f %%a in ('%ThisCommandLine%') do (
  1340. set BuildsToKeep=%%a
  1341. )
  1342. )
  1343. goto :EOF
  1344. REM **************************************************************************
  1345. REM
  1346. REM GetArchsToDelete
  1347. REM
  1348. REM Get a list of the architectures that we are supposed to delete
  1349. REM
  1350. REM Right now this only gets called if this is a SymFarm
  1351. REM
  1352. REM Return values
  1353. REM
  1354. REM ArchsToDelete %CurArchType% if there is no list of archs to delete
  1355. REM if this is in the ini file, then it is a list of archs
  1356. REM to delete
  1357. REM
  1358. REM **************************************************************************
  1359. :GetArchsToDelete
  1360. set ThereWereErrors=
  1361. set ArchsToDelete=
  1362. set ArchsToDelete=%CurArchType%
  1363. if not defined ThisIsASymFarm goto :EOF
  1364. set param=SymFarmArchsToDelete::%COMPUTERNAME%
  1365. set ThisCommandLine=%CmdIni% -l:%Lang% -f:%param%
  1366. %ThisCommandLine% >nul 2>nul
  1367. if !ERRORLEVEL! NEQ 0 (
  1368. call logmsg.cmd "%param% is not defined in the ini file"
  1369. ) else (
  1370. for /f "tokens=1 delims=" %%a in ('%ThisCommandLine%') do (
  1371. set ArchsToDelete=%%a
  1372. )
  1373. )
  1374. goto :EOF
  1375. REM **************************************************************************
  1376. REM
  1377. REM GetFreeSpaceReq %1
  1378. REM
  1379. REM %1 - Archtype (x86fre, x86chk, etc.)
  1380. REm
  1381. REM Get how much free space is required from the ini file.
  1382. REM
  1383. REM Return values
  1384. REM
  1385. REM FreeSpaceReq undefined if not in the ini file
  1386. REM number of builds to keep if defined in ini file
  1387. REM
  1388. REM
  1389. REM ***************************************************************************
  1390. :GetFreeSpaceReq %1
  1391. set ThereWereErrors=
  1392. if defined ThisIsABuildMachine (
  1393. set param=BuildMachineFreeSpace::%COMPUTERNAME%
  1394. )
  1395. if defined ThisIsAReleaseServer (
  1396. set param=ReleaseServerFreeSpace::%COMPUTERNAME%
  1397. )
  1398. if defined ThisIsASymFarm (
  1399. set param=SymFarmFreeSpace::%COMPUTERNAME%
  1400. )
  1401. set ThisCommandLine=%CmdIni% -l:%Lang% -f:%param%
  1402. %ThisCommandLine% >nul 2>nul
  1403. if !ERRORLEVEL! NEQ 0 (
  1404. call logmsg.cmd "%param% is not defined in the ini file"
  1405. set FreeSpaceReq=%DefaultFreeSpaceReq%
  1406. ) else (
  1407. for /f %%a in ('%ThisCommandLine%') do (
  1408. set FreeSpaceReq=%%a
  1409. )
  1410. )
  1411. goto :EOF
  1412. REM **************************************************************************
  1413. REM
  1414. REM SortBuildList %1 %2
  1415. REM
  1416. REM %1 Temporary deleteDirectory
  1417. REM
  1418. REM %2 List to sort
  1419. REM
  1420. REM This sorts a list of builds, putting the oldest first
  1421. REM
  1422. REM Return value:
  1423. REM The sorted list is returned in %1\sorted.txt
  1424. REM
  1425. REM **************************************************************************
  1426. :SortBuildList %1 %2
  1427. set ThereWereErrors=
  1428. set ThisDeleteTmpDir=%1\sortbuildlist
  1429. if exist %ThisDeleteTmpDir% rd /s /q %ThisDeleteTmpDir%
  1430. if exist %ThisDeleteTmpDir% (
  1431. call errmsg "Could not remove %ThisDeleteTmpDir%"
  1432. set ThereWereErrors=yes
  1433. goto :EOF
  1434. )
  1435. call :CreateDeleteTmpDir %ThisDeleteTmpDir%
  1436. if defined ThereWereErrors (
  1437. call errmsg "Could not create %ThisDeleteTmpDir%"
  1438. goto :EOF
  1439. )
  1440. REM Put the date, time, and build name into %1\possible.txt
  1441. REM so that we can sort according to date first, then time
  1442. for /f %%a in ( %2 ) do (
  1443. set BuildNameCmd=%RazzleToolPath%\postbuildscripts\buildname.cmd
  1444. for /f "tokens=1,2 delims=-" %%b in ('!BuildNameCmd! -name %%a build_date') do (
  1445. set ThisBuild=%%a
  1446. set ThisDate=%%b
  1447. set ThisTime=%%c
  1448. )
  1449. REM Write the date, time, build name to possible.txt
  1450. REM By doing this, we can use sort to sort them by date, and then time
  1451. echo !ThisDate!,!ThisTime!,%%a >> %ThisDeleteTmpDir%\possible.txt
  1452. )
  1453. if not exist %ThisDeleteTmpDir%\possible.txt (
  1454. call errmsg.cmd "All builds have a sav, idw, ids, or idc qly file in build_logs"
  1455. call errmsg.cmd "or they are on the exclusion list"
  1456. call errmsg.cmd "No builds can be deleted from %ReleaseDir%"
  1457. set ThereWereErrors=yes
  1458. goto :EOF
  1459. )
  1460. sort %ThisDeleteTmpDir%\possible.txt > %ThisDeleteTmpDir%\sorted.txt
  1461. if not exist %ThisDeleteTmpDir%\sorted.txt (
  1462. call errmsg.cmd "Error in sort -- %ThisDeleteTmpDir%\sorted.txt not created"
  1463. set ThereWereErrors=yes
  1464. goto :EOF
  1465. )
  1466. if exist %1\sorted.txt (
  1467. del /f /q %1\sorted.txt
  1468. )
  1469. for /f "tokens=3 delims=," %%a in (%ThisDeleteTmpDir%\sorted.txt) do (
  1470. echo %%a>> %1\sorted.txt
  1471. )
  1472. if not exist %1\sorted.txt (
  1473. call errmsg.cmd "Error creating %1\sorted.txt"
  1474. set ThereWereErrors=yes
  1475. goto :EOF
  1476. )
  1477. goto :EOF
  1478. REM **************************************************************************
  1479. REM Usage
  1480. REM
  1481. REM **************************************************************************
  1482. :Usage
  1483. echo.
  1484. echo Usage:
  1485. echo deletebuild.cmd /b ^<Bld^> /a ^<ArchType^> ^[/r ^<RelDir^>^] ^[PARTIAL ^[Compress^]^] ^[/l ^<lang^>^]
  1486. echo ^[/e ^<Bld^>^]
  1487. echo.
  1488. echo deletebuild.cmd AUTO /a ^<ArchType^> ^[/r ^<RelDir^>^] ^[Compress^] ^[/f ^<FreeReq^>^]
  1489. echo ^[/k ^<BuildsToKeep^>^] ^[/l ^<lang^>^] ^[/e ^<Bld^>^]
  1490. echo.
  1491. echo Arch: x86fre ^| x86chk ^| ia64fre ^| ia64chk ^| amd64fre ^| amd64chk
  1492. echo.
  1493. echo AUTO "AUTO" delete builds based on the following priorities:
  1494. echo 1. Always delete from oldest to newest
  1495. echo 2. Never delete the newest ^<BuildsToKeep^> builds
  1496. echo 3. Delete until ^<FreeReq^> bytes are free, or until
  1497. echo no more builds can be deleted.
  1498. echo 4. Perform partial deletes first.
  1499. echo 4. Perform full deletes only if all eligible builds are
  1500. echo partially deleted.
  1501. echo.
  1502. echo /r Release directory that has the individual builds as
  1503. echo subdirectories. Default is to use the release directory
  1504. echo that is shared on the current computer.
  1505. echo.
  1506. echo /b Name of build.
  1507. echo.
  1508. echo Compress Enables NTFS compression on the remaining files. Normally not
  1509. echo necessary.
  1510. echo.
  1511. echo PARTIAL Only delete files not indexed on the symbol server.
  1512. echo Indexed files will remain. Default is to do a full delete.
  1513. echo.
  1514. echo /f Number of free Gigabytes required. Default is 10.
  1515. echo.
  1516. echo /a Architecture type for the build(s) to be deleted.
  1517. echo.
  1518. echo /k Number of builds to keep no matter what. Default is 3.
  1519. echo.
  1520. echo /l language. Default is USA.
  1521. echo.
  1522. echo /e Build to exclude from deleting
  1523. echo.
  1524. goto errend
  1525. :errend
  1526. endlocal
  1527. REM Set errorlevel to 1 in case of errors during execution.
  1528. seterror.exe 1
  1529. goto :EOF
  1530. :end
  1531. endlocal
  1532. REM Set errorlevel to 0 when the script finishes successfully.
  1533. seterror.exe 0
  1534. goto :EOF
  1535. REM **********************************************************
  1536. REM
  1537. REM Template
  1538. REM
  1539. REM **********************************************************
  1540. :MAIN
  1541. REM
  1542. REM Define SCRIPT_NAME. Used by the logging scripts.
  1543. REM
  1544. for %%i in (%0) do set script_name=%%~ni.cmd
  1545. REM
  1546. REM Save the command line.
  1547. REM
  1548. set cmdline=%script_name% %*
  1549. REM
  1550. REM Define LOGFILE, to be used by the logging scripts.
  1551. REM As the build rule scripts are typically invoked from wrappers (congeal.cmd),
  1552. REM LOGFILE is already defined.
  1553. REM
  1554. REM Do not redefine LOGFILE if already defined.
  1555. REM
  1556. if defined LOGFILE goto logfile_defined
  1557. if not exist %tmp% md %tmp%
  1558. for %%i in (%script_name%) do (
  1559. set LOGFILE=%tmp%\%%~ni.log
  1560. )
  1561. if exist %LOGFILE% del /f %LOGFILE%
  1562. :logfile_defined
  1563. REM
  1564. REM Create a temporary file, to be deleted when the script finishes its execution.
  1565. REM The existence of the temporary file tells congeal.cmd that this script is still running.
  1566. REM Before the temporary file is deleted, its contents are appended to LOGFILE.
  1567. REM International builds define tmpfile based on language prior to calling the US build
  1568. REM rule script, so that multiple languages can run the same build rule script concurrently.
  1569. REM
  1570. REM Do not redefine tmpfile if already defined.
  1571. REM
  1572. if defined tmpfile goto tmpfile_defined
  1573. if not exist %tmp% md %tmp%
  1574. for %%i in (%script_name%) do (
  1575. set tmpfile=%tmp%\%%~ni.tmp
  1576. )
  1577. if exist %tmpfile% del /f %tmpfile%
  1578. :tmpfile_defined
  1579. set LOGFILE_BAK=%LOGFILE%
  1580. set LOGFILE=%tmpfile%
  1581. REM
  1582. REM Mark the beginning of script's execution.
  1583. REM
  1584. call logmsg.cmd /t "START %cmdline%"
  1585. REM
  1586. REM Execute the build rule option.
  1587. REM
  1588. call :BeginDeleteBuild
  1589. if errorlevel 1 (set /A ERRORS=%errorlevel%) else (set /A ERRORS=0)
  1590. REM
  1591. REM Mark the end of script's execution.
  1592. REM
  1593. call logmsg.cmd /t "END %cmdline% (%ERRORS% errors)"
  1594. set LOGFILE=%LOGFILE_BAK%
  1595. REM
  1596. REM Append the contents of tmpfile to logfile, then delete tmpfile.
  1597. REM
  1598. type %tmpfile% >> %LOGFILE%
  1599. del /f %tmpfile%
  1600. echo.& echo %script_name% : %ERRORS% errors : see %LOGFILE%.
  1601. if "%ERRORS%" == "0" goto end_main
  1602. goto errend_main
  1603. :end_main
  1604. endlocal
  1605. goto end
  1606. :errend_main
  1607. endlocal
  1608. goto errend
  1609. :ExecuteCmd
  1610. REM Do not use setlocal/endlocal:
  1611. REM for ex., if the command itself is "pushd",
  1612. REM a "popd" will be executed automatically at the end.
  1613. set cmd_bak=cmd
  1614. set cmd=%1
  1615. REM Remove the quotes
  1616. set cmd=%cmd:~1,-1%
  1617. if "%cmd%" == "" (
  1618. call errmsg.cmd "internal error: no parameters for ExecuteCmd %1."
  1619. set cmd=cmd_bak& goto errend
  1620. )
  1621. REM Run the command.
  1622. call logmsg.cmd "Running %cmd%."
  1623. %cmd%
  1624. if not "%errorlevel%" == "0" (
  1625. call errmsg.cmd "%cmd% failed."
  1626. set cmd=%cmd_bak%& goto errend
  1627. )
  1628. set cmd=cmd_bak
  1629. goto end
  1630. :errend
  1631. seterror.exe 1
  1632. goto :EOF
  1633. :end
  1634. seterror.exe 0
  1635. goto :EOF
  1636. REM END