/[sudobot]/trunk/blazew.ps1
ViewVC logotype

Contents of /trunk/blazew.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 630 - (show annotations)
Sat Sep 7 14:57:22 2024 UTC (6 months, 2 weeks ago) by rakinar2
File size: 4454 byte(s)
chore: merge branch dev

1 #!/usr/bin/env powershell
2
3 $blazeDir = (Join-Path (Get-Location) ".blaze").Replace("\", "/")
4 $blazewDir = (Join-Path (Get-Location) "blaze/wrapper").Replace("\", "/")
5 $propertiesFile = Join-Path $blazewDir "blaze_wrapper.properties"
6 $wrapperJSFile = Join-Path $blazewDir "blaze_wrapper.js"
7 $bunBinDir = Join-Path $blazeDir "bun/bin"
8 $bunPath = Join-Path $bunBinDir "bun.exe"
9 $debugMode = $false
10
11 if ($env:BLAZEW_DEBUG -eq "1") {
12 $debugMode = $true
13 }
14
15 function Debug-Log {
16 param([string]$message)
17
18 if ($debugMode) {
19 Write-Host "[debug] $message"
20 }
21 }
22
23 function Get-Property {
24 param([string]$key)
25
26 $value = Get-Content $propertiesFile | Select-String -Pattern "$key=" | ForEach-Object { $_ -replace "$key=" }
27 return $value
28 }
29
30 function Start-Blaze {
31 if (-not (Test-Path $blazeDir)) {
32 Debug-Log "Creating .blaze/ directory"
33 New-Item -ItemType Directory -Path $blazeDir | Out-Null
34 }
35
36 if (-not (Test-Path $blazewDir)) {
37 Write-Error "blaze/wrapper/ directory not found. Please run this script from the root of a BlazeBuild project."
38 exit 1
39 }
40
41 if (-not (Test-Path $propertiesFile)) {
42 Write-Error "blaze_wrapper.properties file not found. Please run this script from the root of a BlazeBuild project."
43 exit 1
44 }
45 }
46
47 # These checks were taken from the Bun installation script.
48 function Test-Bun {
49 $bunRevision = "$(& "${bunPath}" --revision)"
50
51 if ($LASTEXITCODE -eq 1073741795) {
52 # STATUS_ILLEGAL_INSTRUCTION
53 Write-Output "Install Failed - bun.exe is not compatible with your CPU. This should have been detected before downloading.`n"
54 exit 1
55 }
56
57 if (($LASTEXITCODE -eq 3221225781) -or ($LASTEXITCODE -eq -1073741515)) {
58 # STATUS_DLL_NOT_FOUND
59 Write-Output "Install Failed - You are missing a DLL required to run bun.exe"
60 Write-Output "This can be solved by installing the Visual C++ Redistributable from Microsoft:`nSee https://learn.microsoft.com/cpp/windows/latest-supported-vc-redist`nDirect Download -> https://aka.ms/vs/17/release/vc_redist.x64.exe`n`n"
61 Write-Output "The command '${bunPath} --revision' exited with code ${LASTEXITCODE}`n"
62 exit 1
63 }
64
65 if ($LASTEXITCODE -ne 0) {
66 Write-Output "Install Failed - could not verify bun.exe"
67 Write-Output "The command '${bunPath} --revision' exited with code ${LASTEXITCODE}`n"
68 exit 1
69 }
70
71 return $bunRevision
72 }
73
74 Start-Blaze
75
76 $bunVersion = Get-Property "bun.version"
77
78 if (-not $bunVersion) {
79 Write-Error "bun.version property not found or is empty in blaze_wrapper.properties file."
80 exit 1
81 }
82
83 if (Test-Path $bunPath) {
84 Write-Host "Found bun installation at $bunPath"
85 Test-Bun
86
87 $version = & $bunPath --version
88
89 if ($version -eq $bunVersion) {
90 Write-Host "Bun is up to date"
91 # TODO
92 exit 0
93 }
94 }
95
96 if (-not (Get-Command Get-CimInstance -ErrorAction SilentlyContinue)) {
97 Write-Output "Cannot Install Bun"
98 Write-Output "Bun for Windows requires PowerShell 3.0 or later.`n"
99 exit 1
100 }
101
102 if (-not ((Get-CimInstance Win32_ComputerSystem)).SystemType -match "x64-based") {
103 Write-Output "Cannot Install Bun"
104 Write-Output "Bun for Windows is currently only available for x86 64-bit Windows.`n"
105 exit 1
106 }
107
108 $bunDownloadURL = "https://github.com/oven-sh/bun/releases/download/bun-v$bunVersion/bun-windows-x64.zip"
109 $zipPath = Join-Path $blazeDir "bun.zip"
110
111 if (Test-Path $zipPath) {
112 Remove-Item -Force $zipPath
113 }
114
115 Write-Host "Downloading Bun from $bunDownloadURL"
116 Invoke-WebRequest -Uri $bunDownloadURL -OutFile $zipPath
117
118 $bunInstallPath = Join-Path $blazeDir "bun"
119
120 if (Test-Path $bunInstallPath) {
121 Remove-Item -Recurse -Force $bunInstallPath
122 }
123
124 Write-Host "Installing Bun to $bunInstallPath"
125 Expand-Archive -Path $zipPath -DestinationPath $bunInstallPath
126 Remove-Item -Force $zipPath
127 Rename-Item -Path (Join-Path $bunInstallPath "bun-windows-x64") -NewName $bunBinDir
128
129 Test-Bun
130
131 Write-Host "Bun installed successfully"
132
133 # Prepare and execute the BlazeBuild wrapper
134
135 if (-not (Test-Path $wrapperJSFile)) {
136 Write-Error "blaze_wrapper.js file not found. Please run this script from the root of a BlazeBuild project."
137 exit 1
138 }
139
140 $env:Path = "$bunBinDir;$env:Path"
141
142 $blazeBuildArgs = $args -join " "
143 Debug-Log "Executing BlazeBuild with arguments: $blazeBuildArgs"
144 & $bunPath run $wrapperJSFile $args
145 exit $LASTEXITCODE

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26