Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions windows/build_windows_executable.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@ECHO OFF
PATH=C:\Program Files\Python313;C:\Program Files\Python313\Scripts;%PATH%
IF "%1"=="/INIT" GOTO InitializeEnvironment
PUSHD "%~dp0"

ECHO.
ECHO Checking current python.exe location(s)
where python.exe
where pip.exe
where pyinstaller.exe

ECHO.
ECHO Version info for Python/pip/pyinstaller:
Expand All @@ -14,37 +17,42 @@ pyinstaller.exe --version

ECHO.
ECHO Testing if current git-restore-mtime Python script works...
python.exe ..\git-restore-mtime --help
python.exe ..\git-restore-mtime --version

REM pyinstaller uses upx by default to compress the executable
REM When running the created executable this results in an error:
REM git-restore-mtime.exe - Bad Image: %TEMP%\VCRUNTIME140.dll
REM is either not designed to run on Windows or it contains an error (..)
REM Therefore run pyinstaller with the --noupx parameter
ECHO.
ECHO Running pyinstaller to create git-restore-mtime.exe...
pyinstaller.exe -F --noupx ..\git-restore-mtime

ECHO.
ECHO Testing if git-restore-mtime.exe works...
dist\git-restore-mtime.exe --help
dist\git-restore-mtime.exe --version

PAUSE
GOTO :EOF

:InitializeEnvironment
ECHO.
ECHO NOTE: This script needs to run as administrator
ECHO Press a key to install Chocolatey, Python and the required Python packages...
PAUSE

ECHO.
ECHO Installing/updating Chocolatey...
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass ^
-Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" ^
&& SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
REM Testing if batch file is running with elevated privileges
NET FILE 1>NUL 2>NUL
IF '%errorlevel%' == '0' (
ECHO Script %~dpfx0 is running with elevated privileges. Parameters: %1 %2 %3 %4 %5 %6 %7 %8 %9
) ELSE (
ECHO.
ECHO NOTE: This script needs to run as administrator, it will attempt to self elevate when necessary.
ECHO Press a key to use Microsoft winget to install Python and the required Python packages...
PAUSE
SETLOCAL EnableDelayedExpansion
GOTO :selfElevateBatchFile
)

REM Everything below here only runs if elevated privileges are available
ECHO.
ECHO Installing/updating Python...
choco.exe install -y python
winget install --exact --id Python.Python.3.13 --scope machine --force --accept-package-agreements

ECHO.
ECHO Upgrading pip and setuptools to latest version...
Expand All @@ -53,9 +61,20 @@ pip.exe install --upgrade --trusted-host pypi.org --trusted-host files.pythonhos
ECHO.
ECHO Installing latest version of pyinstaller...
pip.exe install --trusted-host pypi.org --trusted-host files.pythonhosted.org ^
https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz

ECHO.
ECHO Finished!
PAUSE
GOTO :EOF

:selfElevateBatchFile
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "%~dpfx0", "%1 %2 %3 %4 %5 %6 %7 %8 %9", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
REM Close the batch file; it will be restarted with elevated privileges
GOTO :EOF
1 change: 1 addition & 0 deletions windows/build_windows_executable_INIT.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@CALL "%~dp0build_windows_executable.bat" /INIT