PowerShell/Scripts/build-repo.ps1

136 lines
4.2 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
2023-04-27 12:51:58 +02:00
function BuildInDir { param($Path)
2022-12-22 12:41:07 +01:00
$DirName = (Get-Item "$Path").Name
if (Test-Path "$Path/CMakeLists.txt" -pathType leaf) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$DirName using CMakeLists.txt into subfolder _My_Build ..."
if (-not(Test-Path "$Path/_My_Build/" -pathType container)) {
2022-01-21 12:46:39 +01:00
& 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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$DirName using Makefile..."
Set-Location "$Path"
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/makefile" -pathType leaf) {
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ Building repo 📂$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) {
2023-04-27 12:51:58 +02:00
"⏳ No make rule found, trying subfolder 📂$($DirName)..."
BuildInDir "$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
2023-04-27 12:51:58 +02:00
BuildInDir "$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
2023-04-27 12:51:58 +02:00
"✔️ built repo 📂$RepoDirName 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
2023-04-27 12:51:58 +02:00
}