Counter Strike : Global Offensive Source Code
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.

141 lines
3.4 KiB

  1. :: //========== Copyright (c) Valve Corporation, All rights reserved. ========
  2. :: //
  3. :: // Script to install the .py output of a swig build. Handles p4 edit
  4. :: // and diffs file so only actual changes get checked in
  5. :: //
  6. :: // Could actually be used to p4 edit & copy with a diff any file to
  7. :: // a destination file
  8. :: //
  9. :: // NOTE: Expects to be installed in SRCDIR\vpc_scripts\swig_installcmd
  10. :: // as it derives the path to SRCDIR from the path to itself
  11. :: //
  12. :: // SYNTAX: swig_install.cmd <SRCFILE> <DSTFILE>
  13. :: //
  14. :: //=========================================================================
  15. @echo off
  16. setlocal
  17. :: // Make sure we have enough arguments
  18. if .%1. == .. goto Usage
  19. if .%2. == .. goto Usage
  20. set PREFIX=[%~n0]
  21. set SRCDIR=%~d0%~p0..
  22. set DIFF=%SRCDIR%\devtools\bin\diff.exe
  23. set SED=%SRCDIR%\devtools\bin\sed.exe
  24. set P4EDIT=%~d0%~p0valve_p4_edit.cmd
  25. set SRC=%~f1
  26. set DST=%~f2
  27. set DSTDIR=%~d2%~p2
  28. if NOT EXIST %DIFF% GOTO ErrorNoDiff
  29. if NOT EXIST %DIFF% GOTO ErrorNoSed
  30. if NOT EXIST %P4EDIT% GOTO ErrorNoP4Edit
  31. if NOT EXIST %SRC% GOTO ErrorNoSrc
  32. if EXIST %DSTDIR% GOTO DstDirOk
  33. MKDIR %DSTDIR%
  34. if ERRORLEVEL 1 GOTO ErrorDstDir
  35. :DstDirOk
  36. set bADD=0
  37. if NOT EXIST %DST% GOTO DoAdd
  38. echo %PREFIX% "%DIFF%" -q "%SRC%" "%DST%"
  39. ::
  40. :: This is horrible but Incredibuild seems to intercept ERRORLEVEL and for sub processes launched from batch files
  41. :: and flag them as RED which sucks... because they're not really errors. So do a wacky way to parse the output
  42. :: diff -q will return nothing if files are the same and 'Files A and B differ' if they are different
  43. :: So if there's no output, they are the same, if there's any output they are different
  44. ::
  45. :: The sed is there to simply clear ERRORLEVEL but echos all output untouched
  46. ::
  47. set sDIFFOUT=
  48. FOR /F "tokens=*" %%A in ( '%DIFF% -q %SRC% %DST% ^| %SED% -e ""' ) do SET sDIFFOUT=%%A
  49. if defined sDIFFOUT goto DoEdit
  50. :DoSame
  51. echo %PREFIX% Ok
  52. GOTO EndOk
  53. :DoAdd
  54. set bADD=1
  55. goto DoCopy
  56. :DoEdit
  57. echo %PREFIX% "%P4EDIT%" %DST% %SRCDIR%
  58. call "%P4EDIT%" %DST% %SRCDIR%
  59. IF ERRORLEVEL 1 goto ErrorP4Edit
  60. :DoCopy
  61. echo %PREFIX% COPY /Y "%SRC%" "%DST%"
  62. COPY /Y %SRC% %DST%
  63. IF ERRORLEVEL 1 goto ErrorCopy
  64. if %bADD%==0 goto EndOk
  65. echo %PREFIX% "%P4EDIT%" %DST% %SRCDIR%
  66. call "%P4EDIT%" %DST% %SRCDIR%
  67. IF ERRORLEVEL 1 goto ErrorP4Add
  68. :EndOk
  69. endlocal
  70. exit /b 0
  71. :Usage
  72. echo.
  73. echo NAME
  74. echo %~n0
  75. echo.
  76. echo SYNOPSIS
  77. echo %0 ^<SRCFILE^> ^<DSTFILE^>
  78. echo.
  79. echo DESCRIPTION
  80. echo Copies ^<SRCFILE^> to ^<DSTFILE^> opening it for p4 edit if necessary
  81. echo.
  82. echo NOTES
  83. echo Files are not automatically added to perforce, only files already
  84. echo controlled by perforce will be edited but no add operations are done
  85. echo.
  86. goto EndError
  87. :ErrorNoDiff
  88. echo %PREFIX% Error! No diff executable found here: %DIFF%
  89. goto EndError
  90. :ErrorNoSed
  91. echo %PREFIX% Error! No sed executable found here: %SED%
  92. goto EndError
  93. :ErrorNoP4Edit
  94. echo %PREFIX% Error! No valve_p4_edit.cmd found here: %P4EDIT%
  95. goto EndError
  96. :ErrorNoSrc
  97. echo %PREFIX% Error! No source file found: %SRC%
  98. goto EndError
  99. :ErrorDstDir
  100. echo %PREFIX% Error! Destination directory doesn't exist and could not be created: %DSTDIR%
  101. goto EndError
  102. :ErrorCopy
  103. echo %PREFIX% Error! Copy "%SRC%" "%DST%" failed
  104. goto EndError
  105. :ErrorP4Edit
  106. echo %PREFIX% Error! "%P4EDIT%" %DST% %SRCDIR% Failed
  107. goto EndError
  108. :ErrorP4Add
  109. echo %PREFIX% Error! "%P4EDIT%" %DST% %SRCDIR% Failed
  110. goto EndError
  111. :EndError
  112. endlocal
  113. exit 1