Update build-repo.ps1

This commit is contained in:
Markus Fleschutz 2023-10-15 11:49:46 +02:00
parent 44a40d4e15
commit 51947ab13d

View File

@ -2,27 +2,30 @@
.SYNOPSIS .SYNOPSIS
Builds a repository Builds a repository
.DESCRIPTION .DESCRIPTION
This PowerShell script builds a repository by supporting: cmake, configure, autogen, Imakefile, and Makefile. This PowerShell script builds a Git repository by supporting: cmake, configure, autogen, Imakefile, and Makefile.
.PARAMETER RepoDir .PARAMETER path
Specifies the path to the Git repository Specifies the path to the Git repository (current working dir by default)
.EXAMPLE .EXAMPLE
PS> ./build-repo.ps1 C:\MyRepo PS> ./build-repo.ps1 C:\Repos\ninja
Building 📂ninja using CMakeLists.txt into 📂ninja/_My_Build...
...
Built 📂ninja in 47 sec
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$RepoDir = "$PWD") param([string]$path = "$PWD")
function BuildInDir { param($Path) function BuildInDir([string]$path) {
$DirName = (Get-Item "$Path").Name $dirName = (Get-Item "$path").Name
if (Test-Path "$Path/CMakeLists.txt" -pathType leaf) { if (Test-Path "$path/CMakeLists.txt" -pathType leaf) {
"⏳ Building repo 📂$DirName using CMakeLists.txt into subfolder _My_Build ..." "⏳ Building 📂$dirName using CMakeLists.txt into 📂$dirName/_My_Build..."
if (-not(Test-Path "$Path/_My_Build/" -pathType container)) { if (-not(Test-Path "$path/_My_Build/" -pathType container)) {
& mkdir "$Path/_My_Build/" & mkdir "$path/_My_Build/"
} }
Set-Location "$Path/_My_Build/" Set-Location "$path/_My_Build/"
& cmake .. & cmake ..
if ($lastExitCode -ne "0") { throw "Executing 'cmake ..' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'cmake ..' has failed" }
@ -33,9 +36,9 @@ function BuildInDir { param($Path)
& make test & make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
} elseif (Test-Path "$Path/configure" -pathType leaf) { } elseif (Test-Path "$path/configure" -pathType leaf) {
"⏳ Building repo 📂$DirName using 'configure'..." "⏳ Building 📂$dirName using 'configure'..."
Set-Location "$Path/" Set-Location "$path/"
& ./configure & ./configure
#if ($lastExitCode -ne "0") { throw "Script 'configure' exited with error code $lastExitCode" } #if ($lastExitCode -ne "0") { throw "Script 'configure' exited with error code $lastExitCode" }
@ -46,9 +49,9 @@ function BuildInDir { param($Path)
& make test & make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
} elseif (Test-Path "$Path/autogen.sh" -pathType leaf) { } elseif (Test-Path "$path/autogen.sh" -pathType leaf) {
"⏳ Building repo 📂$DirName using 'autogen.sh'..." "⏳ Building 📂$dirName using 'autogen.sh'..."
Set-Location "$Path/" Set-Location "$path/"
& ./autogen.sh & ./autogen.sh
if ($lastExitCode -ne "0") { throw "Script 'autogen.sh' exited with error code $lastExitCode" } if ($lastExitCode -ne "0") { throw "Script 'autogen.sh' exited with error code $lastExitCode" }
@ -56,9 +59,9 @@ function BuildInDir { param($Path)
& make -j4 & make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/build.gradle" -pathType leaf) { } elseif (Test-Path "$path/build.gradle" -pathType leaf) {
"⏳ Building repo 📂$DirName using build.gradle..." "⏳ Building 📂$dirName using build.gradle..."
Set-Location "$Path" Set-Location "$path"
& gradle build & gradle build
if ($lastExitCode -ne "0") { throw "'gradle build' has failed" } if ($lastExitCode -ne "0") { throw "'gradle build' has failed" }
@ -66,9 +69,9 @@ function BuildInDir { param($Path)
& gradle test & gradle test
if ($lastExitCode -ne "0") { throw "'gradle test' has failed" } if ($lastExitCode -ne "0") { throw "'gradle test' has failed" }
} elseif (Test-Path "$Path/Imakefile" -pathType leaf) { } elseif (Test-Path "$path/Imakefile" -pathType leaf) {
"⏳ Building repo 📂$DirName using Imakefile..." "⏳ Building 📂$dirName using Imakefile..."
Set-Location "$RepoDir/" Set-Location "$path/"
& xmkmf & xmkmf
if ($lastExitCode -ne "0") { throw "Executing 'xmkmf' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'xmkmf' has failed" }
@ -76,23 +79,23 @@ function BuildInDir { param($Path)
& make -j4 & make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/Makefile" -pathType leaf) { } elseif (Test-Path "$path/Makefile" -pathType leaf) {
"⏳ Building repo 📂$DirName using Makefile..." "⏳ Building 📂$dirName using Makefile..."
Set-Location "$Path" Set-Location "$path"
& make -j4 & make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/makefile" -pathType leaf) { } elseif (Test-Path "$path/makefile" -pathType leaf) {
"⏳ Building repo 📂$DirName using makefile..." "⏳ Building 📂$dirName using makefile..."
Set-Location "$Path" Set-Location "$path"
& make -j4 & make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/compile.sh" -pathType leaf) { } elseif (Test-Path "$path/compile.sh" -pathType leaf) {
"⏳ Building repo 📂$DirName using 'compile.sh'..." "⏳ Building 📂$dirName using 'compile.sh'..."
Set-Location "$Path/" Set-Location "$path/"
& ./compile.sh & ./compile.sh
if ($lastExitCode -ne "0") { throw "Script 'compile.sh' exited with error code $lastExitCode" } if ($lastExitCode -ne "0") { throw "Script 'compile.sh' exited with error code $lastExitCode" }
@ -100,34 +103,34 @@ function BuildInDir { param($Path)
& make -j4 & make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" } if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/attower/src/build/DevBuild/build.bat" -pathType leaf) { } elseif (Test-Path "$path/attower/src/build/DevBuild/build.bat" -pathType leaf) {
"⏳ Building repo 📂$DirName using build.bat ..." "⏳ Building 📂$dirName using build.bat ..."
Set-Location "$Path/attower/src/build/DevBuild/" Set-Location "$path/attower/src/build/DevBuild/"
& ./build.bat build-all-release & ./build.bat build-all-release
if ($lastExitCode -ne "0") { throw "Script 'build.bat' exited with error code $lastExitCode" } if ($lastExitCode -ne "0") { throw "Script 'build.bat' exited with error code $lastExitCode" }
} elseif (Test-Path "$Path/$DirName" -pathType container) { } elseif (Test-Path "$path/$dirName" -pathType container) {
"⏳ No make rule found, trying subfolder 📂$($DirName)..." "⏳ No make rule found, trying subfolder 📂$($dirName)..."
BuildInDir "$Path/$DirName" BuildInDir "$path/$dirName"
} else { } else {
Write-Warning "Sorry, no make rule applies to: 📂$DirName" Write-Warning "Sorry, no make rule applies to: 📂$dirName"
exit 0 # success exit 0 # success
} }
} }
try { try {
$StopWatch = [system.diagnostics.stopwatch]::startNew() $stopWatch = [system.diagnostics.stopwatch]::startNew()
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } if (-not(Test-Path "$path" -pathType container)) { throw "Can't access directory: $path" }
$RepoDirName = (Get-Item "$RepoDir").Name
$PreviousPath = Get-Location $previousPath = Get-Location
BuildInDir "$RepoDir" BuildInDir "$path"
Set-Location "$PreviousPath" Set-Location "$previousPath"
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds $repoDirName = (Get-Item "$path").Name
"✔️ built repo 📂$RepoDirName in $Elapsed sec" [int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✔️ Built 📂$repoDirName in $elapsed sec"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"