Skip to content

Commit 041cdcf

Browse files
committed
update windows pwsh build script
1 parent e26df45 commit 041cdcf

File tree

4 files changed

+96
-68
lines changed

4 files changed

+96
-68
lines changed

scripts/build.ps1

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ $PROJECT_DIR = "$PWD"
8181
$SCRIPT_DIR = "${PROJECT_DIR}\scripts"
8282

8383
# Command-line arguments
84-
$AUTOMATE = if ( $Automate.IsPresent ) { $true } else { $false }
8584
$BUILD_MODE = "$BuildMode"
8685
$CMAKE_GENERATOR = "$CmakeGenerator"
8786
$DEBUG_MODE = if ( $SystemDebug.IsPresent ) { $true } else { $false }
8887
$UNREAL_ASSET = if ( $UnrealAsset.IsPresent ) { $true } else { $false }
8988
$BUILD_DOCS = if ( $BuildDocs.IsPresent ) { $true } else { $false }
89+
$AUTOMATE_MODE = if ( $Automate.IsPresent ) { $true } else { $false }
9090

9191
# Dynamic variables
9292
$SYSTEM_INFO = Get-ComputerInfo # WARNING: Windows only
@@ -95,7 +95,7 @@ $SYSTEM_ARCHITECTURE = "${env:PROCESSOR_ARCHITECTURE}"
9595
$SYSTEM_PLATFORM = Get-Architecture -Info $SYSTEM_INFO
9696
$SYSTEM_CPU_MAX = Set-ProcessorCount -Info $SYSTEM_INFO
9797
$SYSTEM_OS_VERSION = Get-WindowsVersion -Info $SYSTEM_INFO
98-
$VS_INSTANCE = Set-VsInstance -Automate $AUTOMATE
98+
$VS_INSTANCE = Set-VsInstance -Automate $AUTOMATE_MODE
9999
$VS_VERSION = Get-VsInstanceVersion -Config $VS_INSTANCE
100100
$CMAKE_VERSION = Get-ProgramVersion -Program 'cmake'
101101

@@ -104,31 +104,31 @@ $CMAKE_VERSION = Get-ProgramVersion -Program 'cmake'
104104
###
105105

106106
# Compile AutonomySim.sln, which will also compile MavLinkCom.
107-
function Build-Solution {
107+
function Build-AutonomySim {
108108
[OutputType()]
109109
param(
110110
[Parameter()]
111111
[String]
112-
$BuildMode = $BUILD_MODE,
113-
[Parameter(Mandatory)]
112+
$BuildMode = "$BUILD_MODE",
113+
[Parameter()]
114114
[String]
115-
$SystemPlatform,
116-
[Parameter(Mandatory)]
115+
$SystemPlatform = "$SYSTEM_PLATFORM",
116+
[Parameter()]
117117
[UInt16]
118-
$SystemCpuMax,
118+
$SystemCpuMax = $SYSTEM_CPU_MAX,
119119
[Parameter()]
120120
[String[]]
121121
$IgnoreErrors = @()
122122
)
123-
[String]$IgnoreErrorCodes = if ( $IgnoreErrors.Count -gt 0 ) { ($IgnoreErrors -Join ';') } else { '' }
124-
if ( $BuildMode -eq 'Release' ) {
125-
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}",
126-
"/p:Platform=${SystemPlatform}", "/p:Configuration=Debug", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
127-
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}",
128-
"/p:Platform=${SystemPlatform}", "/p:Configuration=Release", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
123+
[String]$IgnoreErrorCodes = if ( $IgnoreErrors.Count -gt 0 ) { '-noerr:' + ($IgnoreErrors -Join ';') } else { '' }
124+
if ( "$BuildMode" -eq 'Release' ) {
125+
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "${IgnoreErrorCodes}",
126+
"/p:Platform=${SystemPlatform}", '/p:Configuration=Debug', 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
127+
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "${IgnoreErrorCodes}",
128+
"/p:Platform=${SystemPlatform}", '/p:Configuration=Release', 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
129129
} else {
130-
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}",
131-
"/p:Platform=${SystemPlatform}", "/p:Configuration=${BuildMode}", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
130+
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "${IgnoreErrorCodes}",
131+
"/p:Platform=${SystemPlatform}", "/p:Configuration=${BuildMode}", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
132132
}
133133
if ( ! $? ) { exit $LastExitCode } # exit on error
134134
return $null
@@ -149,24 +149,24 @@ function Copy-GeneratedBinaries {
149149
)
150150
# Copy binaries and includes for MavLinkCom in deps
151151
New-Item -ItemType Directory -Path ("$MavLinkTargetLib", "$MavLinkTargetInclude") -Force | Out-Null
152-
Copy-Item -Path '.\MavLinkCom\lib' -Destination "$MavLinkTargetLib" -Recurse -Verbose
153-
Copy-Item -Path '.\MavLinkCom\include' -Destination "$MavLinkTargetInclude" -Recurse -Verbose
152+
Copy-Item -Path '.\MavLinkCom\lib' -Destination "$MavLinkTargetLib" -Recurse
153+
Copy-Item -Path '.\MavLinkCom\include' -Destination "$MavLinkTargetInclude" -Recurse
154154
# Copy outputs into Unreal/Plugins directory
155155
New-Item -ItemType Directory -Path "$AutonomyLibPluginDir" -Force | Out-Null
156-
Copy-Item -Path '.\AutonomyLib' -Destination "$AutonomyLibPluginDir" -Recurse -Verbose
157-
Copy-Item -Path '.\AutonomySim.props' -Destination "$AutonomyLibPluginDir" -Recurse -Verbose
156+
Copy-Item -Path '.\AutonomyLib' -Destination "$AutonomyLibPluginDir" -Recurse
157+
Copy-Item -Path '.\AutonomySim.props' -Destination "$AutonomyLibPluginDir" -Recurse
158158
return $null
159159
}
160160

