2024-01-25 13:37:12 +01:00
|
|
|
Script: *build-repo.ps1*
|
|
|
|
========================
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
This PowerShell script builds a Git repository by supporting build systems such as: autogen, cmake, configure, Gradle, Imakefile, Makefile, and Meson.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2021-11-08 21:36:42 +01:00
|
|
|
```powershell
|
2023-10-19 08:12:00 +02:00
|
|
|
PS> ./build-repo.ps1 [[-path] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
-path <String>
|
2024-03-27 17:36:59 +01:00
|
|
|
Specifies the path to the Git repository (default is current working directory)
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value "$PWD"
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2021-11-08 21:36:42 +01:00
|
|
|
```powershell
|
2023-10-19 08:12:00 +02:00
|
|
|
PS> ./build-repo.ps1 C:\Repos\ninja
|
2024-03-27 17:36:59 +01:00
|
|
|
⏳ Building 📂ninja using CMakeLists.txt into 📂ninja/_Build_Results...
|
2023-10-19 08:12:00 +02:00
|
|
|
...
|
2024-03-27 17:36:59 +01:00
|
|
|
✔️ Built 📂ninja repository in 47 sec.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2021-11-08 21:36:42 +01:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2023-05-26 12:20:18 +02:00
|
|
|
Builds a repository
|
2022-11-17 20:02:26 +01:00
|
|
|
.DESCRIPTION
|
2023-10-19 08:12:00 +02:00
|
|
|
This PowerShell script builds a Git repository by supporting build systems such as: autogen, cmake, configure, Gradle, Imakefile, Makefile, and Meson.
|
|
|
|
.PARAMETER path
|
2024-03-27 17:36:59 +01:00
|
|
|
Specifies the path to the Git repository (default is current working directory)
|
2022-11-17 20:02:26 +01:00
|
|
|
.EXAMPLE
|
2023-10-19 08:12:00 +02:00
|
|
|
PS> ./build-repo.ps1 C:\Repos\ninja
|
2024-03-27 17:36:59 +01:00
|
|
|
⏳ Building 📂ninja using CMakeLists.txt into 📂ninja/_Build_Results...
|
2023-10-19 08:12:00 +02:00
|
|
|
...
|
2024-03-27 17:36:59 +01:00
|
|
|
✔️ Built 📂ninja repository in 47 sec.
|
2022-11-17 20:02:26 +01:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
param([string]$path = "$PWD")
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
function BuildInDir([string]$path) {
|
|
|
|
$dirName = (Get-Item "$path").Name
|
|
|
|
if (Test-Path "$path/CMakeLists.txt" -pathType leaf) {
|
2024-03-27 17:36:59 +01:00
|
|
|
"⏳ (1/4) Building 📂$dirName by using CMake into 📂$dirName/_Build_Results..."
|
|
|
|
if (-not(Test-Path "$path/_Build_Results/" -pathType container)) {
|
|
|
|
& mkdir "$path/_Build_Results/"
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
2024-03-27 17:36:59 +01:00
|
|
|
Set-Location "$path/_Build_Results/"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-12-07 20:24:45 +01:00
|
|
|
"⏳ (2/4) Executing 'cmake' to generate the Makefile..."
|
2022-11-17 20:02:26 +01:00
|
|
|
& cmake ..
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'cmake ..' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-12-07 20:24:45 +01:00
|
|
|
"⏳ (3/4) Executing 'make -j4' to compile and link..."
|
2022-11-17 20:02:26 +01:00
|
|
|
& make -j4
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-01-03 12:11:22 +01:00
|
|
|
"⏳ (4/4) Executing 'ctest -V' to perform tests (optional)..."
|
|
|
|
& ctest -V
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'ctest -V' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
} elseif (Test-Path "$path/autogen.sh" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using 'autogen.sh'..."
|
2023-10-19 08:12:00 +02:00
|
|
|
Set-Location "$path/"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
& ./autogen.sh --force
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing './autogen.sh --force' exited with error code $lastExitCode" }
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
& ./configure
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing './configure' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& make -j4
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
} elseif (Test-Path "$path/configure" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using 'configure'..."
|
2023-10-19 08:12:00 +02:00
|
|
|
Set-Location "$path/"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
& ./configure
|
|
|
|
#if ($lastExitCode -ne "0") { throw "Executing './configure' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& make -j4
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
|
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
& make test
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
|
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/build.gradle" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using Gradle..."
|
|
|
|
Set-Location "$path"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& gradle build
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'gradle build' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& gradle test
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'gradle test' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/meson.build" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using Meson..."
|
|
|
|
Set-Location "$path"
|
|
|
|
& meson . build --prefix=/usr/local
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'meson . build' exited with error code $lastExitCode" }
|
2023-10-19 08:12:00 +02:00
|
|
|
|
|
|
|
} elseif (Test-Path "$path/Imakefile" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using Imakefile..."
|
|
|
|
Set-Location "$path/"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& xmkmf
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'xmkmf' has failed" }
|
|
|
|
|
|
|
|
& make -j4
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
|
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/Makefile" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using Makefile..."
|
|
|
|
Set-Location "$path"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& make -j4
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
|
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/makefile" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using makefile..."
|
|
|
|
Set-Location "$path"
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
& make -j4
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
|
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/compile.sh" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using 'compile.sh'..."
|
|
|
|
Set-Location "$path/"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& ./compile.sh
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing './compile.sh' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& make -j4
|
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
|
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/attower/src/build/DevBuild/build.bat" -pathType leaf) {
|
|
|
|
"⏳ Building 📂$dirName by using build.bat ..."
|
|
|
|
Set-Location "$path/attower/src/build/DevBuild/"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
& ./build.bat build-all-release
|
2024-05-19 10:25:56 +02:00
|
|
|
if ($lastExitCode -ne "0") { throw "Executing 'build.bat build-all-release' exited with error code $lastExitCode" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
} elseif (Test-Path "$path/$dirName" -pathType container) {
|
|
|
|
"⏳ No make rule found, trying subfolder 📂$($dirName)..."
|
|
|
|
BuildInDir "$path/$dirName"
|
2022-11-17 20:02:26 +01:00
|
|
|
} else {
|
2023-10-19 08:12:00 +02:00
|
|
|
Write-Warning "Sorry, no make rule applies to: 📂$dirName"
|
2022-11-17 20:02:26 +01:00
|
|
|
exit 0 # success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-10-19 08:12:00 +02:00
|
|
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
if (-not(Test-Path "$path" -pathType container)) { throw "Can't access directory: $path" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
$previousPath = Get-Location
|
|
|
|
BuildInDir "$path"
|
|
|
|
Set-Location "$previousPath"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-10-19 08:12:00 +02:00
|
|
|
$repoDirName = (Get-Item "$path").Name
|
|
|
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
2024-03-27 17:36:59 +01:00
|
|
|
"✔️ Built 📂$repoDirName repository in $elapsed sec."
|
2022-11-17 20:02:26 +01:00
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of build-repo.ps1 as of 05/19/2024 10:25:16)*
|