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.

348 lines
12 KiB

  1. REM
  2. REM things to do before chekin
  3. REM (1) add header
  4. REM (2) remove REM about delete temporary directory
  5. REM (3) change myMove to move
  6. REM
  7. setlocal ENABLEDELAYEDEXPANSION
  8. if "%1" == "" (
  9. set AsmRoot=%_NTPOSTBLD%
  10. ) else (
  11. set AsmRoot=%1
  12. )
  13. set myMOVE=copy
  14. set NumOfNextNewAsmsCab=
  15. set AsmCabinetStore=
  16. call :PrepareBaseAssemblyCabinet
  17. set NewAsmsCabinet=asms%NumOfNextNewAsmsCab%.cab
  18. call :CreateNewCabinet
  19. if "!errorlevel!"=="1" (
  20. call errmsg.cmd "Failed to apply create the Cabinet for assemblies under asms tree"
  21. goto :cleanup
  22. )
  23. :cleanup
  24. REM remove the directory for all old asms.cab
  25. REM if not "%AsmCabinetStore%" == "" @rmdir /s /q %AsmCabinetStore%
  26. REM
  27. REM remove the directory where we try to create the cabinet
  28. REM
  29. REM if not "%NewAssemblyCabinetDir%"=="" @rmdir /s /q %NewAssemblyCabinetDir%
  30. goto :Eof
  31. REM main function End }
  32. REM Sub Function PrepareBaseAssemblyCabinet Begin {
  33. REM Function:
  34. REM create the cabinet from this directory, each subdir would be a folder in the cabinet
  35. REM rename this cabinet as asms_n.cab
  36. REM move this cabinet into asms
  37. REM remove the directory
  38. :PrepareBaseAssemblyCabinet
  39. if not exist %AsmRoot%\asms.cab goto :Eof
  40. REM
  41. REM create a tempDir and extrace cab files from %AsmRoot% to it
  42. REM Directory name used in CABARC.cmd MUST has a backslash at the end
  43. REM
  44. set AsmCabinetStore=%TEMP%\%random%\
  45. if exist %AsmCabinetStore% (
  46. call ExecuteCmd.cmd "rmdir /s /q %%AsmCabinetStore%%"
  47. if "!errorlevel!"=="1" (
  48. call logmsg.cmd "Failed to create temporary directory for %%AsmCabinetStore%%"
  49. goto :Eof
  50. )
  51. )
  52. call ExecuteCmd.cmd "mkdir %%AsmCabinetStore%%"
  53. if "!errorlevel!"=="1" (
  54. call logmsg.cmd "Failed to create temporary directory %%AsmCabinetStore%% for cabinets"
  55. goto :EOF
  56. )
  57. REM
  58. REM extrace asms.cab which is the base cabinet for all
  59. REM
  60. call ExecuteCmd.cmd "cabarc.exe -p x %%AsmRoot%%\asms.cab %%AsmCabinetStore%%"
  61. if "!errorlevel!"=="1" (
  62. call errmsg.cmd "Failed to extract the assembly cabinet %%i"
  63. goto :EOF
  64. )
  65. REM
  66. REM there are other asms.cab avaiable and need extract them
  67. REM
  68. for /L %%i in (1,1,100) do (
  69. set CurrentAsmCabinet=%AsmRoot%\asms%%i.cab
  70. REM
  71. REM if no more asms cabinet, exit the loop
  72. REM
  73. if not exist !CurrentAsmCabinet! (
  74. set NumOfNextNewAsmsCab=%%i
  75. goto :Eof
  76. )
  77. REM
  78. REM extrace thd cabinet into the Cabinet temporary directory
  79. REM
  80. call ExecuteCmd.cmd "cabarc.exe -p x %%CurrentAsmCabinet%% %%AsmCabinetStore%%"
  81. if "!errorlevel!"=="1" (
  82. call errmsg.cmd "Failed to extract the assembly cabinet %%i"
  83. goto :EOF
  84. )
  85. call :ApplyPatchToAssemblyCabinet
  86. )
  87. goto :Eof
  88. REM sub function PrepareBaseAssemblyCabinet End }
  89. REM sub function start {
  90. :ApplyPatchToAssemblyCabinet
  91. REM
  92. REM the reason to put patch-apply inside of the loop is to guarrantee the sequence of patches
  93. REM could be applied
  94. REM
  95. REM if there exists patches, apply patch based on base
  96. REM
  97. set OneAssemblyPatchFile=
  98. for /F %%I in ('dir /s/b %AsmCabinetStore%\assembly.patch') do (
  99. set OneAssemblyPatchFile=%%I
  100. goto :FindPatchInAssembly
  101. )
  102. if not "!OneAssemblyPatchFile!" == "" (
  103. :FindPatchInAssembly
  104. for /F %%I in ('dir /s /b %%AsmCabinetStore%%assembly.patch') do (
  105. set OneAssemblyPatchFile=%%I
  106. for /F %%w in ('type %%OneAssemblyPatchFile%%') do set AssemblyIdentityAttribute=%%w
  107. set AssemblyIdentityAttribute=!AssemblyIdentityAttribute:"=\"!
  108. call logmsg.cmd "xiaoyu : AssemblyIdentityAttribute is %%AssemblyIdentityAttribute%%"
  109. for /F %%w in ('sxs_GetAsmDir.exe -AsmIdToAsmDir %%AssemblyIdentityAttribute%%') do set BaseAssemblyDirectory=%%w
  110. call logmsg.cmd "xiaoyu : BaseAssemblyDirectory is %%BaseAssemblyDirectory%%"
  111. set PatchedAssemblyDir=%%~dpI
  112. REM
  113. REM for each .patch in the directory, apply patch
  114. REM
  115. for /F %%w in ('dir /s /b %%PatchedAssemblyDir%%*.patch') do (
  116. if /i "%%~nxw" neq "assembly.patch" (
  117. REM
  118. REM get the real filename by remove the ending extension ".patch"
  119. REM
  120. set PatchFileName=%%w
  121. set DllFileName=%%~nxw
  122. set DllFileName=!DllFileName:.patch=!
  123. set BaseDllFileName=%AsmCabinetStore%!BaseAssemblyDirectory!\!DllFileName!
  124. set TargetDllFileName=%%~pdw!DllFileName!
  125. echo xiaoyu : BaseDllFileName is !BaseDllFileName!, TargetDllFileName is !TargetDllFileName!
  126. REM
  127. REM wpatch.exe PatchFile BaseFile TargetFile
  128. REM
  129. call ExecuteCmd.cmd "wpatch.exe %%PatchFileName%% %%BaseDllFileName%% %%TargetDllFileName%%"
  130. if "!errorlevel!"=="1" (
  131. call errmsg.cmd "Failed to apply patch %%w to %%i %%BaseDllFileName%%"
  132. goto :EOF
  133. )
  134. REM
  135. REM remove the xxx.dll.patch after apply it
  136. REM
  137. call ExecuteCmd.cmd "del %%w"
  138. )
  139. )
  140. REM
  141. REM remove assembly.patch
  142. REM
  143. call ExecuteCmd.cmd "del %%I"
  144. )
  145. )
  146. goto :Eof
  147. REM }
  148. REM sub Function CreateNewCabinet Begin {
  149. REM Function Description:
  150. REM create a directory
  151. REM for assemblies in asms(
  152. REM create a temporary directory to put files
  153. REM for each assembly(
  154. REM create x86_name_xxxx_hash directory under the cabinet directory
  155. REM locate its baseAssembly
  156. REM for all the files of this assembly (
  157. REM if it is a manifest, or a catalog,
  158. REM put it into the cabinet directory
  159. REM else if it is a brand new file (not exist in the BaseAssembly)
  160. REM put it into the cabinet directory
  161. REM else
  162. REM make a patch based on BaseAssemblyDll
  163. REM put the patch into the directory
  164. REM )
  165. REM )
  166. REM )
  167. :CreateNewCabinet
  168. set NewAssemblyCabinetDir=%TEMP%\%random%
  169. if exist %NewAssemblyCabinetDir% rmdir /s /q %NewAssemblyCabinetDir%
  170. call ExecuteCmd.cmd "mkdir %%NewAssemblyCabinetDir%%"
  171. set NewAssemblyList=%NewAssemblyCabinetDir%\Assemblies.List
  172. @dir /s /b %AsmRoot%\asms\*.man > %NewAssemblyList%
  173. REM
  174. REM prepare cabarc.cmd line
  175. REM
  176. set CreateAsmCabinetCmd=cabarc.exe -p n %AsmRoot%\asms%NumOfNextNewAsmsCab%.cab
  177. set IsFirstFolderInCabinetCreated=0
  178. for /F %%f in (%NewAssemblyList%) do (
  179. set CurrentAssemblyPath=%%~dpf
  180. REM
  181. REM create one directory for an assembly
  182. REM
  183. for /F %%I in ('sxs_GetAsmDir.exe -manifestToAsmDir %%f') do set AssemblyFolder=%%I
  184. if "!AssemblyFolder!" == "" (
  185. call errmsg.cmd "AssemblyFolder generated is wrong\n";
  186. goto :Eof
  187. )
  188. if "!errorlevel!" == "1" (
  189. call errmsg.cmd "sxs_GetAsmDir.exe -manifest %%f failed!"
  190. goto :Eof
  191. )
  192. call ExecuteCmd.cmd "mkdir %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%"
  193. if "!errorlevel!" == "1" (
  194. call errmsg.cmd "create directory %%NewAssemblyCabinetDir%%\%%AssemblyFolder%% failed"
  195. goto :Eof
  196. )
  197. call :GeneratePatchForOneAssembly
  198. if "!IsFirstFolderInCabinetCreated!"=="1" (
  199. set CreateAsmCabinetCmd=!CreateAsmCabinetCmd! +
  200. ) else (
  201. set IsFirstFolderInCabinetCreated=1
  202. )
  203. set CreateAsmCabinetCmd=!CreateAsmCabinetCmd! !AssemblyFolder!\*.*
  204. call logmsg.cmd "CreateAsmCabinetCmd is %%CreateAsmCabinetCmd%%"
  205. )
  206. REM
  207. REM time to create a cabinet
  208. REM
  209. pushd %NewAssemblyCabinetDir%\
  210. call ExecuteCmd.cmd "%%CreateAsmCabinetCmd%%"
  211. set error = !errorlevel!
  212. popd
  213. if "%error%"=="1" (
  214. call errmsg.cmd "Failed to create Cabinet for assemblies under asms tree"
  215. goto :EOF
  216. )
  217. REM
  218. REM nuke %AsmRoot%asms and make it empty: we want to keep this dir in the build anyway
  219. REM
  220. REM @cd /d %AsmRoot%asms
  221. REM @rmdir /s /q .
  222. goto :Eof
  223. REM sub Function CreateNewCabinet End}
  224. REM sub Function GeneratePatchForOneAssembly Start{
  225. :GeneratePatchForOneAssembly
  226. set BaseAssembly=
  227. REM
  228. REM find the possible Base Assembly from CabinetStore
  229. REM
  230. REM First Step: try to find base assembly with the same laguage ID
  231. REM
  232. if not "!AsmCabinetStore!" == "" (
  233. for /F "tokens=1-6 delims=_" %%I in ('echo %%AssemblyFolder%%') do set PossibleBaseAssembly=%%I_%%J_%%K_*_%%M_*
  234. for /F %%I in ('dir /b /ad /o-n %%AsmCabinetStore%%%%PossibleBaseAssembly%%') do (
  235. set BaseAssembly=%AsmCabinetStore%%%I
  236. goto :FoundBaseAssembly
  237. )
  238. REM
  239. REM Second Step: try to find base assembly with whatever laguage ID
  240. REM
  241. for /F "tokens=1-6 delims=_" %%I in ('echo %%AssemblyFolder%%') do set PossibleBaseAssmelby=%%I_%%J_%%K_*
  242. for /F %%I in ('dir /b /ad /o-n %%PossibleBaseAssembly%%') do (
  243. set BaseAssembly=%AsmCabinetStore%%%I
  244. goto :FoundBaseAssembly
  245. )
  246. )
  247. :FoundBaseAssembly
  248. call logmsg.cmd "xiaoyu : BaseAssembly is %%BaseAssembly%%"
  249. REM
  250. REM for all files of this assembly, move it or its patch to the directory %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%
  251. REM
  252. for /F %%I in ('dir /s /b %%CurrentAssemblyPath%%*.*') do (
  253. REM
  254. REM for .man and .cat file, move it
  255. REM
  256. if /i "%%~xI" equ ".man" (
  257. call ExecuteCmd.Cmd "%%myMove%% %%I %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%"
  258. ) else (
  259. if /i "%%~xI" equ ".cat" (
  260. call ExecuteCmd.Cmd "%%myMove%% %%I %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%"
  261. ) else (
  262. if "%BaseAssembly%" == "" (
  263. REM
  264. REM no BaseAssembly, just copy the file
  265. REM
  266. call ExecuteCmd.Cmd "%%myMove%% %%I %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%"
  267. ) else (
  268. REM
  269. REM create patch on BaseAssembly files
  270. REM
  271. set BaseAssemblyFile=%BaseAssembly%\%%~nxI
  272. if exist %BaseAssemblyFile%. (
  273. REM
  274. REM create patch based on it
  275. REM
  276. set PatchFileName=%NewAssemblyCabinetDir%\%AssemblyFolder%\%%~nxI.patch
  277. call ExecuteCmd.cmd "mpatch.exe -NOCOMPARE -NOSYMS -NOPROGRESS -FAILBIGGER %%BaseAssemblyFile%% %%I %%PatchFileName%%"
  278. if "!errorlevel!"=="1" (
  279. call ExecuteCmd.Cmd "%%myMove%% %%I %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%"
  280. ) else (
  281. REM
  282. REM generate assembly.patch
  283. REM
  284. if not exist %NewAssemblyCabinetDir%\%AssemblyFolder%\assembly.patch (
  285. for /F %%I in ('dir /s/b %%BaseAssembly%%\*.man*') do set BaseManifestFileName=%%I
  286. for /F %%I in ('sxs_GetAsmDir.exe -manifestToAsmID %%BaseManifestFileName%%') do echo %%I > %NewAssemblyCabinetDir%\%AssemblyFolder%\assembly.patch
  287. )
  288. )
  289. ) else (
  290. REM
  291. REM new file in assembly
  292. REM
  293. call ExecuteCmd.Cmd "%%myMove%% %%PatchFileName%% %%NewAssemblyCabinetDir%%\%%AssemblyFolder%%"
  294. )
  295. )
  296. )
  297. )
  298. )
  299. goto :Eof
  300. REM sub Function GeneratePatchForOneAssembly ends}
  301. goto :Eof