build.bat 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. @echo off
  2. @echo Salt Windows Build Script, which calls the other *.ps1 scripts.
  3. @echo ---------------------------------------------------------------------
  4. @echo.
  5. :: This script builds salt on any machine. It uses the following scripts:
  6. :: - build_env.ps1: Sets up a Python environment will all dependencies salt will
  7. :: will require
  8. :: - build_pkg.bat: Bundles the contents of the Python directory into a
  9. :: nullsoft installer binary
  10. :: The script first calls the `build_env.ps1` script to set up a python
  11. :: environment. Then it installs Salt into that python environment using Salt's
  12. :: `setup.py install` command. Finally, it runs the `build_pkg.bat` to create
  13. :: a NullSoft installer in the `installer` directory (pkg\windows\installer)
  14. :: This script accepts two parameters.
  15. :: Version: The version of Salt being built. If not passed, the version will
  16. :: determined using `git describe`. The leading `v` will be removed
  17. :: Python: The version of Python to build Salt on (Default is 3)
  18. :: These parameters can be passed positionally or as named parameters. Named
  19. :: parameters must be wrapped in quotes.
  20. :: Examples:
  21. :: # To build Salt 3000.3 on Python 3
  22. :: build.bat 3000.3
  23. :: build.bat 3000.3 3
  24. :: # Using named parameters
  25. :: build.bat "Version=3000.3"
  26. :: build.bat "Version=3000.3" "Python=3"
  27. :: # Using a mix
  28. :: build.bat 3000.3 "Python=3"
  29. :: To activate caching, set environment variables
  30. :: SALTREPO_LOCAL_CACHE for resources from saltstack.com/...
  31. :: SALT_REQ_LOCAL_CACHE for pip resources specified in req.txt
  32. :: SALT_PIP_LOCAL_CACHE for pip resources specified in req_pip.txt
  33. :: Make sure the script is run as Admin
  34. @echo Administrative permissions required. Detecting permissions...
  35. @echo ---------------------------------------------------------------------
  36. net session >nul 2>&1
  37. if %errorLevel%==0 (
  38. echo ...Success: Administrative permissions confirmed.
  39. ) else (
  40. echo ...Failure: This script must be run as Administrator
  41. goto eof
  42. )
  43. @echo =====================================================================
  44. @echo.
  45. @echo Git required. Detecting git...
  46. @echo ---------------------------------------------------------------------
  47. where git >nul 2>&1
  48. if %errorLevel%==0 (
  49. echo ...Success: Git found.
  50. ) else (
  51. echo ...Failure: This script needs to call git
  52. goto eof
  53. )
  54. @echo =====================================================================
  55. @echo.
  56. :: Get Passed Parameters
  57. @echo %0 :: Get Passed Parameters...
  58. @echo ---------------------------------------------------------------------
  59. set "Version="
  60. set "Python="
  61. :: First Parameter
  62. if not "%~1"=="" (
  63. echo.%1 | FIND /I "=" > nul && (
  64. :: Named Parameter
  65. echo Named Parameter
  66. set "%~1"
  67. ) || (
  68. :: Positional Parameter
  69. echo Positional Parameter
  70. set "Version=%~1"
  71. )
  72. )
  73. :: Second Parameter
  74. if not "%~2"=="" (
  75. echo.%2 | FIND /I "=" > nul && (
  76. :: Named Parameter
  77. set "%~2"
  78. ) || (
  79. :: Positional Parameter
  80. set "Python=%~2"
  81. )
  82. )
  83. :: If Version not defined, Get the version from Git
  84. set git=0
  85. if "%Version%"=="" (
  86. echo Getting version from git
  87. for /f "delims=" %%a in ('git describe') do @set "Version=%%a"
  88. set git=1
  89. )
  90. :: Strip off the leading `v` when getting version from git describe
  91. if %git%==1 set Version=%Version:~1%
  92. :: If Python not defined, Assume Python 3
  93. if "%Python%"=="" (
  94. set Python=3
  95. )
  96. :: Verify valid Python value (3)
  97. :: We may need to add Python 4 in the future (delims=34)
  98. set "x="
  99. for /f "delims=3" %%i in ("%Python%") do set x=%%i
  100. if Defined x (
  101. echo Invalid Python Version specified. Must be 3. Passed %Python%
  102. goto eof
  103. )
  104. @echo =====================================================================
  105. @echo.
  106. :: Define Variables
  107. @echo %0 :: Defining Variables...
  108. @echo ---------------------------------------------------------------------
  109. if %Python%==3 (
  110. Set "PyDir=C:\Python37"
  111. Set "PyVerMajor=3"
  112. Set "PyVerMinor=7"
  113. ) else (
  114. :: Placeholder for future version
  115. :: Set "PyDir=C:\Python4"
  116. )
  117. Set "PATH=%PATH%;%PyDir%;%PyDir%\Scripts"
  118. Set "CurDir=%~dp0"
  119. for /f "delims=" %%a in ('git rev-parse --show-toplevel') do @set "SrcDir=%%a"
  120. @echo =====================================================================
  121. @echo.
  122. :: Create Build Environment
  123. @echo %0 :: Create the Build Environment...
  124. @echo ---------------------------------------------------------------------
  125. PowerShell.exe -ExecutionPolicy RemoteSigned -File "%CurDir%build_env.ps1" -Silent
  126. if not %errorLevel%==0 (
  127. echo "%CurDir%build_env.ps1" returned errorlevel %errorLevel%. Aborting %0
  128. goto eof
  129. )
  130. @echo.
  131. :: Remove build and dist directories
  132. @echo %0 :: Remove build and dist directories...
  133. @echo ---------------------------------------------------------------------
  134. "%PyDir%\python.exe" "%SrcDir%\setup.py" clean --all
  135. if not %errorLevel%==0 (
  136. goto eof
  137. )
  138. If Exist "%SrcDir%\dist" (
  139. @echo removing %SrcDir%\dist
  140. rd /S /Q "%SrcDir%\dist"
  141. )
  142. @echo.
  143. :: Install Current Version of salt
  144. @echo %0 :: Install Current Version of salt...
  145. @echo ---------------------------------------------------------------------
  146. "%PyDir%\python.exe" "%SrcDir%\setup.py" --quiet install --force
  147. if not %errorLevel%==0 (
  148. goto eof
  149. )
  150. @echo.
  151. :: Build the Salt Package
  152. @echo %0 :: Build the Salt Package...
  153. @echo ---------------------------------------------------------------------
  154. call "%CurDir%build_pkg.bat" "%Version%" "%Python%"
  155. @echo.
  156. :eof
  157. @echo.
  158. @echo =====================================================================
  159. @echo End of %0
  160. @echo =====================================================================