161161
function Get-VsUnrealProjectFiles {
162162
[OutputType()]
163163
param(
164-
[Parameter(Mandatory)]
165-
[String]
166-
$UnrealEnvDir,
167164
[Parameter()]
168165
[String]
169-
$ProjectDir = "$PROJECT_DIR"
166+
$ProjectDir = "$PROJECT_DIR",
167+
[Parameter(Mandatory)]
168+
[String]
169+
$UnrealEnvDir
170170
)
171171
Set-Location "$UnrealEnvDir"
172172
# imports: Test-DirectoryPath, Copy-UnrealEnvItems, Remove-UnrealEnvItems, Invoke-VsUnrealProjectFileGenerator
@@ -188,9 +188,9 @@ function Update-VsUnrealProjectFiles {
188188
$ProjectDir = "$PROJECT_DIR",
189189
[Parameter()]
190190
[String]
191-
$UnrealEnvDir = '.\Unreal\Environments'
191+
$UnrealEnvBaseDir = '.\UnrealPlugin\Unreal\Environments'
192192
)
193-
$UnrealEnvDirs = (Get-ChildItem -Path "$UnrealEnvDir" -Directory | Select-Object FullName).FullName
193+
$UnrealEnvDirs = (Get-ChildItem -Path "$UnrealEnvBaseDir" -Directory | Select-Object FullName).FullName
194194
foreach ( $d in $UnrealEnvDirs ) {
195195
Get-VsUnrealProjectFiles -UnrealEnvDir "$d" -ProjectDir "$ProjectDir"
196196
}
@@ -220,7 +220,7 @@ if ( $Verbose.IsPresent ) {
220220
Write-Output " Build mode: $BUILD_MODE"
221221
Write-Output '-----------------------------------------------------------------------------------------'
222222
Write-Output " Debug mode: $DEBUG_MODE"
223-
Write-Output " CI/CD mode: $AUTOMATE"
223+
Write-Output " CI/CD mode: $AUTOMATE_MODE"
224224
Write-Output " Build docs: $BUILD_DOCS"
225225
Write-Output '-----------------------------------------------------------------------------------------'
226226
Write-Output " Windows version: $SYSTEM_OS_VERSION"
@@ -241,7 +241,7 @@ Test-WorkingDirectory
241241
Add-Directories -Directories @('temp', 'external', 'external\rpclib')
242242

243243
# Test Visual Studio version (optionally automated for CI/CD).
244-
Test-VsInstanceVersion -Automate $AUTOMATE
244+
Test-VsInstanceVersion -Automate $AUTOMATE_MODE
245245

246246
# Test CMake version (downloads and installs CMake).
247247
Test-CmakeVersion
@@ -250,13 +250,13 @@ Test-CmakeVersion
250250
Test-EigenVersion
251251

252252
# Test RpcLib version (downloads and builds rpclib).
253-
Test-RpcLibVersion -CmakeGenerator "$CMAKE_GENERATOR"
253+
Test-RpcLibVersion -BuildMode "$BUILD_MODE" -CmakeGenerator "$CMAKE_GENERATOR"
254254

255255
# Test high-polycount SUV asset.
256256
Test-UnrealAssetVersion -FullPolySuv $UNREAL_ASSET
257257

258258
# Compile AutonomySim.sln including MavLinkCom.
259-
Build-Solution -BuildMode "$BUILD_MODE" -SystemPlatform "$SYSTEM_PLATFORM" -SystemCpuMax "$SYSTEM_CPU_MAX"
259+
Build-AutonomySim -BuildMode "$BUILD_MODE" -SystemPlatform "$SYSTEM_PLATFORM" -SystemCpuMax "$SYSTEM_CPU_MAX"
260260

261261
# Copy binaries and includes for MavLinkCom and Unreal/Plugins.
262262
Copy-GeneratedBinaries

scripts/mod_rpclib.psm1

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ Import-Module "${PWD}\scripts\mod_utils.psm1"
2828
###
2929

3030
[String]$PROJECT_DIR = "$PWD"
31-
[String]$SCRIPT_DIR = "${PROJECT_DIR}\scripts"
31+
#[String]$SCRIPT_DIR = "${PROJECT_DIR}\scripts"
3232

3333
[Version]$RPCLIB_VERSION = '2.3.0'
3434
[String]$RCPLIB_VERSION_MAJ_MIN_BUILD = Get-VersionMajorMinorBuild -Version $RPCLIB_VERSION
35-
[String]$RPCLIB_PATH = "external\rpclib\rpclib-${RCPLIB_VERSION_MAJ_MIN_BUILD}"
35+
[String]$RPCLIB_PATH = ".\external\rpclib\rpclib-${RCPLIB_VERSION_MAJ_MIN_BUILD}"
3636
[String]$RPCLIB_URL = "https://github.com/rpclib/rpclib/archive/v${RCPLIB_VERSION_MAJ_MIN_BUILD}.zip"
3737

38+
[String]$BUILD_MODE = 'Release'
3839
[String]$CMAKE_GENERATOR = 'Visual Studio 17 2022'
3940

4041
###
@@ -46,16 +47,17 @@ function Install-RpcLib {
4647
param(
4748
[Parameter()]
4849
[String]
49-
$RpcLibPath = $RPCLIB_PATH,
50+
$RpcLibPath = "$RPCLIB_PATH",
5051
[Parameter()]
5152
[String]
52-
$RpcLibUrl = $RPCLIB_URL
53+
$RpcLibUrl = "$RPCLIB_URL"
5354
)
5455
if ( $Verbose.IsPresent ) {
5556
Write-Output '-----------------------------------------------------------------------------------------'
5657
Write-Output ' Installing rpclib...'
5758
Write-Output '-----------------------------------------------------------------------------------------'
5859
}
60+
Remove-Item '.\temp\rpclib.zip' -Force 2>$null
5961
# Set security protocol used for web requests and download rpclib
6062
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # TLS v1.2
6163
Invoke-WebRequest "$RpcLibUrl" -OutFile '.\temp\rpclib.zip' -HttpVersion '2.0'
@@ -75,46 +77,57 @@ function Build-RpcLib {
7577
param(
7678
[Parameter()]
7779
[String]
78-
$RpcLibPath = $RPCLIB_PATH,
80+
$BuildMode = "$BUILD_MODE",
81+
[Parameter()]
82+
[String]
83+
$RpcLibPath = "$RPCLIB_PATH",
7984
[Parameter(HelpMessage = 'Options: [ Visual Studio 17 2022 | Visual Studio 16 2019 ]')]
8085
[String]
81-
$CmakeGenerator = "$CMAKE_GENERATOR"
86+
$CmakeGenerator = "$CMAKE_GENERATOR",
87+
[Parameter()]
88+
[String]
89+
$RpcLibTargetLib = '.\AutonomyLib\deps\rpclib\lib\x64',
90+
[Parameter()]
91+
[String]
92+
$RpcLibTargetInclude = '.\AutonomyLib\deps\rpclib\include'
8293
)
8394
if ( $Verbose.IsPresent ) {
8495
Write-Output '-----------------------------------------------------------------------------------------'
8596
Write-Output ' Building rpclib...'
8697
Write-Output '-----------------------------------------------------------------------------------------'
8798
}
99+
if ( -not (Test-Program -Program 'cmake.exe') ) {
100+
Invoke-Fail -ErrorMessage 'Error: cmake.exe not found.'
101+
}
88102
New-Item -ItemType Directory -Path "${RpcLibPath}\build" -Force | Out-Null
89103
Set-Location "${RpcLibPath}\build"
90-
if ( $Verbose.IsPresent ) { Write-Output "Current directory: ${RpcLibPath}\build" }
104+
if ( $Verbose.IsPresent ) {
105+
Write-Output "Current directory: ${PWD}"
106+
Write-Output "Using CMake generator: ${CmakeGenerator}"
107+
}
91108
# Generate RpcLib build files
92-
Write-Output "Using CMake generator: ${CmakeGenerator}"
93109
${env:CMAKE_GENERATOR} = "$CmakeGenerator" # [System.Environment]::GetEnvironmentVariables()
94-
Start-Process -FilePath 'cmake.exe' -ArgumentList "-G `"${CmakeGenerator}"`", '..' -Wait -NoNewWindow
110+
# Generate build files
111+
Start-Process -FilePath 'cmake.exe' -ArgumentList '-G', "`"$CmakeGenerator`"", '..' -Wait -NoNewWindow
95112
# Build RpcLib
96-
if ( $BUILD_MODE -eq 'Release' ) {
113+
if ( "$BuildMode" -eq 'Release' ) {
97114
Start-Process -FilePath 'cmake.exe' -ArgumentList '--build', '.' -Wait -NoNewWindow
98-
Start-Process -FilePath 'cmake.exe' -ArgumentList '--build', '.', '--config Release' -Wait -NoNewWindow
99-
}
100-
else {
101-
Start-Process -FilePath 'cmake.exe' -ArgumentList '--build', '.', "--config ${BUILD_MODE}" -Wait -NoNewWindow
115+
Start-Process -FilePath 'cmake.exe' -ArgumentList '--build', '.', '--config', 'Release' -Wait -NoNewWindow
116+
} else {
117+
Start-Process -FilePath 'cmake.exe' -ArgumentList '--build', '.', "--config ${BuildMode}" -Wait -NoNewWindow
102118
}
103119
if ( ! $? ) { exit $LastExitCode } # exit on subprocess error
104120
Set-Location "$PROJECT_DIR"
105121
if ( $Verbose.IsPresent ) { Write-Output "Current directory: ${PROJECT_DIR}" }
106122
# Copy rpclib binaries and include folder inside AutonomyLib folder
107-
[String]$RPCLIB_TARGET_LIB = '.\AutonomyLib\deps\rpclib\lib\x64'
108-
[String]$RPCLIB_TARGET_INCLUDE = '.\AutonomyLib\deps\rpclib\include'
109-
New-Item -ItemType Directory -Path ("$RPCLIB_TARGET_LIB", "$RPCLIB_TARGET_INCLUDE") -Force | Out-Null
110-
# copy directories robustly
111-
Copy-Item -Path "${RpcLibPath}\include" -Destination "${RPCLIB_TARGET_INCLUDE}" -Recurse -Force
112-
if ( $BUILD_MODE -eq 'Release' ) {
113-
Copy-Item -Path "${RpcLibPath}\build\Debug" -Destination "${RPCLIB_TARGET_LIB}\Debug" -Recurse -Force
114-
Copy-Item -Path "${RpcLibPath}\build\Release" -Destination "${RPCLIB_TARGET_LIB}\Release" -Recurse -Force
115-
}
116-
else {
117-
Copy-Item -Path "${RpcLibPath}\build\${BUILD_MODE}" -Destination "${RPCLIB_TARGET_LIB}\$BUILD_MODE" -Recurse -Force
123+
New-Item -ItemType Directory -Path ("$RpcLibTargetLib", "$RpcLibTargetInclude") -Force | Out-Null
124+
# Copy directories to targets
125+
Copy-Item -Path "${RpcLibPath}\include" -Destination "${RpcLibTargetInclude}" -Recurse -Force
126+
if ( "$BuildMode" -eq 'Release' ) {
127+
Copy-Item -Path "${RpcLibPath}\build\Debug" -Destination "${RpcLibTargetLib}\Debug" -Recurse -Force
128+
Copy-Item -Path "${RpcLibPath}\build\Release" -Destination "${RpcLibTargetLib}\Release" -Recurse -Force
129+
} else {
130+
Copy-Item -Path "${RpcLibPath}\build\${BuildMode}" -Destination "${RpcLibTargetLib}\${BuildMode}" -Recurse -Force
118131
}
119132
return $null
120133
}
@@ -124,23 +137,25 @@ function Test-RpcLibVersion {
124137
param(
125138
[Parameter()]
126139
[String]
127-
$RpcLibPath = $RPCLIB_PATH,
128-
[Parameter(HelpMessage = 'Options: [ "Visual Studio 17 2022" | "Visual Studio 16 2019" ]')]
140+
$BuildMode = "$BUILD_MODE",
141+
[Parameter()]
142+
[String]
143+
$RpcLibPath = "$RPCLIB_PATH",
144+
[Parameter(HelpMessage = 'Options: [ Visual Studio 17 2022 | Visual Studio 16 2019 ]')]
129145
[String]
130146
$CmakeGenerator = "$CMAKE_GENERATOR"
131147
)
132148
if ( -not (Test-Path -LiteralPath "$RpcLibPath") ) {
133149
# Remove previous installations
134-
Remove-Item '.\external\rpclib' -Force -Recurse
150+
Remove-Item '.\external\rpclib' -Force -Recurse 2>$null
135151
Install-RpcLib
136-
Build-RpcLib -CmakeGenerator "$CmakeGenerator"
152+
Build-RpcLib -BuildMode "$BuildMode" -CmakeGenerator "$CmakeGenerator"
137153
# Fail if rpclib version path not found
138154
if ( -not (Test-Path -LiteralPath "$RpcLibPath") ) {
139155
Write-Error 'Error: Download and build of rpclib failed. Stopping build.' -ErrorAction SilentlyContinue
140156
Invoke-Fail -ErrorMessage "Error: Failed to download and build rpclib."
141157
}
142-
}
143-
else {
158+
} else {
144159
Write-Output "Success: rcplib version test passed."
145160
}
146161
return $null

scripts/mod_utils.psm1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ function Get-Exceptions {
9393
[String[]]$Exceptions = [AppDomain]::CurrentDomain.GetAssemblies() | foreach {
9494
try {
9595
$_.GetExportedTypes().BaseType | Where { $_.Fullname -Match 'Exception' }
96-
}
97-
catch {}
96+
} catch {}
9897
}
9998
return $Exceptions | Sort-Object -Unique
10099
}
@@ -105,6 +104,18 @@ function Get-EnvVars {
105104
return $EnvVars
106105
}
107106

107+
function Test-Program {
108+
[OutputType([Boolean])]
109+
param(
110+
[Parameter(Mandatory)]
111+
[String]
112+
$Program
113+
)
114+
$ProgramResult = (Get-Command -Name "$Program" -ErrorAction SilentlyContinue)
115+
[Boolean]$ProgramExists = if ( $null -eq $ProgramResult ) { $false } else { $true }
116+
return $ProgramExists
117+
}
118+
108119
function Get-ProgramVersion {
109120
[OutputType([Version])]
110121
param(

scripts/mod_visualstudio.psm1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ function Set-VsInstance {
6161
for ($i = 0; $i -lt $Configs.count; $i++) {
6262
$Configs[$i] | Add-Member -NotePropertyName "#" -NotePropertyValue "$i"
6363
}
64-
$DisplayProperties = @('displayName', 'instanceId', 'installationVersion', 'isPrerelease', 'installationName', 'installDate')
65-
$DisplayProperties = @('#') + $DisplayProperties
66-
$VsVersionTable = ($Configs | Format-Table -Property $DisplayProperties | Out-String | ForEach-Object { Write-Output $_ })
67-
Write-Output 'The following Visual Studio installations were found:'
68-
Write-Output $VsVersionTable
64+
if ( $Verbose.IsPresent ) {
65+
$DisplayProperties = @('displayName', 'instanceId', 'installationVersion', 'isPrerelease', 'installationName', 'installDate')
66+
$DisplayProperties = @('#') + $DisplayProperties
67+
$VsVersionTable = ($Configs | Format-Table -Property $DisplayProperties | Out-String | ForEach-Object { Write-Output $_ })
68+
Write-Output 'The following Visual Studio installations were found:'
69+
Write-Output $VsVersionTable
70+
}
6971
# If automation is enabled: select the latest version
7072
if ($Automate -eq $true) {
7173
$Selected = '0'

0 commit comments

Comments
 (0)