PowerShell/Docs/build-repo.md

181 lines
5.2 KiB
Markdown
Raw Normal View History

2023-07-29 10:34:04 +02:00
*build-repo.ps1*
================
2021-11-08 21:36:42 +01:00
2023-05-26 12:20:18 +02:00
This PowerShell script builds a repository by supporting: cmake, configure, autogen, Imakefile, and Makefile.
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-07-29 10:15:44 +02:00
PS> ./build-repo.ps1 [[-RepoDir] <String>] [<CommonParameters>]
2021-11-08 21:36:42 +01:00
-RepoDir <String>
Specifies the path to the Git repository
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-08-06 21:36:33 +02:00
PS> ./build-repo.ps1 C:\MyRepo
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-05-26 12:20:18 +02:00
This PowerShell script builds a repository by supporting: cmake, configure, autogen, Imakefile, and Makefile.
2022-11-17 20:02:26 +01:00
.PARAMETER RepoDir
Specifies the path to the Git repository
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./build-repo.ps1 C:\MyRepo
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$RepoDir = "$PWD")
2023-05-26 12:20:18 +02:00
function BuildInDir { param($Path)
$DirName = (Get-Item "$Path").Name
if (Test-Path "$Path/CMakeLists.txt" -pathType leaf) {
"⏳ Building repo 📂$DirName using CMakeLists.txt into subfolder _My_Build ..."
if (-not(Test-Path "$Path/_My_Build/" -pathType container)) {
2022-11-17 20:02:26 +01:00
& mkdir "$Path/_My_Build/"
}
2023-05-26 12:20:18 +02:00
Set-Location "$Path/_My_Build/"
2022-11-17 20:02:26 +01:00
& cmake ..
if ($lastExitCode -ne "0") { throw "Executing 'cmake ..' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
& make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
2023-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/configure" -pathType leaf) {
"⏳ Building repo 📂$DirName using 'configure'..."
Set-Location "$Path/"
2022-11-17 20:02:26 +01:00
& ./configure
#if ($lastExitCode -ne "0") { throw "Script 'configure' exited with error code $lastExitCode" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
& make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
2023-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/autogen.sh" -pathType leaf) {
"⏳ Building repo 📂$DirName using 'autogen.sh'..."
Set-Location "$Path/"
2022-11-17 20:02:26 +01:00
& ./autogen.sh
if ($lastExitCode -ne "0") { throw "Script 'autogen.sh' exited with error code $lastExitCode" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2023-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/build.gradle" -pathType leaf) {
"⏳ Building repo 📂$DirName using build.gradle..."
Set-Location "$Path"
2022-11-17 20:02:26 +01:00
& gradle build
if ($lastExitCode -ne "0") { throw "'gradle build' has failed" }
& gradle test
if ($lastExitCode -ne "0") { throw "'gradle test' has failed" }
2023-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/Imakefile" -pathType leaf) {
"⏳ Building repo 📂$DirName using Imakefile..."
Set-Location "$RepoDir/"
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-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/Makefile" -pathType leaf) {
"⏳ Building repo 📂$DirName 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-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/makefile" -pathType leaf) {
"⏳ Building repo 📂$DirName using makefile..."
Set-Location "$Path"
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (Test-Path "$Path/compile.sh" -pathType leaf) {
"⏳ Building repo 📂$DirName using 'compile.sh'..."
Set-Location "$Path/"
2022-11-17 20:02:26 +01:00
& ./compile.sh
if ($lastExitCode -ne "0") { throw "Script 'compile.sh' exited with error code $lastExitCode" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2023-05-26 12:20:18 +02:00
} elseif (Test-Path "$Path/attower/src/build/DevBuild/build.bat" -pathType leaf) {
"⏳ Building repo 📂$DirName using build.bat ..."
Set-Location "$Path/attower/src/build/DevBuild/"
2022-11-17 20:02:26 +01:00
& ./build.bat build-all-release
if ($lastExitCode -ne "0") { throw "Script 'build.bat' exited with error code $lastExitCode" }
2023-05-26 12:20:18 +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-05-26 12:20:18 +02:00
Write-Warning "Sorry, no make rule applies to: 📂$DirName"
2022-11-17 20:02:26 +01:00
exit 0 # success
}
}
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2023-05-26 12:20:18 +02:00
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
$RepoDirName = (Get-Item "$RepoDir").Name
2022-11-17 20:02:26 +01:00
2023-05-26 12:20:18 +02:00
$PreviousPath = Get-Location
BuildInDir "$RepoDir"
Set-Location "$PreviousPath"
2022-11-17 20:02:26 +01:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2023-05-26 12:20:18 +02:00
"✔️ built repo 📂$RepoDirName 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
2023-09-20 17:05:11 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of build-repo.ps1 as of 09/20/2023 17:04:37)*