mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 23:11:00 +00:00
5ae30c4264
We mark some dependency installations using empty `.release/debug_installation` files to support coexisting release/debug installations, which is needed on Windows to be able to easily switch between Release/Debug builds of IfcOpenShell and avoiding conflicts when different binaries are using different debubg/non-debug runtimes.
It was introduced in 517ba237f and `mark_based_on_artifacts` was pre-existing installations based on the found artifacts, all new installations were not relying on this for marking. Since it's been some time, dropping this workaround.
179 lines
4.8 KiB
PowerShell
179 lines
4.8 KiB
PowerShell
Set-PSDebug -Trace 0
|
|
Set-StrictMode -Version 3
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$cecho = "$PSScriptRoot\cecho.cmd"
|
|
|
|
|
|
# Create marker file to indicate whether Release or Debug build was installed.
|
|
function mark {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$installation_dir
|
|
)
|
|
|
|
if (-not (Test-Path -Path $installation_dir)) {
|
|
throw "Directory '$installation_dir' does not exist."
|
|
}
|
|
|
|
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
|
|
if (Test-Path -Path $marker_filepath) {
|
|
return
|
|
}
|
|
. $cecho 0 13 "Marking installation in '$installation_dir' with '$ENV:MARKER_FILE'."
|
|
New-Item -Path $marker_filepath -ItemType File | Out-Null
|
|
}
|
|
|
|
# Check if installation exists for the current `BUILD_CFG`.
|
|
# Returns exit code 200 if installation exists, 404 otherwise.
|
|
# Since we want Release and Debug installation to coexist,
|
|
# we add special marker file to indicate which build type was installed.
|
|
function check_installation {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dependency_name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$installation_dir
|
|
)
|
|
|
|
if (-not (Test-Path -Path $installation_dir)) {
|
|
exit 404
|
|
}
|
|
|
|
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
|
|
if (-not (Test-Path -Path $marker_filepath)) {
|
|
exit 404
|
|
}
|
|
exit 200
|
|
}
|
|
|
|
|
|
# Dependencies Release/Debug configs compatibility:
|
|
# - OpenCASCADE: incompatible
|
|
# - rocksdb: incompatible
|
|
# - opencollada: incompatible
|
|
# - Qt6: compatible when both Release and Debug artifacts are installed
|
|
# - zstd: compatible
|
|
|
|
function setup_build_cfg {
|
|
if (-not $env:BUILD_CFG) {
|
|
throw "Variable 'BUILD_CFG' is not defined."
|
|
}
|
|
if ($env:BUILD_CFG -eq "Debug") {
|
|
$ENV:MARKER_FILE = ".debug_installation"
|
|
}
|
|
else {
|
|
$ENV:MARKER_FILE = ".release_installation"
|
|
}
|
|
}
|
|
|
|
|
|
function extract_file {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dependency_name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$filename,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$destination_dir,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dir_after_extraction
|
|
)
|
|
if (Test-Path -Path "$dir_after_extraction") {
|
|
. $cecho 0 13 "$dependency_name already extracted into '$dir_after_extraction'. Skipping."
|
|
return
|
|
}
|
|
. $cecho 0 13 "Extracting $dependency_name into '$destination_dir' from '$filename'."
|
|
7z x -bso0 -bsp0 "$filename" -o"$destination_dir"
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to extract '$filename' for '$dependency_name' with 7z exit code $LASTEXITCODE."
|
|
}
|
|
}
|
|
|
|
|
|
function download_file {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dependency_name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$url,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$destination_dir,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$filename
|
|
)
|
|
mkdir "$destination_dir" -Force | Out-Null
|
|
pushd "$destination_dir"
|
|
if (Test-Path -Path "$filename") {
|
|
. $cecho 0 13 "$dependency_name already downloaded. Skipping."
|
|
return
|
|
}
|
|
|
|
. $cecho 0 13 "Downloading $dependency_name into '$destination_dir'"
|
|
Invoke-WebRequest $url -OutFile $filename
|
|
}
|
|
|
|
|
|
# Required env variables:
|
|
# - DEPS_DIR
|
|
function git_clone_and_checkout_revision {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dependency_name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$git_url,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dest_dir,
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$revision
|
|
)
|
|
if (Test-Path -Path "$dest_dir") {
|
|
. $cecho 0 13 "Cloning $dependency_name is already cloned."
|
|
return
|
|
}
|
|
. $cecho 0 13 "Cloning $dependency_name into '$dest_dir'."
|
|
pushd "$env:DEPS_DIR"
|
|
git clone $git_url $dest_dir
|
|
popd
|
|
|
|
pushd "$dest_dir"
|
|
git fetch
|
|
. $cecho 0 13 "Checking out $dependency_name revision $revision."
|
|
git reset --hard
|
|
git checkout $revision
|
|
popd
|
|
}
|
|
|
|
function install_cmake_project {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$dependency_name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$build_dir,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$configuration
|
|
)
|
|
pushd "$build_dir"
|
|
. $cecho 0 13 "Installing $dependency_name ($configuration). Please be patient, this may take a while."
|
|
$command = "cmake --install . --config $configuration"
|
|
. $cecho 0 13 "$command"
|
|
Invoke-Expression $command
|
|
popd
|
|
}
|
|
|
|
function main {
|
|
& setup_build_cfg
|
|
# Dispatch command.
|
|
$command = $Args[0]
|
|
if ($args.Count -gt 1) {
|
|
$command_args = $Args[1..($args.Count - 1)]
|
|
}
|
|
else {
|
|
$command_args = @()
|
|
}
|
|
& $command @command_args
|
|
}
|
|
|
|
& main @Args
|
|
exit 0
|