PowerShell/Scripts/build-repo.ps1

128 lines
3.9 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2022-12-22 12:41:07 +01:00
Builds a repository
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2022-12-22 12:41:07 +01:00
This PowerShell script builds a repository by supporting: cmake, configure, autogen, Imakefile, and Makefile.
.PARAMETER RepoDir
2021-10-12 21:51:51 +02:00
Specifies the path to the Git repository
2021-07-13 21:10:02 +02:00
.EXAMPLE
PS> ./build-repo C:\MyRepo
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-29 12:47:46 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2021-04-14 17:50:35 +02:00
#>
2021-07-15 15:51:22 +02:00
param([string]$RepoDir = "$PWD")
2021-04-14 17:50:35 +02:00
2021-05-07 15:37:04 +02:00
function MakeDir { param($Path)
2022-12-22 12:41:07 +01:00
$DirName = (Get-Item "$Path").Name
if (Test-Path "$Path/CMakeLists.txt" -pathType leaf) {
"🔨 Building 📂$DirName using CMakeLists.txt into subfolder _My_Build/..."
2022-01-21 12:46:39 +01:00
if (-not(test-path "$Path/_My_Build/" -pathType container)) {
& mkdir "$Path/_My_Build/"
2021-04-14 19:23:34 +02:00
}
2022-12-22 12:41:07 +01:00
Set-Location "$Path/_My_Build/"
2021-05-10 16:21:38 +02:00
2021-04-14 19:01:47 +02:00
& cmake ..
if ($lastExitCode -ne "0") { throw "Executing 'cmake ..' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-04-14 20:02:04 +02:00
2021-05-22 15:51:36 +02:00
& make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/configure" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using 'configure'..."
2022-12-22 12:41:07 +01:00
Set-Location "$Path/"
2021-04-14 20:02:04 +02:00
& ./configure
2021-07-02 17:09:52 +02:00
#if ($lastExitCode -ne "0") { throw "Script 'configure' exited with error code $lastExitCode" }
2021-04-14 20:02:04 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-07-02 17:09:52 +02:00
& make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/autogen.sh" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using 'autogen.sh'..."
2022-12-22 12:41:07 +01:00
Set-Location "$Path/"
2021-04-14 20:02:04 +02:00
& ./autogen.sh
2021-05-23 12:10:58 +02:00
if ($lastExitCode -ne "0") { throw "Script 'autogen.sh' exited with error code $lastExitCode" }
2021-04-14 20:02:04 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/build.gradle" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using build.gradle..."
2022-12-22 12:41:07 +01:00
Set-Location "$Path"
2021-05-10 16:21:38 +02:00
& gradle build
if ($lastExitCode -ne "0") { throw "'gradle build' has failed" }
& gradle test
if ($lastExitCode -ne "0") { throw "'gradle test' has failed" }
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/Imakefile" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using Imakefile..."
2022-12-22 12:41:07 +01:00
Set-Location "$RepoDir/"
2021-04-15 08:25:20 +02:00
& xmkmf
if ($lastExitCode -ne "0") { throw "Executing 'xmkmf' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/Makefile" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using Makefile..."
2022-12-22 12:41:07 +01:00
Set-Location "$Path"
2021-04-14 19:01:47 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-04-14 20:02:04 +02:00
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/compile.sh" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using 'compile.sh'..."
2022-12-22 12:41:07 +01:00
Set-Location "$Path/"
2021-05-23 11:59:46 +02:00
& ./compile.sh
2021-05-23 12:10:58 +02:00
if ($lastExitCode -ne "0") { throw "Script 'compile.sh' exited with error code $lastExitCode" }
2021-05-23 11:59:46 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/attower/src/build/DevBuild/build.bat" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using build.bat ..."
2022-12-22 12:41:07 +01:00
Set-Location "$Path/attower/src/build/DevBuild/"
2021-04-14 19:23:34 +02:00
2021-04-15 08:25:20 +02:00
& ./build.bat build-all-release
2021-05-23 12:10:58 +02:00
if ($lastExitCode -ne "0") { throw "Script 'build.bat' exited with error code $lastExitCode" }
2021-04-14 19:23:34 +02:00
2022-12-22 12:41:07 +01:00
} elseif (Test-Path "$Path/$DirName" -pathType container) {
2021-07-02 16:22:17 +02:00
"🔨 No make rule found, trying subfolder 📂$($DirName)..."
2021-05-07 15:37:04 +02:00
MakeDir "$Path/$DirName"
2021-04-14 17:50:35 +02:00
} else {
2022-12-22 12:41:07 +01:00
Write-Warning "Sorry, no make rule applies to: 📂$DirName"
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-04-14 17:50:35 +02:00
}
2021-05-07 15:37:04 +02:00
}
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2022-12-22 12:41:07 +01:00
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
$RepoDirName = (Get-Item "$RepoDir").Name
2021-05-07 15:37:04 +02:00
2022-12-22 12:41:07 +01:00
$PreviousPath = Get-Location
2021-05-07 15:37:04 +02:00
MakeDir "$RepoDir"
2022-12-22 12:41:07 +01:00
Set-Location "$PreviousPath"
2021-04-15 08:41:37 +02:00
2021-04-21 16:43:08 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2022-12-22 12:41:07 +01:00
"✔️ built 📂$RepoDirName repository in $Elapsed sec"
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-04-14 17:50:35 +02:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-04-14 17:50:35 +02:00
exit 1
2022-12-22 12:41:07 +01:00
}