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.

248 lines
6.8 KiB

  1. @if "%_echo%"=="" echo off
  2. setlocal
  3. if "%1" == "-?" goto Usage
  4. if "%1" == "/?" goto Usage
  5. if "%1" == "-help" goto Usage
  6. if "%1" == "/help" goto Usage
  7. if "%BUILD_OFFLINE%"=="1" goto :eof
  8. set PUB=%_NTDRIVE%%_NTROOT%\public
  9. set _readme=%TEMP%\revert_public_readme.txt
  10. if exist %_readme% del /f %_readme%
  11. pushd %PUB%
  12. call :revert_public public %PUB%\publish.log %1
  13. for %%i in (*_CHANGENUM.SD) do (
  14. for /f "delims=_ tokens=1" %%j in ("%%i") do (
  15. @if /i "%%j" neq "public" (
  16. call :revert_public %%j %PUB%\%%j_publish.log %1
  17. )
  18. )
  19. )
  20. popd
  21. goto :eof
  22. :revert_public
  23. if exist %PUB%\%1_CHANGENUM.SD goto GotPubChangeNum
  24. echo %PUB%\public\%1_CHANGENUM.SD is missing - Open a new razzle window and retry
  25. goto :eof
  26. :GotPubChangeNum
  27. pushd %_NTDRIVE%%_NTROOT%\%1
  28. set PROJECT_BINDROP_DIR=
  29. if /I "%1" neq "public" (
  30. rem
  31. rem determine where published binaries are dropped.
  32. rem
  33. if not exist project.mk (
  34. echo No project.mk file in %CD% for project %1.
  35. popd
  36. goto :eof
  37. )
  38. for /f "tokens=1,2 delims==" %%b in (project.mk) do (
  39. if "%%b" equ "PROJECT_BINDROP_DIR" (
  40. set PROJECT_BINDROP_DIR=%%c
  41. )
  42. )
  43. if not defined PROJECT_BINDROP_DIR (
  44. echo Project.mk file in %CD% doesn't define PROJECT_BINDROP_DIR
  45. popd
  46. goto :eof
  47. )
  48. )
  49. @rem
  50. @rem we've already pushed into the project directory. just cd here and let the
  51. @rem pop at the end get us out.
  52. @rem
  53. cd %PROJECT_BINDROP_DIR%
  54. @rem
  55. @rem Check for old edit_public turds. Make sure they're handled before continueing.
  56. @rem
  57. set _publishfile=%2
  58. if exist %_publishfile%* (
  59. for %%x in (%_publishfile%_*) do (
  60. type %%x >> %_publishfile%
  61. del %%x
  62. )
  63. call edit_public.cmd
  64. )
  65. set _rwfiles=%TEMP%\revert_public_not_in_sd_%RANDOM%
  66. set _rwfiles2=%TEMP%\revert_public_not_in_sd2_%RANDOM%
  67. set _openedfiles=%TEMP%\revert_public_opened_in_other_changenum%RANDOM%
  68. set _missingfiles=%TEMP%\revert_public_missing_%RANDOM%
  69. set _missingfiles2=%TEMP%\revert_public_missing2_%RANDOM%
  70. for /f "tokens=2" %%i in (%PUB%\%1_CHANGENUM.SD) do (
  71. set __CHANGENUM=%%i
  72. )
  73. echo Reverting public changes (changenum: %__CHANGENUM%) in %CD%\...
  74. sd revert -c %__CHANGENUM% ...
  75. if %errorlevel% GEQ 1 echo.&&echo Error talking to SD depot - Try again later&&echo.&& goto Finished
  76. :DoSync
  77. if NOT "%3" == "-ForceSync" goto CheckForExtraRandomFiles
  78. shift
  79. sd sync -f ...
  80. if %errorlevel% GEQ 1 echo.&&echo Error talking to SD depot - Try again later&&echo.&& goto Finished
  81. :CheckForExtraRandomFiles
  82. echo Looking for other opened files...
  83. sd opened -l ... > %_openedfiles%
  84. if %errorlevel% GEQ 1 echo.&&echo Error talking to SD depot - Try again later&&echo.&& goto Finished
  85. if exist %_openedfiles% for /f "delims=#" %%i in (%_openedfiles%) do attrib +r %%i
  86. @rem Preserve files we don't want cleaned up by temporarily making them read-only.
  87. @rem only relevant for the src\public directory but it's benign for anything
  88. @rem else.
  89. if exist publish.log attrib +r publish.log
  90. if exist build_logs attrib +r build_logs\*.*
  91. dir /s/b/a-d-r > %_rwfiles%_1 2>nul
  92. for /f %%i in (%_rwfiles%_1) do echo %%i>> %_rwfiles%
  93. if exist %_rwfiles%_1 del %_rwfiles%_1
  94. if exist publish.log attrib -r publish.log
  95. del /s/q/a-r *
  96. if exist build_logs attrib -r build_logs\*.*
  97. :CheckForMissingFiles
  98. echo Update missing files...
  99. if exist %_openedfiles% for /f "delims=#" %%i in (%_openedfiles%) do attrib -r %%i
  100. if exist %_openedfiles% del /f %_openedfiles%
  101. for /f %%i in ('sd diff -sd ...') do (
  102. echo %%i>>%_missingfiles%
  103. )
  104. if exist %_missingfiles% sd -x %_missingfiles% sync -f
  105. @rem
  106. @rem O.K. We now have a list of r/w files that aren't previously edit'ed
  107. @rem And another list of files that are missing according to sd. Reconcile the differences
  108. @rem and print out the results.
  109. @rem
  110. @rem
  111. @rem no r/w files
  112. @rem
  113. if exist %_rwfiles% goto CheckMissingFiles
  114. if NOT exist %_missingfiles% goto Finished
  115. @rem
  116. @rem No r/w files - all the missing files must be legit warnings.
  117. @rem
  118. type %_missingfiles% > %_missingfiles2%
  119. goto PrintMissingFiles
  120. :CheckMissingFiles
  121. @rem
  122. @rem r/w files exist, do missing files?
  123. @rem
  124. if exist %_missingfiles% goto CheckMissingFiles2
  125. @rem
  126. @rem Nope. All r/w files must be legit warnings.
  127. @rem
  128. for /f %%i in (%_rwfiles%) do echo %%i>> %_rwfiles2%
  129. goto PrintMissingFiles
  130. @rem
  131. @rem Both r/w and missing files exist. See if there's any files in the r/w list
  132. @rem that are also in the missing list. These are files that for some reason
  133. @rem didn't get checked out. Any files on the r/w list that aren't in the missing list
  134. @rem are just mistakes.
  135. @rem
  136. :CheckMissingFiles2
  137. @rem
  138. @rem First make both files have lowercase names
  139. @rem
  140. set tempfile=%TEMP%\%RANDOM%
  141. perl -n -e "tr/A-Z/a-z/;print $_;" < %_rwfiles% > %tempfile%
  142. type %tempfile% > %_rwfiles%
  143. perl -n -e "tr/A-Z/a-z/;print $_;" < %_missingfiles% > %tempfile%
  144. type %tempfile% > %_missingfiles%
  145. del %tempfile%
  146. @rem
  147. @rem then find the intersections.
  148. @rem
  149. for /f %%i in ('findstr /l /g:%_rwfiles% /v %_missingfiles%') do echo %%i>> %_missingfiles2%
  150. for /f %%i in ('findstr /l /g:%_missingfiles% /v %_rwfiles%') do echo %%i>> %_rwfiles2%
  151. goto PrintMissingFiles
  152. :PrintMissingFiles
  153. if NOT exist %_rwfiles2% goto PrintMissingFiles2
  154. echo Warning: The following file(s) were not under source control.>>%_readme%
  155. echo If these files are new, make sure they're added asap.>>%_readme%
  156. if "%1" == "public" (
  157. echo If they shouldn't be in public, fix the build so they're not.>>%_readme%
  158. ) else (
  159. echo If they shouldn't be binary drops in %1, fix the build so they're not.>>%_readme%
  160. )
  161. echo ======================================================================>>%_readme%
  162. echo files under %CD%\... >>%_readme%
  163. type %_rwfiles2% >>%_readme%
  164. echo ======================================================================>>%_readme%
  165. :PrintMissingFiles2
  166. if NOT exist %_missingfiles2% goto Finished
  167. echo.>>%_readme%
  168. echo Warning: The following file(s) are in source control, but were missing>>%_readme%
  169. echo from your client. They have all been restored to the last sync'd version.>>%_readme%
  170. echo ======================================================================>>%_readme%
  171. type %_MissingFiles2% >>%_readme%
  172. echo ======================================================================>>%_readme%
  173. :Finished
  174. if exist %_openedfiles% del /f %_openedfiles%
  175. if exist %_missingfiles% del /f %_missingfiles%
  176. if exist %_missingfiles2% del /f %_missingfiles2%
  177. if exist %_rwfiles2% del /f %_rwfiles2%
  178. if exist %_rwfiles% del /f %_rwfiles%
  179. @rem
  180. @rem Back to whereever we started.
  181. @rem
  182. popd
  183. goto :eof
  184. :usage
  185. echo.
  186. echo This script will revert all the files checked out as a result of publishing to public.
  187. echo.
  188. echo Usually done as the first step of a clean build.
  189. echo.
  190. echo Usage: revert_public {-?} {-ForceSync}
  191. echo where:
  192. echo -? : prints this message
  193. echo -ForceSync : issue a sd sync -f ... cmd after reverting (to ensure all files are correct)
  194. echo.