Skip to content

Commit

Permalink
Invoke-Build powershell script that can create a .exe for Windows usi…
Browse files Browse the repository at this point in the history
…ng pyinstaller.
  • Loading branch information
KerstinKeller committed May 25, 2023
1 parent c4aeb6e commit a8f4101
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions python/ecal-foxglove-bridge.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
param(
$eCALVersion = '5.11.3', #
[ValidateSet('3.8', '3.9', '3.10', '3.11')]
[string]$PythonVersion = '3.11' # 3.8, 3.9, 3.10, 3.11
)

function eCALWheelName {
$PyVersion = $PythonVersion -replace '\.' , ''
$WheelName = "ecal5-" + $eCALVersion + "-cp" + $PyVersion + "-cp" + $PyVersion + "-win_amd64.whl"
return $WheelName
}

function DownloadeCALPythonWheel {
$WheelName = eCALWheelName
$eCALTagName = "v" + $eCALVersion
$DownloadCommand = "gh release download " + $eCALTagName + " -p " + $WheelName + " -R github.com/eclipse-ecal/ecal"
Write-Build Green $DownloadCommand
exec { Invoke-Expression $DownloadCommand }
}

function BuildDirName {
$BuildDirName = "_build_eCAL_$($eCALVersion)_python_$($PythonVersion)"
return $BuildDirName
}

function ChangeDirectory {
$BuildDir = BuildDirName
New-Item -ItemType Directory -Path .\$BuildDir
Set-Location -Path .\$BuildDir
}

# Synopsis: Create / Activate virtual environment
function ActivateEnvironment {
if ( -not (Test-Path '.venv' ) )
{
Write-Build Green 'Creating a virtual environment for the build'
exec { py -$PythonVersion -m venv .venv }
}
Write-Build Green 'Activating virtual environment'
.venv\Scripts\activate
}

function InstallRequirements {
Write-Build Green 'Installing Requirements'
exec { python --version }
exec { python -m pip install -r ..\requirements.txt }
DownloadeCALPythonWheel
$WheelName = eCALWheelName
exec { python -m pip install $WheelName }
exec { python -m pip install pyinstaller }
}

# Synopsis: Deactivate virtual environment
function DeactivateEnvironment {
exec { deactivate }
}

function BuildExe {
Write-Build Green 'Building the installer'
exec {pyinstaller ../ecal-foxglove-bridge.py --onefile}
}

task Build {
ChangeDirectory
ActivateEnvironment
InstallRequirements
BuildExe
DeactivateEnvironment
}

task . Build

0 comments on commit a8f4101

Please sign in to comment.