forked from xt-sys/xtchain
Use PowerShell module and improved xtchain ps1
This commit is contained in:
@@ -1,57 +1,156 @@
|
||||
#
|
||||
# PROJECT: XTchain
|
||||
# LICENSE: See the COPYING.md in the top level directory
|
||||
# FILE: scripts/xtchain.ps1
|
||||
# DESCRIPTION: XTchain Entry Script
|
||||
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||
#
|
||||
|
||||
# Get the absolute path to the XTchain
|
||||
$XTCDIR = (Get-Item -Path ".\").FullName
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Position = 0)]
|
||||
[string]$TargetArchitecture = "amd64",
|
||||
|
||||
[Parameter(Position = 1)]
|
||||
[string]$SourceDirectory = $PWD.Path
|
||||
)
|
||||
|
||||
# Read the XTchain version
|
||||
$env:XTCVER = Get-Content "${XTCDIR}\Version"
|
||||
|
||||
# Load the library (Make sure the xtclib.ps1 file is PowerShell compatible)
|
||||
. "${XTCDIR}\lib\xtchain\xtclib.ps1"
|
||||
|
||||
# Set the target architecture
|
||||
$env:TARGET = $args[0]
|
||||
if (-not $env:TARGET) { $env:TARGET = "amd64" }
|
||||
|
||||
# Save the source directory
|
||||
$SRCDIR = $args[1]
|
||||
if (-not $SRCDIR) { $SRCDIR = (Get-Location).Path }
|
||||
|
||||
# Make sure the compiler flags are clean
|
||||
$env:HOST = $null
|
||||
$env:CFLAGS = $null
|
||||
$env:CXXFLAGS = $null
|
||||
$env:LDFLAGS = $null
|
||||
|
||||
# Update PATH
|
||||
$env:PATH = "${XTCDIR}\bin;" + $env:PATH
|
||||
|
||||
# Display banner
|
||||
version
|
||||
|
||||
# Invoke shell with fancy prompt
|
||||
function global:prompt {
|
||||
$PROMPT = " XT Toolchain "
|
||||
$CWD = (Get-Location).Path
|
||||
$CHEVRON = [char]0xE0B0
|
||||
$SEGMENTS = @(
|
||||
@{ TEXT = $PROMPT; BGCOLOR = "Blue"; FGCOLOR = "White" },
|
||||
@{ TEXT = " $CWD "; BGCOLOR = "DarkCyan"; FGCOLOR = "White" }
|
||||
# Initialize XTchain environment
|
||||
function Initialize-XTChain {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Architecture,
|
||||
[string]$SourcePath
|
||||
)
|
||||
for ($INDEX = 0; $INDEX -lt $SEGMENTS.Count; $INDEX++) {
|
||||
$SEGMENT = $SEGMENTS[$INDEX]
|
||||
$NEXTBG = if ($INDEX + 1 -lt $SEGMENTS.Count) { $SEGMENTS[$INDEX + 1].BGCOLOR } else { "Default" }
|
||||
Write-Host $SEGMENT.TEXT -NoNewLine -ForegroundColor $SEGMENT.FGCOLOR -BackgroundColor $SEGMENT.BGCOLOR
|
||||
if ($NEXTBG -ne "Default") {
|
||||
Write-Host $CHEVRON -NoNewLine -ForegroundColor $SEGMENT.BGCOLOR -BackgroundColor $NEXTBG
|
||||
} else {
|
||||
Write-Host $CHEVRON -NoNewLine -ForegroundColor $SEGMENT.BGCOLOR
|
||||
|
||||
# Get the absolute path to XTchain
|
||||
$script:XTCDIR = (Get-Item -Path ".\").FullName
|
||||
|
||||
# Read XTchain version
|
||||
$versionFile = Join-Path $script:XTCDIR "Version"
|
||||
if (Test-Path $versionFile) {
|
||||
$env:XTCVER = Get-Content $versionFile -Raw | ForEach-Object { $_.Trim() }
|
||||
} else {
|
||||
Write-Warning "Version file not found at $versionFile"
|
||||
$env:XTCVER = "Unknown"
|
||||
}
|
||||
|
||||
# Set XTchain directory environment variable
|
||||
$env:XTCDIR = $script:XTCDIR
|
||||
|
||||
# Import XTchain module
|
||||
$modulePath = Join-Path $script:XTCDIR "lib\xtchain\xtclib.psm1"
|
||||
if (Test-Path $modulePath) {
|
||||
Import-Module $modulePath -Force -Global
|
||||
} else {
|
||||
Write-Error "XTchain module not found at $modulePath"
|
||||
return $false
|
||||
}
|
||||
|
||||
# Set target architecture
|
||||
$env:TARGET = $Architecture
|
||||
|
||||
# Validate source directory
|
||||
if (-not (Test-Path $SourcePath)) {
|
||||
Write-Error "Source directory does not exist: $SourcePath"
|
||||
return $false
|
||||
}
|
||||
|
||||
# Clean compiler environment variables
|
||||
$env:HOST = $null
|
||||
$env:CFLAGS = $null
|
||||
$env:CXXFLAGS = $null
|
||||
$env:LDFLAGS = $null
|
||||
|
||||
# Update PATH to include XTchain binaries
|
||||
$xtcBinPath = Join-Path $script:XTCDIR "bin"
|
||||
if (Test-Path $xtcBinPath) {
|
||||
$env:PATH = "$xtcBinPath;" + $env:PATH
|
||||
} else {
|
||||
Write-Warning "XTchain bin directory not found at $xtcBinPath"
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
# Create fancy PowerLine-style prompt
|
||||
function Set-XTChainPrompt {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
function global:prompt {
|
||||
try {
|
||||
$promptText = " XT Toolchain "
|
||||
$currentPath = (Get-Location).Path
|
||||
$chevron = [char]0xE0B0
|
||||
|
||||
# Define prompt segments
|
||||
$segments = @(
|
||||
@{
|
||||
Text = $promptText
|
||||
BackgroundColor = "Blue"
|
||||
ForegroundColor = "White"
|
||||
},
|
||||
@{
|
||||
Text = " $currentPath "
|
||||
BackgroundColor = "DarkCyan"
|
||||
ForegroundColor = "White"
|
||||
}
|
||||
)
|
||||
|
||||
# Render segments
|
||||
for ($index = 0; $index -lt $segments.Count; $index++) {
|
||||
$segment = $segments[$index]
|
||||
$nextBackground = if ($index + 1 -lt $segments.Count) {
|
||||
$segments[$index + 1].BackgroundColor
|
||||
} else {
|
||||
"Default"
|
||||
}
|
||||
|
||||
# Write segment text
|
||||
Write-Host $segment.Text -NoNewLine -ForegroundColor $segment.ForegroundColor -BackgroundColor $segment.BackgroundColor
|
||||
|
||||
# Write separator
|
||||
if ($nextBackground -ne "Default") {
|
||||
Write-Host $chevron -NoNewLine -ForegroundColor $segment.BackgroundColor -BackgroundColor $nextBackground
|
||||
} else {
|
||||
Write-Host $chevron -NoNewLine -ForegroundColor $segment.BackgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
return " "
|
||||
}
|
||||
catch {
|
||||
# Fallback to simple prompt if PowerLine fails
|
||||
return "XTC> "
|
||||
}
|
||||
}
|
||||
return " "
|
||||
}
|
||||
Set-Location -Path $SRCDIR
|
||||
|
||||
# Main execution
|
||||
try {
|
||||
Write-Host "Initializing XTchain environment..." -ForegroundColor Green
|
||||
|
||||
if (-not (Initialize-XTChain -Architecture $TargetArchitecture -SourcePath $SourceDirectory)) {
|
||||
Write-Error "Failed to initialize XTchain environment"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Display version information
|
||||
Show-XTCVersion
|
||||
|
||||
# Set up the fancy prompt
|
||||
Set-XTChainPrompt
|
||||
|
||||
# Change to source directory
|
||||
Set-Location -Path $SourceDirectory
|
||||
|
||||
Write-Host "XTchain environment ready!" -ForegroundColor Green
|
||||
Write-Host "Current directory: $(Get-Location)" -ForegroundColor Cyan
|
||||
Write-Host "Target architecture: $env:TARGET" -ForegroundColor Cyan
|
||||
Write-Host "Type 'Show-XTCHelp' or 'help' for available commands" -ForegroundColor Yellow
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to initialize XTchain: $_"
|
||||
exit 1
|
||||
}
|
Reference in New Issue
Block a user