win-standalone-build.cmd 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. set project=pwman
  4. set PATH=%PATH%;C:\WINDOWS;C:\WINDOWS\SYSTEM32
  5. for /D %%f in ( "C:\PYTHON*" ) do set PATH=!PATH!;%%f
  6. for /D %%f in ( "%USERPROFILE%\AppData\Local\Programs\Python\Python*" ) do set PATH=!PATH!;%%f;%%f\Scripts
  7. set PATH=%PATH%;%ProgramFiles%\7-Zip
  8. cd ..
  9. if ERRORLEVEL 1 goto error_basedir
  10. call :detect_version
  11. if "%PROCESSOR_ARCHITECTURE%" == "x86" (
  12. set winprefix=win32
  13. ) else (
  14. set winprefix=win64
  15. )
  16. set distdir=%project%-%winprefix%-standalone-%version%
  17. set sfxfile=%project%-%winprefix%-%version%.package.exe
  18. set bindirname=%project%-bin
  19. set bindir=%distdir%\%bindirname%
  20. set builddir=%bindir%\build
  21. set licensedirname=licenses
  22. set licensedir=%distdir%\%licensedirname%
  23. echo Building standalone Windows executable for %project%-%version%
  24. call :prepare_env
  25. call :build_cxfreeze
  26. call :build_doc
  27. call :copy_files
  28. call :gen_startup_wrapper
  29. call :make_archive
  30. echo ---
  31. echo finished
  32. pause
  33. exit /B 0
  34. :detect_version
  35. py -c "import libpwman; print(libpwman.__version__)" > version.txt
  36. if ERRORLEVEL 1 goto error_version
  37. set /p version= < version.txt
  38. del version.txt
  39. exit /B 0
  40. :prepare_env
  41. echo === Preparing distribution environment
  42. rd /S /Q build 2>NUL
  43. rd /S /Q %distdir% 2>NUL
  44. del %sfxfile% 2>NUL
  45. timeout /T 2 /NOBREAK >NUL
  46. mkdir %distdir%
  47. if ERRORLEVEL 1 goto error_prep
  48. mkdir %bindir%
  49. if ERRORLEVEL 1 goto error_prep
  50. exit /B 0
  51. :build_cxfreeze
  52. echo === Creating the cx_Freeze distribution
  53. py setup.py ^
  54. build ^
  55. --build-base=%builddir% ^
  56. build_exe ^
  57. --build-exe=%bindir%
  58. if ERRORLEVEL 1 goto error_exe
  59. exit /B 0
  60. :build_doc
  61. for %%i in (*.rst) do (
  62. echo Generating %%~ni.html from %%i ...
  63. py -m readme_renderer -o %%~ni.html %%i
  64. if ERRORLEVEL 1 goto error_doc
  65. )
  66. exit /B 0
  67. :copy_files
  68. echo === Copying additional files
  69. mkdir %licensedir%
  70. if ERRORLEVEL 1 goto error_copy
  71. copy *.html %distdir%\
  72. if ERRORLEVEL 1 goto error_copy
  73. copy examplescript.py %distdir%\
  74. if ERRORLEVEL 1 goto error_copy
  75. xcopy /E /I doc %distdir%\doc
  76. if ERRORLEVEL 1 goto error_copy
  77. rmdir /S /Q %distdir%\doc\foreign-licenses
  78. if ERRORLEVEL 1 goto error_copy
  79. copy doc\foreign-licenses\*.txt %licensedir%\
  80. if ERRORLEVEL 1 goto error_copy
  81. copy COPYING %licensedir%\PWMAN-LICENSE.txt
  82. if ERRORLEVEL 1 goto error_copy
  83. rd /S /Q %builddir%
  84. if ERRORLEVEL 1 goto error_copy
  85. exit /B 0
  86. :gen_startup_wrapper
  87. echo === Generating startup wrapper
  88. set wrapper=%distdir%\%project%.cmd
  89. echo @set PATH=%bindirname%;%bindirname%\lib;%bindirname%\platforms;%bindirname%\imageformats;%%PATH%% > %wrapper%
  90. echo @start %project%-bin\pwman.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >> %wrapper%
  91. if ERRORLEVEL 1 goto error_wrapper
  92. exit /B 0
  93. :make_archive
  94. echo === Creating the distribution archive
  95. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  96. if ERRORLEVEL 1 goto error_7z
  97. exit /B 0
  98. :error_basedir
  99. echo FAILED to CD to base directory
  100. goto error
  101. :error_version
  102. echo FAILED to detect version
  103. goto error
  104. :error_prep
  105. echo FAILED to prepare environment
  106. goto error
  107. :error_exe
  108. echo FAILED to build exe
  109. goto error
  110. :error_doc
  111. echo FAILED to build doc
  112. goto error
  113. :error_copy
  114. echo FAILED to copy files
  115. goto error
  116. :error_wrapper
  117. echo FAILED to create wrapper
  118. goto error
  119. :error_7z
  120. echo FAILED to create archive
  121. goto error
  122. :error
  123. pause
  124. exit 1