salt/pkg/windows/build.ps1
2022-12-16 11:03:06 -07:00

183 lines
5.4 KiB
PowerShell

<#
.SYNOPSIS
Parent script that runs all other scripts required to build Salt
.DESCRIPTION
This script Cleans, Installs Dependencies, Builds Python, Installs Salt,
and builds the NullSoft Installer. It depends on the following Scripts
and are called in this order:
- clean_env.ps1
- install_nsis.ps1
- build_python.ps1
- install_salt.ps1
- build_pkg.ps1
.EXAMPLE
build.ps1
.EXAMPLE
build.ps1 -Version 3005 -PythonVersion 3.8.13
#>
param(
[Parameter(Mandatory=$false)]
[Alias("v")]
# The version of Salt to be built. If this is not passed, the script will
# attempt to get it from the git describe command on the Salt source
# repo
[String] $Version,
[Parameter(Mandatory=$false)]
[ValidateSet("x86", "x64")]
[Alias("a")]
# The System Architecture to build. "x86" will build a 32-bit installer.
# "x64" will build a 64-bit installer. Default is: x64
$Architecture = "x64",
[Parameter(Mandatory=$false)]
[ValidatePattern("^\d{1,2}.\d{1,2}.\d{1,2}$")]
[ValidateSet(
# Until Pythonnet supports newer versions
#"3.10.5",
#"3.10.4",
#"3.10.3",
#"3.9.13",
#"3.9.12",
#"3.9.11",
"3.8.16",
"3.8.15",
"3.8.14",
"3.8.13",
"3.8.12",
"3.8.11",
"3.8.10"
)]
[Alias("p")]
# The version of Python to be built. Pythonnet only supports up to Python
# 3.8 for now. Pycurl stopped building wheel files after 7.43.0.5 which
# supported up to 3.8. So we're pinned to the latest version of Python 3.8.
# We may have to drop support for pycurl.
# Default is: 3.8.16
[String] $PythonVersion = "3.8.16",
[Parameter(Mandatory=$false)]
[Alias("b")]
# Build python from source instead of fetching a tarball
# Requires VC Build Tools
[Switch] $Build
)
# Script Preferences
$ProgressPreference = "SilentlyContinue"
$ErrorActionPreference = "Stop"
#-------------------------------------------------------------------------------
# Variables
#-------------------------------------------------------------------------------
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$PROJECT_DIR = $(git rev-parse --show-toplevel)
$SALT_SRC_DIR = "$( (Get-Item $PROJECT_DIR).Parent.FullName )\salt"
#-------------------------------------------------------------------------------
# Verify Salt and Version
#-------------------------------------------------------------------------------
if ( [String]::IsNullOrEmpty($Version) ) {
if ( ! (Test-Path -Path $SALT_SRC_DIR) ) {
Write-Host "Missing Salt Source Directory: $SALT_SRC_DIR"
exit 1
}
Push-Location $SALT_SRC_DIR
$Version = $( git describe )
$Version = $Version.Trim("v")
Pop-Location
if ( [String]::IsNullOrEmpty($Version) ) {
Write-Host "Failed to get version from $SALT_SRC_DIR"
exit 1
}
}
#-------------------------------------------------------------------------------
# Start the Script
#-------------------------------------------------------------------------------
Write-Host $("#" * 80)
Write-Host "Build Salt Installer Packages" -ForegroundColor Cyan
Write-Host "- Salt Version: $Version"
Write-Host "- Python Version: $PythonVersion"
Write-Host "- Architecture: $Architecture"
Write-Host $("v" * 80)
#-------------------------------------------------------------------------------
# Install NSIS
#-------------------------------------------------------------------------------
& "$SCRIPT_DIR\install_nsis.ps1"
if ( ! $? ) {
Write-Host "Failed to install NSIS"
exit 1
}
#-------------------------------------------------------------------------------
# Install Visual Studio Build Tools
#-------------------------------------------------------------------------------
& "$SCRIPT_DIR\install_vs_buildtools.ps1"
if ( ! $? ) {
Write-Host "Failed to install Visual Studio Build Tools"
exit 1
}
#-------------------------------------------------------------------------------
# Build Python
#-------------------------------------------------------------------------------
$KeywordArguments = @{
Version = $PythonVersion
Architecture = $Architecture
}
if ( $Build ) {
$KeywordArguments["Build"] = $true
}
& "$SCRIPT_DIR\build_python.ps1" @KeywordArguments
if ( ! $? ) {
Write-Host "Failed to build Python"
exit 1
}
#-------------------------------------------------------------------------------
# Install Salt
#-------------------------------------------------------------------------------
& "$SCRIPT_DIR\install_salt.ps1"
if ( ! $? ) {
Write-Host "Failed to install Salt"
exit 1
}
#-------------------------------------------------------------------------------
# Prep Salt for Packaging
#-------------------------------------------------------------------------------
& "$SCRIPT_DIR\prep_salt.ps1"
if ( ! $? ) {
Write-Host "Failed to Prepare Salt for packaging"
exit 1
}
#-------------------------------------------------------------------------------
# Build Package
#-------------------------------------------------------------------------------
$KeywordArguments = @{}
if ( ! [String]::IsNullOrEmpty($Version) ) {
$KeywordArguments.Add("Version", $Version)
}
powershell -file "$SCRIPT_DIR\build_pkg.ps1" @KeywordArguments
if ( ! $? ) {
Write-Host "Failed to build package"
exit 1
}
Write-Host $("^" * 80)
Write-Host "Build Salt $Architecture Completed" -ForegroundColor Cyan
Write-Host $("#" * 80)