win-standalone-build.cmd 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. set project=piccol
  4. set PATH=%PATH%;C:\WINDOWS;C:\WINDOWS\SYSTEM32
  5. for /D %%f in ( "%USERPROFILE%\AppData\Local\Programs\Python\Python*" ) do set PATH=!PATH!;%%f;%%f\Scripts
  6. set PATH=%PATH%;%ProgramFiles%\7-Zip
  7. cd ..
  8. if ERRORLEVEL 1 goto error_basedir
  9. call :detect_version
  10. set distdir=%project%-win64-standalone-%version%
  11. set sfxfile=%project%-win64-%version%.package.exe
  12. set bindirname=%project%-bin
  13. set bindir=%distdir%\%bindirname%
  14. set licensedirname=licenses
  15. set licensedir=%distdir%\%licensedirname%
  16. echo Building standalone Windows executable for %project% v%version%...
  17. echo.
  18. call :prepare_env
  19. call :build_cxfreeze
  20. call :copy_files
  21. call :gen_startup_wrapper
  22. call :make_archive
  23. echo ---
  24. echo finished
  25. pause
  26. exit /B 0
  27. :detect_version
  28. py -c "import re; print(re.match(r'.*^\s*PICCOL_VERSION\s*=\s*\"([\w\d\.\-_]+)\"\s*$.*', open('piccol').read(), re.DOTALL | re.MULTILINE).group(1))" > version.txt
  29. if ERRORLEVEL 1 goto error_version
  30. set /p version= < version.txt
  31. del version.txt
  32. exit /B 0
  33. :prepare_env
  34. echo === Preparing distribution environment
  35. rd /S /Q build 2>NUL
  36. rd /S /Q %distdir% 2>NUL
  37. del %sfxfile% 2>NUL
  38. timeout /T 2 /NOBREAK >NUL
  39. mkdir %distdir%
  40. if ERRORLEVEL 1 goto error_prep
  41. mkdir %bindir%
  42. if ERRORLEVEL 1 goto error_prep
  43. exit /B 0
  44. :build_cxfreeze
  45. echo === Creating the cx_Freeze distribution
  46. py setup.py build build_exe --build-exe=%bindir%
  47. if ERRORLEVEL 1 goto error_exe
  48. exit /B 0
  49. :copy_files
  50. echo === Copying additional files
  51. mkdir %licensedir%
  52. if ERRORLEVEL 1 goto error_copy
  53. copy README.* %distdir%\
  54. if ERRORLEVEL 1 goto error_copy
  55. copy foreign-licenses\*.txt %licensedir%\
  56. if ERRORLEVEL 1 goto error_copy
  57. copy COPYING %licensedir%\%project%-LICENSE.txt
  58. if ERRORLEVEL 1 goto error_copy
  59. exit /B 0
  60. :gen_startup_wrapper
  61. echo === Generating startup wrapper
  62. set wrapper=%distdir%\%project%.cmd
  63. echo @set PATH=%bindirname%;%bindirname%\lib;%%PATH%% > %wrapper%
  64. echo @start %bindirname%\%project%.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >> %wrapper%
  65. if ERRORLEVEL 1 goto error_wrapper
  66. exit /B 0
  67. :make_archive
  68. echo === Creating the distribution archive
  69. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  70. if ERRORLEVEL 1 goto error_7z
  71. exit /B 0
  72. :error_basedir
  73. echo FAILED to CD to base directory
  74. goto error
  75. :error_version
  76. echo FAILED to detect version
  77. goto error
  78. :error_prep
  79. echo FAILED to prepare environment
  80. goto error
  81. :error_exe
  82. echo FAILED to build exe
  83. goto error
  84. :error_copy
  85. echo FAILED to copy files
  86. goto error
  87. :error_wrapper
  88. echo FAILED to create wrapper
  89. goto error
  90. :error_7z
  91. echo FAILED to create archive
  92. goto error
  93. :error
  94. pause
  95. exit 1