From b74c31f17cd64a7b64c7b54d28fe862f686cb250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Valad=C3=A9s?= Date: Fri, 10 Oct 2025 16:26:28 +0200 Subject: [PATCH] configure.ps1: Fix path handling and improve reliability - Use $PSScriptRoot for reliable source directory detection - Use Join-Path for proper path construction - Validate BUILD_TYPE against Debug/Release - Fix CMake argument quoting - Use Write-Error for error messages --- configure.ps1 | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/configure.ps1 b/configure.ps1 index 739a47a1..26b651a7 100644 --- a/configure.ps1 +++ b/configure.ps1 @@ -4,48 +4,41 @@ # DESCRIPTION: Project configuration script for preparing the build environment # DEVELOPERS: Aiken Harris - # Check XTchain if (-not $env:XTCVER) { - Write-Host "XTChain not detected or corrupted!" + Write-Error "XTChain not detected or corrupted!" exit 1 } -# Set target architecture -if ($env:TARGET) { - $ARCH = $env:TARGET -} else { - $ARCH = "amd64" -} +# Set target architecture defaulting to amd64 +$ARCH = if ($env:TARGET) { $env:TARGET } else { "amd64" } -# Set target build type -if (-not $env:BUILD_TYPE) { - $env:BUILD_TYPE = "DEBUG" -} +# Set target build type defaulting to Debug +$env:BUILD_TYPE = if ($env:BUILD_TYPE -in @("Debug", "Release")) { $env:BUILD_TYPE } else { "Debug" } # Set variables -$EXECTOS_SOURCE_DIR = (Get-Location).Path -$EXECTOS_BINARY_DIR = "build-$($ARCH)-$($env:BUILD_TYPE.ToLower())" +$EXECTOS_SOURCE_DIR = $PSScriptRoot +$EXECTOS_BINARY_DIR = Join-Path $EXECTOS_SOURCE_DIR "build-$ARCH-$($env:BUILD_TYPE.ToLower())" -# Create directories if needed -if ($EXECTOS_SOURCE_DIR -eq (Get-Location).Path) { - Write-Host "Creating directories in $EXECTOS_BINARY_DIR" +# Create build directory +if (-not (Test-Path $EXECTOS_BINARY_DIR)) { + Write-Host "Creating build directory: $EXECTOS_BINARY_DIR" New-Item -ItemType Directory -Path $EXECTOS_BINARY_DIR -Force | Out-Null - Set-Location -Path $EXECTOS_BINARY_DIR } +Set-Location $EXECTOS_BINARY_DIR + # Delete old cache -Remove-Item -Path "CMakeCache.txt" -ErrorAction SilentlyContinue -Remove-Item -Path "host-tools/CMakeCache.txt" -ErrorAction SilentlyContinue +Remove-Item "CMakeCache.txt", "host-tools/CMakeCache.txt" -ErrorAction SilentlyContinue # Configure project using CMake -& cmake -G Ninja -DARCH:STRING=$($ARCH) -DBUILD_TYPE:STRING=$($env:BUILD_TYPE) $EXECTOS_SOURCE_DIR +& cmake -G Ninja "-DARCH:STRING=$ARCH" "-DBUILD_TYPE:STRING=$($env:BUILD_TYPE)" $EXECTOS_SOURCE_DIR # Check if configuration succeeded if ($LASTEXITCODE -ne 0) { - Write-Host "Configure script failed." + Write-Error "Configure script failed." exit 1 -} else { - "$($ARCH)" | Out-File -Encoding ASCII -NoNewline build.arch - Write-Host "Configure script completed. Enter '$EXECTOS_BINARY_DIR' directory and execute 'xbuild' to build ExectOS." } + +$ARCH | Out-File -Encoding ASCII -NoNewline "build.arch" +Write-Host "Configure completed. Run 'xbuild' to build ExectOS." \ No newline at end of file