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.

358 lines
12 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM drivercab.cmd - BPerkins
  4. @REM generates driver.cab for each sku
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @if defined _CPCMAGIC goto CPCBegin
  10. @perl -x "%~f0" %*
  11. @goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use ParseArgs;
  18. sub Usage { print<<USAGE; exit(1) }
  19. drivercab [-l <language>]
  20. Generates driver.cab for each sku using *drivers.txt files generated by
  21. cddata from drvindex.inf.
  22. USAGE
  23. parseargs('?' => \&Usage);
  24. # *** TEMPLATE CODE ***
  25. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  26. __END__
  27. @:CPCBegin
  28. @set _CPCMAGIC=
  29. @setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  30. @if not defined DEBUG echo off
  31. @REM *** CMD SCRIPT BELOW ***
  32. REM
  33. REM drivercab.cmd
  34. REM
  35. REM this script will generate a driver.cab for each sku appropriate to this
  36. REM language. the files to be used are contained in drvindex.inf for each
  37. REM sku, which is read by cddata.cmd, and passed through txt files here.
  38. REM details:
  39. REM we are passed .txt lists for each sku, and then a file called
  40. REM commondrivers.txt for all common files. if the commondrivers.txt file
  41. REM exists, we can assume that we are not in incremental mode, as the idea
  42. REM of a common cab doesn't really make sense in an incremental environment.
  43. REM
  44. REM if commondrivers.txt does not exist, we will use cabinc.exe to add
  45. REM the changed files in each SKU to the appropriate driver.cab
  46. REM
  47. REM if perdrivers.txt does not exist, then there are no changes for per or
  48. REM alternately the per cab is equivalent to the common cab if not in
  49. REM incremental mode.
  50. REM
  51. REM setup
  52. REM
  53. REM get all appropriate products
  54. call logmsg.cmd "Calculating which products to act on ..."
  55. set Products=
  56. for %%a in (pro per bla sbs srv ads dtc) do (
  57. perl %RazzleToolPath%\cksku.pm -t:%%a -l:%lang% -a:%_BuildArch%
  58. if !ErrorLevel! == 0 (
  59. if not defined Products (
  60. set Products=%%a
  61. ) else (
  62. set Products=!Products! %%a
  63. )
  64. )
  65. )
  66. call logmsg.cmd "Checking for incremental mode ..."
  67. set IncMode=TRUE
  68. if exist %TMP%\commondrivers.txt set IncMode=
  69. REM set up the temp cab locations
  70. set TmpCabLocation=%_NTPOSTBLD%\cabs\driver\cabs
  71. if not exist %TmpCabLocation% md %TmpCabLocation%
  72. REM
  73. REM test for incremental mode
  74. REM
  75. if defined IncMode goto :PerformIncrementalCabbing
  76. goto :PerformFullCabbing
  77. REM
  78. REM PerformIncrementalCabbing
  79. REM
  80. REM here we just want to go through our product list, and use cabinc.exe
  81. REM to replace the old entries in driver.cab with the new ones.
  82. REM
  83. :PerformIncrementalCabbing
  84. call logmsg.cmd "Performing incremental cabbing ..."
  85. REM loop over products and cabinc the files in
  86. for %%a in (%Products%) do (
  87. REM the call to :SetMyInfDirName just sets the MyInfDirName env var to
  88. REM whatever the inf subdir for that product is, like for ads it is entinf
  89. set MyInfDirName=
  90. call :SetMyInfDirName %%a
  91. if not defined MyInfDirName (
  92. call errmsg.cmd "Invalid sku %%a found ..."
  93. )
  94. set MyDriverCab=%_NTPOSTBLD%\!MyInfDirName!\driver.cab
  95. if not exist !MyDriverCab! (
  96. call errmsg.cmd "Can't perform incremental updates without full cabs ..."
  97. goto :End
  98. )
  99. set MyFileList=%TMP%\%%adrivers.txt
  100. if not exist !MyFileList! (
  101. call logmsg.cmd "No files to change for %%a sku ..."
  102. ) else (
  103. call logmsg.cmd "Replacing files for %%a sku ..."
  104. set IncCommand=
  105. set NewFiles=
  106. for /f %%b in (!MyFileList!) do (
  107. set NewFile=%_NTPOSTBLD%\%%b
  108. for %%c in (!NewFile!) do set NewFileName=%%~nxc
  109. extract.exe -d !MyDriverCab! !NewFileName! | findstr /ic:"No matching files"
  110. if !ErrorLevel! NEQ 0 (
  111. REM this file was already in the cab, replace it
  112. set IncCommand=!IncCommand! !NewFile!
  113. ) else (
  114. REM this file is new to the cab, add it
  115. set NewFiles=!NewFiles! mergefile !NewFile!
  116. )
  117. )
  118. if defined IncCommand (
  119. call ExecuteCmd.cmd "cabinc.exe -t %NUMBER_OF_PROCESSORS% -q 40 -p 80 !MyDriverCab! !IncCommand!"
  120. if !ErrorLevel! NEQ 0 (
  121. call errmsg.cmd "Replace failed for %%a sku, file was !NewFile!,"
  122. call errmsg.cmd "cab file was !MyDriverCab! ..."
  123. ) else (
  124. call logmsg.cmd "!NewFileName! replaced in !MyDriverCab! ..."
  125. )
  126. )
  127. if defined NewFiles (
  128. call ExecuteCmd.cmd "cabbench.exe load !MyDriverCab! !NewFiles! save !MyDriverCab!.new"
  129. if !ErrorLevel! NEQ 0 (
  130. call errmsg.cmd "Add failed for %%a sku, file was !NewFile!,"
  131. call errmsg.cmd "cab file was !MyDriverCab! ..."
  132. ) else (
  133. call ExecuteCmd.cmd "del !MyDriverCab!"
  134. call ExecuteCmd.cmd "ren !MyDriverCab!.new driver.cab"
  135. call logmsg.cmd "!NewFileName! added to !MyDriverCab! ..."
  136. )
  137. )
  138. )
  139. )
  140. call logmsg.cmd "Finished."
  141. goto :End
  142. REM
  143. REM PerformFullCabbing
  144. REM
  145. REM here we want to break the common list into NUM_PROCS sublists, then
  146. REM multithread generation of those sub cabs. after that, we mash them all
  147. REM back together, and then multithread generation of the sku specific cabs.
  148. REM finally, we mash the sku specific cabs onto the common cab for each sku,
  149. REM and put those in the fooinf\driver.cab position.
  150. REM
  151. :PerformFullCabbing
  152. call logmsg.cmd "Performing full cabbing ..."
  153. REM
  154. REM first, do the common cab. we want to break the list down into NUM_PROCS
  155. REM lists, so we can thread them nicely
  156. REM
  157. call logmsg.cmd "Finding common drivers list ..."
  158. set CommonList=%TMP%\commondrivers.txt
  159. if not exist %CommonList% (
  160. call errmsg.cmd "Could not find %CommonList% to generate driver.cab ..."
  161. goto :End
  162. )
  163. set BackupName=%TMP%\backuplist.txt
  164. if exist %BackupName% del /f /q %BackupName%
  165. move %CommonList% %BackupName%
  166. if exist %CommonList%.* del /f /q %CommonList%.*
  167. move %BackupName% %CommonList%
  168. set /a NumLists=%NUMBER_OF_PROCESSORS%
  169. call logmsg.cmd "Splitting common drivers list into %NumLists% parts ..."
  170. perl %RazzleToolPath%\PostBuildScripts\splitlist.pl -n %NumLists% -f %CommonList% -l %lang%
  171. REM splitlist.pl creates commondrivers.txt.1, commondrivers.txt.2, etc
  172. set /a NumThreads=0
  173. for /l %%a in (1,1,%NumLists%) do (
  174. if exist %CommonList%.%%a set /a NumThreads=%%a
  175. )
  176. REM now NumThreads is the list count
  177. call logmsg.cmd "Created %NumThreads% sub lists ..."
  178. REM set the common cab name and location
  179. set CommonCab=%TmpCabLocation%\common.cab
  180. if exist %CommonCab% del /f %CommonCab%
  181. if exist %CommonCab% (
  182. call errmsg.cmd "Failed to delete old common cab ..."
  183. goto :End
  184. )
  185. REM
  186. REM now, we want to kick off our child processes and wait for them to finish.
  187. REM the wrapper script will generate the DDF from the list we pass it on the
  188. REM command line, in this case something like %TMP%\commondrivers.txt.1
  189. REM
  190. set EventList=
  191. for /l %%a in (1,1,%NumThreads%) do (
  192. call logmsg.cmd "Starting %CommonCab%.%%a cab ..."
  193. set EventName=commoncab%%a
  194. start "PB_CommonCab.%%a" /min cmd /c CabWrapper.cmd %CommonList%.%%a %CommonCab%.%%a !EventName!"
  195. set EventList=!EventList! !EventName!
  196. )
  197. if not defined EventList (
  198. REM hmmm?
  199. call errmsg.cmd "No events to wait on for common cabs ..."
  200. ) else (
  201. call logmsg.cmd "Waiting for common cabs ..."
  202. perl %RazzleToolPath%\PostBuildScripts\cmdevt.pl -iwv !EventList!
  203. )
  204. REM
  205. REM check if there were errors in the generation
  206. REM
  207. call logmsg.cmd "Checking for errors in sub cab generation ..."
  208. findstr /ic:"ERROR:" %LOGFILE% >nul 2>nul
  209. if %ErrorLevel% == 0 (
  210. REM we found some errors
  211. call errmsg.cmd "There were errors generating the sub cabs for driver.cab"
  212. call errmsg.cmd "Please investigate or run postbuild -full"
  213. goto :End
  214. )
  215. REM
  216. REM the common cab now needs to be merged together. we will use cabbench.exe
  217. REM to do this
  218. REM
  219. call logmsg.cmd "Merging common cab pieces back together ..."
  220. if %NumThreads% == 1 (
  221. REM only one cab, just rename it
  222. call logmsg.cmd "Only one common cab, renaming ..."
  223. move %TmpCabLocation%\common.cab.1 %CommonCab%
  224. ) else (
  225. REM multiple cabs, merge them
  226. set MergeCommand=load %TmpCabLocation%\common.cab.1
  227. for /l %%a in (2,1,%NumThreads%) do (
  228. set MergeCommand=!MergeCommand! load %TmpCabLocation%\common.cab.%%a merge
  229. )
  230. set MergeCommand=!MergeCommand! save %CommonCab%
  231. call logmsg.cmd "Issuing merge ..."
  232. call ExecuteCmd.cmd "cabbench.exe !MergeCommand!"
  233. if !ErrorLevel! NEQ 0 (
  234. call errmsg.cmd "Merge of common cab failed ..."
  235. goto :End
  236. )
  237. )
  238. if not exist %CommonCab% (
  239. call errmsg.cmd "Common cab does not exist at %CommonCab% after merge ..."
  240. goto :End
  241. )
  242. call logmsg.cmd "Merge successful, continuing ..."
  243. REM
  244. REM now, we get to create the sub cabs for each sku. just kick off as many
  245. REM threads as we need to do this, and give the short lists to the wrapper.
  246. REM the wrapper will handle creating the DDFs from the lists we pass it.
  247. REM
  248. call logmsg.cmd "Creating sku specific cabs ..."
  249. set EventList=
  250. for %%a in (%Products%) do (
  251. if not exist %TMP%\%%adrivers.txt (
  252. call logmsg.cmd "No drivers to cab for %%a sku ..."
  253. ) else (
  254. call logmsg.cmd "Starting generation for %%a specific drivers ..."
  255. set EventName=%%adrivercab
  256. REM syntax for CabWrapper.cmd is:
  257. REM list of files
  258. REM cab name to create
  259. REM event name to signal
  260. start "PB_%%adrivercab" /min cmd /c CabWrapper.cmd %TMP%\%%adrivers.txt %TmpCabLocation%\%%adriver.cab !EventName!
  261. set EventList=!EventList! !EventName!
  262. )
  263. )
  264. if not defined EventList (
  265. REM no events to wait for? okay ... whatever ...
  266. call logmsg.cmd "No sku specific cabs to wait for, continuing ..."
  267. ) else (
  268. call logmsg.cmd "Waiting for sku specific cabs to generate ..."
  269. perl %RazzleToolPath%\PostBuildScripts\cmdevt.pl -iwv %EventList%
  270. )
  271. REM
  272. REM now we have the common cab and the sku specific cabs, let's merge them
  273. REM into full sku particular driver.cab files
  274. REM
  275. for %%a in (%Products%) do (
  276. set MySkuCab=%_NTPOSTBLD%\%%ainf\driver.cab
  277. if /i "%%a" == "pro" set MySkuCab=%_NTPOSTBLD%\driver.cab
  278. if /i "%%a" == "ads" set MySkuCab=%_NTPOSTBLD%\entinf\driver.cab
  279. if not exist %TmpCabLocation%\%%adriver.cab (
  280. call logmsg.cmd "No %%a specific cab, copying common cab in place ..."
  281. copy %CommonCab% !MySkuCab!
  282. ) else (
  283. call logmsg.cmd "Merging %%a specific and common cabs ..."
  284. set MergeCommand=load %TmpCabLocation%\%%adriver.cab
  285. set MergeCommand=!MergeCommand! load %CommonCab%
  286. set MergeCommand=!MergeCommand! merge save !MySkuCab!
  287. call ExecuteCmd.cmd "cabbench.exe !MergeCommand!"
  288. if !ErrorLevel! NEQ 0 (
  289. call errmsg.cmd "Merge of %%a driver.cab failed ..."
  290. ) else (
  291. call logmsg.cmd "Merge of %%a driver.cab successful ..."
  292. )
  293. )
  294. )
  295. REM
  296. REM and we're done
  297. REM
  298. call logmsg.cmd "Finished."
  299. goto :End
  300. :SetMyInfDirName
  301. set SkuName=%1
  302. set MyInfDirName=
  303. if /i "%SkuName%" == "pro" set MyInfDirName=.
  304. if /i "%SkuName%" == "per" set MyInfDirName=perinf
  305. if /i "%SkuName%" == "bla" set MyInfDirName=blainf
  306. if /i "%SkuName%" == "sbs" set MyInfDirName=sbsinf
  307. if /i "%SkuName%" == "srv" set MyInfDirName=srvinf
  308. if /i "%SkuName%" == "ads" set MyInfDirName=entinf
  309. if /i "%SkuName%" == "dtc" set MyInfDirName=dtcinf
  310. goto :End
  311. :end
  312. if "%errors%" == "" set errors=0
  313. seterror.exe "%errors%"& goto :EOF