build.bat 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. @echo off
  2. @echo Salt Windows Build Script, which calls the other *.ps1 scripts.
  3. @echo ---------------------------------------------------------------------
  4. @echo.
  5. :: To activate caching, set environment variables
  6. :: SALTREPO_LOCAL_CACHE for resources from saltstack.com/...
  7. :: SALT_REQ_LOCAL_CACHE for pip resources specified in req.txt
  8. :: SALT_PIP_LOCAL_CACHE for pip resources specified in req_pip.txt
  9. :: Make sure the script is run as Admin
  10. @echo Administrative permissions required. Detecting permissions...
  11. @echo ---------------------------------------------------------------------
  12. net session >nul 2>&1
  13. if %errorLevel%==0 (
  14. echo ...Success: Administrative permissions confirmed.
  15. ) else (
  16. echo ...Failure: This script must be run as Administrator
  17. goto eof
  18. )
  19. @echo =====================================================================
  20. @echo.
  21. @echo Git required. Detecting git...
  22. @echo ---------------------------------------------------------------------
  23. where git >nul 2>&1
  24. if %errorLevel%==0 (
  25. echo ...Success: Git found.
  26. ) else (
  27. echo ...Failure: This script needs to call git
  28. goto eof
  29. )
  30. @echo =====================================================================
  31. @echo.
  32. :: Get Passed Parameters
  33. @echo %0 :: Get Passed Parameters...
  34. @echo ---------------------------------------------------------------------
  35. set "Version="
  36. set "Python="
  37. :: First Parameter
  38. if not "%~1"=="" (
  39. echo.%1 | FIND /I "=" > nul && (
  40. :: Named Parameter
  41. echo Named Parameter
  42. set "%~1"
  43. ) || (
  44. :: Positional Parameter
  45. echo Positional Parameter
  46. set "Version=%~1"
  47. )
  48. )
  49. :: Second Parameter
  50. if not "%~2"=="" (
  51. echo.%2 | FIND /I "=" > nul && (
  52. :: Named Parameter
  53. set "%~2"
  54. ) || (
  55. :: Positional Parameter
  56. set "Python=%~2"
  57. )
  58. )
  59. :: If Version not defined, Get the version from Git
  60. if "%Version%"=="" (
  61. for /f "delims=" %%a in ('git describe') do @set "Version=%%a"
  62. )
  63. :: If Python not defined, Assume Python 2
  64. if "%Python%"=="" (
  65. set Python=2
  66. )
  67. :: Verify valid Python value (2 or 3)
  68. set "x="
  69. for /f "delims=23" %%i in ("%Python%") do set x=%%i
  70. if Defined x (
  71. echo Invalid Python Version specified. Must be 2 or 3. Passed %Python%
  72. goto eof
  73. )
  74. @echo =====================================================================
  75. @echo.
  76. :: Define Variables
  77. @echo %0 :: Defining Variables...
  78. @echo ---------------------------------------------------------------------
  79. if %Python%==2 (
  80. Set "PyDir=C:\Python27"
  81. ) else (
  82. Set "PyDir=C:\Python35"
  83. )
  84. Set "PATH=%PATH%;%PyDir%;%PyDir%\Scripts"
  85. Set "CurDir=%~dp0"
  86. for /f "delims=" %%a in ('git rev-parse --show-toplevel') do @set "SrcDir=%%a"
  87. @echo =====================================================================
  88. @echo.
  89. :: Create Build Environment
  90. @echo %0 :: Create the Build Environment...
  91. @echo ---------------------------------------------------------------------
  92. PowerShell.exe -ExecutionPolicy RemoteSigned -File "%CurDir%build_env_%Python%.ps1" -Silent
  93. if not %errorLevel%==0 (
  94. echo "%CurDir%build_env_%Python%.ps1" returned errorlevel %errorLevel%. Aborting %0
  95. goto eof
  96. )
  97. @echo.
  98. :: Remove build and dist directories
  99. @echo %0 :: Remove build and dist directories...
  100. @echo ---------------------------------------------------------------------
  101. "%PyDir%\python.exe" "%SrcDir%\setup.py" clean --all
  102. if not %errorLevel%==0 (
  103. goto eof
  104. )
  105. If Exist "%SrcDir%\dist" (
  106. @echo removing %SrcDir%\dist
  107. rd /S /Q "%SrcDir%\dist"
  108. )
  109. @echo.
  110. :: Install Current Version of salt
  111. @echo %0 :: Install Current Version of salt...
  112. @echo ---------------------------------------------------------------------
  113. "%PyDir%\python.exe" "%SrcDir%\setup.py" --quiet install --force
  114. if not %errorLevel%==0 (
  115. goto eof
  116. )
  117. @echo.
  118. :: Build the Salt Package
  119. @echo %0 :: Build the Salt Package...
  120. @echo ---------------------------------------------------------------------
  121. call "%CurDir%build_pkg.bat" "%Version%" %Python%
  122. @echo.
  123. :eof
  124. @echo.
  125. @echo =====================================================================
  126. @echo End of %0
  127. @echo =====================================================================