1
1
The * build-repo.ps1* Script
2
2
===========================
3
3
4
- This PowerShell script builds a Git repository by supporting build systems such as : autogen, cmake, configure, Gradle, Imakefile, Makefile, and Meson.
4
+ This PowerShell script builds a Git repository by supporting the build systems: autogen, cmake, configure, Gradle, Imakefile, Makefile, and Meson.
5
5
6
6
Parameters
7
7
----------
8
8
``` powershell
9
9
/Repos/PowerShell/scripts/build-repo.ps1 [[-path] <String>] [<CommonParameters>]
10
10
11
11
-path <String>
12
- Specifies the path to the Git repository (default is current working directory)
12
+ Specifies the path to the Git repository (current working directory by default )
13
13
14
14
Required? false
15
15
Position? 1
16
16
Default value "$PWD"
17
17
Accept pipeline input? false
18
+ Aliases
18
19
Accept wildcard characters? false
19
20
20
21
[<CommonParameters>]
@@ -26,9 +27,9 @@ Example
26
27
-------
27
28
``` powershell
28
29
PS> ./build-repo.ps1 C:\Repos\ninja
29
- ⏳ Building 📂ninja using CMakeLists.txt into 📂ninja/_Build_Results ...
30
+ ⏳ Building 📂ninja by using CMake ...
30
31
...
31
- ✅ Built 📂ninja repository in 47 sec.
32
+ ✅ Build of 📂ninja succeeded in 47s, results in: 📂C:\Repos\ninja\_results
32
33
33
34
```
34
35
@@ -45,16 +46,16 @@ Script Content
45
46
``` powershell
46
47
<#
47
48
.SYNOPSIS
48
- Builds a repository
49
+ Builds a repo
49
50
.DESCRIPTION
50
- This PowerShell script builds a Git repository by supporting build systems such as : autogen, cmake, configure, Gradle, Imakefile, Makefile, and Meson.
51
+ This PowerShell script builds a Git repository by supporting the build systems: autogen, cmake, configure, Gradle, Imakefile, Makefile, and Meson.
51
52
.PARAMETER path
52
- Specifies the path to the Git repository (default is current working directory)
53
+ Specifies the path to the Git repository (current working directory by default )
53
54
.EXAMPLE
54
55
PS> ./build-repo.ps1 C:\Repos\ninja
55
- ⏳ Building 📂ninja using CMakeLists.txt into 📂ninja/_Build_Results ...
56
+ ⏳ Building 📂ninja by using CMake ...
56
57
...
57
- ✅ Built 📂ninja repository in 47 sec.
58
+ ✅ Build of 📂ninja succeeded in 47s, results in: 📂C:\Repos\ninja\_results
58
59
.LINK
59
60
https://github.com/fleschutz/PowerShell
60
61
.NOTES
@@ -63,114 +64,114 @@ Script Content
63
64
64
65
param([string]$path = "$PWD")
65
66
66
- function BuildInDir ([string]$path) {
67
+ function BuildFolder ([string]$path) {
67
68
$dirName = (Get-Item "$path").Name
68
69
if (Test-Path "$path/CMakeLists.txt" -pathType leaf) {
69
- "⏳ (1/4) Building 📂$dirName by using CMake into 📂$dirName/_Build_Results..."
70
- if (-not(Test-Path "$path/_Build_Results/" -pathType container)) {
71
- & mkdir "$path/_Build_Results/"
70
+ "⏳ (1/4) Building 📂$dirName by using CMake..."
71
+ $global:results = "$path/_results/"
72
+ if (-not(Test-Path $global:results -pathType container)) {
73
+ & mkdir $global:results
72
74
}
73
- Set-Location "$path/_Build_Results/"
75
+ Set-Location $global:results
74
76
75
77
"⏳ (2/4) Executing 'cmake' to generate the Makefile..."
76
78
& cmake ..
77
- if ($lastExitCode -ne "0" ) { throw "Executing 'cmake ..' exited with error code $lastExitCode" }
79
+ if ($lastExitCode -ne 0 ) { throw "Executing 'cmake ..' failed with exit code $lastExitCode" }
78
80
79
81
"⏳ (3/4) Executing 'make -j4' to compile and link..."
80
82
& make -j4
81
- if ($lastExitCode -ne "0" ) { throw "Executing 'make -j4' exited with error code $lastExitCode" }
83
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make -j4' failed with exit code $lastExitCode" }
82
84
83
- "⏳ (4/4) Executing 'ctest -V' to perform tests (optional)... "
85
+ "⏳ (4/4) Executing 'ctest -V'... (if tests are provided) "
84
86
& ctest -V
85
- if ($lastExitCode -ne "0") { throw "Executing 'ctest -V' exited with error code $lastExitCode" }
86
-
87
+ if ($lastExitCode -ne 0) { throw "Executing 'ctest -V' failed with exit code $lastExitCode" }
87
88
} elseif (Test-Path "$path/autogen.sh" -pathType leaf) {
88
- "⏳ Building 📂$dirName by using 'autogen.sh'..."
89
+ "⏳ Building 📂$dirName by executing 'autogen.sh'..."
89
90
Set-Location "$path/"
90
-
91
91
& ./autogen.sh --force
92
- if ($lastExitCode -ne "0") { throw "Executing './autogen.sh --force' exited with error code $lastExitCode" }
92
+ if ($lastExitCode -ne 0) { throw "Executing './autogen.sh --force' failed with exit code $lastExitCode" }
93
+ "⏳ Executing './configure'..."
93
94
94
95
& ./configure
95
- if ($lastExitCode -ne "0" ) { throw "Executing './configure' exited with error code $lastExitCode" }
96
+ if ($lastExitCode -ne 0 ) { throw "Executing './configure' failed with exit code $lastExitCode" }
96
97
97
98
& make -j4
98
- if ($lastExitCode -ne "0") { throw "Executing 'make -j4' exited with error code $lastExitCode" }
99
-
99
+ if ($lastExitCode -ne 0) { throw "Executing 'make -j4' failed with exit code $lastExitCode" }
100
100
101
101
} elseif (Test-Path "$path/configure" -pathType leaf) {
102
- "⏳ Building 📂$dirName by using ' configure'..."
102
+ "⏳ Building 📂$dirName by executing './ configure' and 'make '..."
103
103
Set-Location "$path/"
104
104
105
105
& ./configure
106
- #if ($lastExitCode -ne "0" ) { throw "Executing './configure' exited with error code $lastExitCode" }
106
+ #if ($lastExitCode -ne 0 ) { throw "Executing './configure' exited with error code $lastExitCode" }
107
107
108
108
& make -j4
109
- if ($lastExitCode -ne "0" ) { throw "Executing 'make -j4' has failed" }
109
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make -j4' failed with exit code $lastExitCode " }
110
110
111
111
& make test
112
- if ($lastExitCode -ne "0" ) { throw "Executing 'make test' has failed" }
112
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make test' failed with exit code $lastExitCode " }
113
113
114
114
} elseif (Test-Path "$path/build.gradle" -pathType leaf) {
115
115
"⏳ Building 📂$dirName by using Gradle..."
116
116
Set-Location "$path"
117
117
118
118
& gradle build
119
- if ($lastExitCode -ne "0" ) { throw "Executing 'gradle build' exited with error code $lastExitCode" }
119
+ if ($lastExitCode -ne 0 ) { throw "Executing 'gradle build' failed with exit code $lastExitCode" }
120
120
121
121
& gradle test
122
- if ($lastExitCode -ne "0" ) { throw "Executing 'gradle test' exited with error code $lastExitCode" }
122
+ if ($lastExitCode -ne 0 ) { throw "Executing 'gradle test' failed with exit code $lastExitCode" }
123
123
124
124
} elseif (Test-Path "$path/meson.build" -pathType leaf) {
125
125
"⏳ Building 📂$dirName by using Meson..."
126
126
Set-Location "$path"
127
127
& meson . build --prefix=/usr/local
128
- if ($lastExitCode -ne "0" ) { throw "Executing 'meson . build' exited with error code $lastExitCode" }
128
+ if ($lastExitCode -ne 0 ) { throw "Executing 'meson . build' failed with exit code $lastExitCode" }
129
129
130
130
} elseif (Test-Path "$path/Imakefile" -pathType leaf) {
131
131
"⏳ Building 📂$dirName by using Imakefile..."
132
132
Set-Location "$path/"
133
133
134
134
& xmkmf
135
- if ($lastExitCode -ne "0" ) { throw "Executing 'xmkmf' has failed" }
135
+ if ($lastExitCode -ne 0 ) { throw "Executing 'xmkmf' failed with exit code $lastExitCode " }
136
136
137
137
& make -j4
138
- if ($lastExitCode -ne "0" ) { throw "Executing 'make -j4' has failed" }
138
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make -j4' failed with exit code $lastExitCode " }
139
139
140
140
} elseif (Test-Path "$path/Makefile" -pathType leaf) {
141
141
"⏳ Building 📂$dirName by using Makefile..."
142
142
Set-Location "$path"
143
143
144
144
& make -j4
145
- if ($lastExitCode -ne "0" ) { throw "Executing 'make -j4' has failed" }
145
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make -j4' failed with exit code $lastExitCode " }
146
146
147
147
} elseif (Test-Path "$path/makefile" -pathType leaf) {
148
148
"⏳ Building 📂$dirName by using makefile..."
149
149
Set-Location "$path"
150
150
151
151
& make -j4
152
- if ($lastExitCode -ne "0" ) { throw "Executing 'make -j4' has failed" }
152
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make -j4' failed with exit code $lastExitCode " }
153
153
154
154
} elseif (Test-Path "$path/compile.sh" -pathType leaf) {
155
- "⏳ Building 📂$dirName by using 'compile.sh'..."
155
+ "⏳ Building 📂$dirName by executing 'compile.sh'..."
156
156
Set-Location "$path/"
157
157
158
158
& ./compile.sh
159
- if ($lastExitCode -ne "0" ) { throw "Executing './compile.sh' exited with error code $lastExitCode" }
159
+ if ($lastExitCode -ne 0 ) { throw "Executing './compile.sh' failed with exit code $lastExitCode" }
160
160
161
161
& make -j4
162
- if ($lastExitCode -ne "0" ) { throw "Executing 'make -j4' has failed" }
162
+ if ($lastExitCode -ne 0 ) { throw "Executing 'make -j4' failed with exit code $lastExitCode " }
163
163
164
164
} elseif (Test-Path "$path/attower/src/build/DevBuild/build.bat" -pathType leaf) {
165
- "⏳ Building 📂$dirName by using build.bat ..."
166
- Set-Location "$path/attower/src/build/DevBuild/"
167
165
168
- & ./build.bat build-all-release
169
- if ($lastExitCode -ne "0") { throw "Executing 'build.bat build-all-release' exited with error code $lastExitCode" }
166
+ Write-Host "⏳ Building 📂$dirName by executing 'build.bat'..."
167
+ Set-Location "$path/attower/src/build/DevBuild/"
168
+ & ./build.bat build-core-release
169
+ if ($lastExitCode -ne 0) { throw "Executing 'build.bat' failed with exit code $lastExitCode" }
170
+ $global:results = "$path\attower\Executables"
170
171
171
172
} elseif (Test-Path "$path/$dirName" -pathType container) {
172
173
"⏳ No make rule found, trying subfolder 📂$($dirName)..."
173
- BuildInDir "$path/$dirName"
174
+ BuildFolder "$path/$dirName"
174
175
} else {
175
176
Write-Warning "Sorry, no make rule applies to: 📂$dirName"
176
177
exit 0 # success
@@ -179,21 +180,27 @@ function BuildInDir([string]$path) {
179
180
180
181
try {
181
182
$stopWatch = [system.diagnostics.stopwatch]::startNew()
183
+ $previousPath = Get-Location
182
184
183
- if (-not(Test-Path "$path" -pathType container)) { throw "Can't access directory: $path" }
185
+ if (-not(Test-Path "$path" -pathType container)) { throw "The file path ' $path' doesn't exist (yet) " }
184
186
185
- $previousPath = Get-Location
186
- BuildInDir "$path"
187
+ $global:results = ""
188
+ BuildFolder "$path"
187
189
Set-Location "$previousPath"
188
190
189
191
$repoDirName = (Get-Item "$path").Name
190
192
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
191
- "✅ Built 📂$repoDirName repository in $elapsed sec."
193
+ if ($global:results -eq "") {
194
+ "✅ Build of 📂$repoDirName succeeded in $($elapsed)s."
195
+ } else {
196
+ "✅ Build of 📂$repoDirName succeeded in $($elapsed)s, results in: 📂$($global:results)"
197
+ }
192
198
exit 0 # success
193
199
} catch {
194
200
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
201
+ Set-Location "$previousPath"
195
202
exit 1
196
203
}
197
204
```
198
205
199
- * (page generated by convert-ps2md.ps1 as of 01/23 /2025 12:15:19 )*
206
+ * (page generated by convert-ps2md.ps1 as of 05/12 /2025 22:02:52 )*
0 commit comments