ConceptCore/pyconcept/scripts/Build.ps1

88 lines
2.9 KiB
PowerShell
Raw Permalink Normal View History

2024-04-15 22:16:14 +03:00
Set-Location $PSScriptRoot\..
$packageName = 'pyconcept'
2024-04-17 00:11:47 +03:00
$output = "${PSScriptRoot}\..\..\output\py\${packageName}"
2024-04-15 22:16:14 +03:00
$python = '.\venv\Scripts\python.exe'
2024-04-17 00:11:47 +03:00
2024-07-14 14:02:16 +03:00
$scripts = Resolve-Path -Path "${PSScriptRoot}\..\venv\Scripts"
$Env:PATH += ";${scripts}"
2024-04-17 00:11:47 +03:00
$ccl_source = "${PSScriptRoot}\..\..\ccl"
$ccl_destination = "${PSScriptRoot}\..\ccl"
$ccl_include = ('*.cpp','*.hpp','*.h')
2024-04-15 22:16:14 +03:00
function Build {
PrepareEnv
2024-04-15 22:16:14 +03:00
PrepareImports
PrepareOutput
2024-04-17 00:11:47 +03:00
BuildProject
$wheel = Get-Childitem -Path "${output}\*.whl" -Name
2024-04-15 22:16:14 +03:00
if (-not (${wheel}) -or $LASTEXITCODE -ne 0) {
Write-Error "No wheel generated for ${packageName}"
Exit 1
}
TestWheel("${output}\${wheel}")
2024-04-17 21:48:36 +03:00
# Remove-Item venv -Recurse -Force
Remove-Item build -Recurse -Force
Remove-Item ${ccl_destination} -Recurse -Force
2024-04-15 22:16:14 +03:00
Exit $LASTEXITCODE
}
function PrepareEnv {
2024-04-17 00:11:47 +03:00
Write-Host "Set up environment for ${python}" -ForegroundColor DarkGreen
2024-04-15 22:16:14 +03:00
if (-not (Test-Path -Path ${python} -PathType Leaf)) {
& 'python' -m venv .\venv
& $python -m pip install --upgrade pip
& $python -m pip install -r requirements-dev.txt
2024-04-15 22:16:14 +03:00
}
}
function PrepareImports {
Write-Host 'Copy imports' -ForegroundColor DarkGreen
2024-04-17 00:11:47 +03:00
if (Test-Path -Path ${ccl_destination}) {
Remove-Item ${ccl_destination} -Recurse -Force
2024-04-15 22:16:14 +03:00
}
2024-04-17 00:11:47 +03:00
New-Item -Path ${ccl_destination} -ItemType Directory | Out-Null
$source = Resolve-Path(${ccl_source})
$destination = Resolve-Path(${ccl_destination})
Get-ChildItem ${source} -Recurse -Include ${ccl_include} `
| Where-Object { `
$_.FullName -CNotLike '*build*' -And `
$_.FullName -CNotLike '*test*' `
} `
| ForEach-Object -Begin{} -End{} -Process{
$destinationFile = Join-Path ${destination}.Path $_.FullName.Substring(${source}.Path.length)
New-Item -ItemType File -Path ${destinationFile} -Force | Out-Null
Copy-Item -Path $_.FullName -Destination ${destinationFile} -Force
}
Copy-Item -Path "${source}/CMakeLists.txt" -Destination ${destination}
Copy-Item -Path "${source}/conanfile.txt" -Destination ${destination}
Copy-Item -Path "${source}/cmake" -Destination ${destination} -Recurse
2024-04-15 22:16:14 +03:00
}
function PrepareOutput {
2024-04-17 00:11:47 +03:00
Write-Host "Clear output at ${output}" -ForegroundColor DarkGreen
2024-04-15 22:16:14 +03:00
if (Test-Path -Path ${output}) {
Remove-Item ${output} -Recurse -Force
}
}
2024-04-17 00:11:47 +03:00
function BuildProject {
Write-Host 'Building project...' -ForegroundColor DarkGreen
& $python -m build --wheel --no-isolation --outdir="${output}"
2024-07-14 14:02:16 +03:00
if ($LASTEXITCODE -eq 0) {
& $python -m build --sdist --no-isolation --outdir="${output}"
}
2024-04-15 22:16:14 +03:00
}
function TestWheel([string] $wheelPath) {
Write-Host 'Running tests...' -ForegroundColor DarkGreen
& ${python} -m pip uninstall -y ${packageName}
& ${python} -m pip install -I ${wheelPath}
& ${python} -m unittest
}
Build