Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
admercs committed Feb 26, 2024
1 parent dbc6690 commit 04fb8e7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 52 deletions.
129 changes: 85 additions & 44 deletions UnrealPlugin/Unreal/Environments/Blocks/scripts/package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DESCRIPTION:
AUTHOR:
Adam Erickson (Nervosys)
DATE:
11-17-2023
2024-02-26
NOTES:
Assumes: PowerShell version >= 7 and Visual Studio 2022 (version 17).
Script is meant to run from AutonomySim\Unreal\Environments\<Name> directory.
Expand All @@ -16,74 +16,115 @@ NOTES:
USAGE:
`powershell scripts\package.ps1`
Copyright © 2023 Nervosys, LLC
Copyright © 2024 Nervosys, LLC
#>

# Command-line arguments
# Command-line interface (CLI) arguments
param(
[Parameter(Mandatory=$true, HelpMessage='Path to directory for package outputs.')]
[Parameter(Mandatory, HelpMessage='Path to directory for package outputs.')]
[String]
$PackageOutputsDir,
[Parameter(HelpMessage='Path to directory containing Unreal Engine build tools.')]
[Parameter(HelpMessage='Unreal Engine version in the format: MAJOR.MINOR')]
[String]
$UnrealBuildToolsDir = "${env:ProgramFiles}\Epic Games\UE_${UNREAL_VERSION}\Engine\Build\BatchFiles",
[Parameter(HelpMessage="Unreal Engine version in format 'MAJOR.MINOR'.")]
$UnrealVersion,
[Parameter(HelpMessage='Path to directory containing Unreal Engine build tools.')]
[String]
$UnrealVersion = '5.3'
$UnrealBuildToolsDir
)

###
### Variables
###

# Static variables
$WORKING_DIR = "$PWD"

# Command-line arguments
$PACKAGE_OUTPUTS_DIR = $PackageOutputsDir
$UNREAL_BUILDTOOLS_DIR = $UnrealBuildToolsDir
$UNREAL_VERSION = $UnrealVersion
[String]$UNREAL_VERSION = '5.3'
[String]$UNREAL_BUILD_TOOLS_DIR = "${env:ProgramFiles}\Epic Games\UE_${UNREAL_VERSION}\Engine\Build\BatchFiles"

# Dynamic variables
[String]$WORKING_DIR = "$PWD"

###
### Main
### Functions
###

Write-Output ''
Write-Output '-----------------------------------------------------------------------------------------'
Write-Output ' Parameters'
Write-Output '-----------------------------------------------------------------------------------------'
Write-Output " Unreal build tools directory: $UNREAL_BUILDTOOLS_DIR"
Write-Output " Package outputs directory: $PACKAGE_OUTPUTS_DIR"
Write-Output '-----------------------------------------------------------------------------------------'
Write-Output ''

if ( -not (Test-Path -LiteralPath $UNREAL_BUILDTOOLS_DIR) ) {
Write-Error "Unreal Engine batch files path not found: $UNREAL_BUILDTOOLS_DIR" -ErrorAction Stop
}
function Build-UnrealProject {
[OutputType()]
param(
[Parameter(Mandatory, HelpMessage='Path to directory for package outputs.')]
[String]
$PackageOutputsDir,
[Parameter(HelpMessage="Unreal Engine version in the format: 'MAJOR.MINOR'")]
[String]
$UnrealVersion = $UNREAL_VERSION,
[Parameter(HelpMessage='Path to directory containing Unreal Engine build tools.')]
[String]
$UnrealBuildToolsDir = $UNREAL_BUILD_TOOLS_DIR
)

if ( -not (Test-Path -LiteralPath $PACKAGE_OUTPUTS_DIR) ) {
Write-Error "Package output directory path not found: $PACKAGE_OUTPUTS_DIR" -ErrorAction Stop
}
if ( $Verbose.IsPresent ) {
Write-Output ""
Write-Output "-----------------------------------------------------------------------------------------"
Write-Output " Parameters"
Write-Output "-----------------------------------------------------------------------------------------"
Write-Output " Unreal build tools directory: ${UNREAL_BUILDTOOLS_DIR}"
Write-Output " Package outputs directory: ${PACKAGE_OUTPUTS_DIR}"
Write-Output "-----------------------------------------------------------------------------------------"
Write-Output ""
}

if ( -not (Test-Path -LiteralPath "$UNREAL_BUILDTOOLS_DIR") ) {
Write-Error "Unreal Engine batch files path not found: ${UNREAL_BUILDTOOLS_DIR}" -ErrorAction Stop
}

if ( -not (Test-Path -LiteralPath "$PACKAGE_OUTPUTS_DIR") ) {
Write-Error "Package output directory path not found: ${PACKAGE_OUTPUTS_DIR}" -ErrorAction Stop
}

$ProjectFiles = Get-ChildItem -Path *.uproject -File | Select-Object FullName

foreach ( $ProjectFile in $ProjectFiles ) {
[String]$ProjectName = [System.IO.Path]::GetFileNameWithoutExtension($ProjectFile.FullName)
if ( $Verbose.IsPresent ) { Write-Output "Packaging Unreal project: ${ProjectName}" }

$ProjectFiles = Get-ChildItem -Path *.uproject -File | Select-Object FullName
foreach ($ProjectFile in $ProjectFiles) {
$ProjectName = [System.IO.Path]::GetFileNameWithoutExtension($ProjectFile.FullName)
Write-Output "Packaging: $ProjectName"
Start-Process -FilePath "${UNREAL_BUILDTOOLS_DIR}\Build.bat" -ArgumentList "${ProjectName}Editor",'Win64',
'Development','-WarningsAsErrors',"$WORKING_DIR\$ProjectFile" -Wait -NoNewWindow
if ( ! $? ) { exit $LastExitCode } # exit on error

Start-Process -FilePath "$UNREAL_BUILDTOOLS_DIR\Build.bat" -ArgumentList "${ProjectName}Editor",'Win64','Development','-WarningsAsErrors',"$WORKING_DIR\$ProjectFile" -Wait -NoNewWindow
if (!$?) { exit $LASTEXITCODE } # exit on error
# "%ToolPath%\RunUAT" -ScriptsForProject="%cd%\%%f" BuildCookRun -installed -nop4 -project="%cd%\%%f" -cook -stage -archive -archivedirectory="%OutPath%" -package -clientconfig=Development -ue4exe=UE4Editor-Cmd.exe -compressed -pak -prereqs -nodebuginfo -targetplatform=Win64 -build -utf8output -nocompile -nocompileeditor
# "%ToolPath%\RunUAT" BuildCookRun -project="%cd%\%%f" -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -rocket -allmaps -build -stage -NoCompile -nocompileeditor -pak -archive -archivedirectory="%OutPath%"
# Start-Process -FilePath "${UnrealBuildToolsDir}\RunUAT" -ArgumentList "-ScriptsForProject=${PWD}$\${ProjectFile}",
# 'BuildCookRun', '-installed', '-nop4', "-project=${PWD}\${ProjectFile}", '-cook', '-stage', '-archive',
# "-archivedirectory=${PackageOutputsDir}", '-package', '-clientconfig=Development', '-ue4exe=UE4Editor-Cmd.exe',
# '-compressed', '-pak', '-prereqs', '-nodebuginfo', '-targetplatform=Win64', '-build', '-utf8output', '-nocompile',
# '-nocompileeditor' -Wait -NoNewWindow -ErrorAction Stop

Remove-Item -Path "$PACKAGE_OUTPUTS_DIR\$ProjectName" -Recurse -Force
Start-Process -FilePath "$UNREAL_BUILDTOOLS_DIR\RunUAT.bat" -ArgumentList 'BuildCookRun',"-project=$WORKING_DIR\$ProjectFile",'-noP4','-platform=Win64','-clientconfig=Development','-cook','-build','-stage','-pak','-archive',"-archivedirectory=$PACKAGE_OUTPUTS_DIR",'-utf8output','-compressed','-prereqs' -Wait -NoNewWindow
if (!$?) { exit $LASTEXITCODE } # exit on error
# Start-Process -FilePath "${UnrealBuildToolsDir}\RunUAT" -ArgumentList "-ScriptsForProject=${PWD}\${ProjectFile}",
# 'BuildCookRun', '-installed', '-nop4', "-project=${PWD}\${ProjectFile}", '-cook', '-stage', '-archive',
# "-archivedirectory=${ProjectOutputsDir}", '-package', '-clientconfig=Development', '-ue4exe=UE4Editor-Cmd.exe',
# '-compressed', '-pak', '-prereqs', '-nodebuginfo', '-targetplatform=Win64', '-build', '-utf8output', '-nocompile',
# '-nocompileeditor' -Wait -NoNewWindow -ErrorAction Stop

Move-Item -Path "$PACKAGE_OUTPUTS_DIR\WindowsNoEditor" -Destination "$PACKAGE_OUTPUTS_DIR\$ProjectName" -Force
"start $ProjectName -windowed" | Out-File -Encoding 'ascii' -FilePath "$PACKAGE_OUTPUTS_DIR\$ProjectName\run.cmd"
Write-Output "Unreal project packaging complete: $ProjectName"
# Start-Process -FilePath "${UnrealBuildToolsDir}\RunUAT" -ArgumentList 'BuildCookRun', "-project=${PWD}\${ProjectFile}",
# '-noP4', '-platform=Win64', '-clientconfig=Development', '-serverconfig=Development', '-cook', '-rocket', '-allmaps',
# '-build', '-stage', '-NoCompile', '-nocompileeditor', '-pak', '-archive', "-archivedirectory=${ProjectOutputsDir}"
# -Wait -NoNewWindow -ErrorAction Stop

Remove-Item -Path "${PACKAGE_OUTPUTS_DIR}\${ProjectName}" -Recurse -Force

Start-Process -FilePath "$UNREAL_BUILDTOOLS_DIR\RunUAT.bat" -ArgumentList 'BuildCookRun',"-project=${WORKING_DIR}\${ProjectFile}",
'-noP4','-platform=Win64','-clientconfig=Development','-cook','-build','-stage','-pak','-archive',"-archivedirectory=${PACKAGE_OUTPUTS_DIR}",
'-utf8output','-compressed','-prereqs' -Wait -NoNewWindow
if ( ! $? ) { exit $LastExitCode } # exit on error

Move-Item -Path "$PACKAGE_OUTPUTS_DIR\WindowsNoEditor" -Destination "$PACKAGE_OUTPUTS_DIR\$ProjectName" -Force
"start ${ProjectName} -windowed" | Out-File -Encoding 'ascii' -FilePath "${PACKAGE_OUTPUTS_DIR}\${ProjectName}\run.cmd"
if ( $Verbose.IsPresent ) { Write-Output "Unreal project packaging complete: $ProjectName" }
}
return $null
}

###
### Main
###

Build-UnrealProject -PackageOutputsDir "$PackageOutputsDir" -UnrealVersion "$UnrealVersion" -UnrealBuildToolsDir "$UnrealBuildToolsDir"

exit 0
9 changes: 5 additions & 4 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ $CMAKE_VERSION = Get-ProgramVersion -Program 'cmake'
### Functions
###

# Compile AutonomySim.sln, which will also compile MavLinkCom.
function Build-Solution {
[OutputType()]
param(
Expand All @@ -118,14 +119,14 @@ function Build-Solution {
[String]$IgnoreErrorCodes = $IgnoreErrors -Join ';'
if ( $BuildMode -eq 'Release' ) {
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}",
"/p:Platform=${SystemPlatform}", "/p:Configuration=Debug", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Continue
"/p:Platform=${SystemPlatform}", "/p:Configuration=Debug", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}",
"/p:Platform=${SystemPlatform}", "/p:Configuration=Release", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Continue
"/p:Platform=${SystemPlatform}", "/p:Configuration=Release", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
}
else {
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}", "/p:Platform=${SystemPlatform}", "/p:Configuration=${BuildMode}", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Continue
Start-Process -FilePath 'msbuild.exe' -ArgumentList "-maxcpucount:${SystemCpuMax}", "-noerr:${IgnoreErrorCodes}", "/p:Platform=${SystemPlatform}", "/p:Configuration=${BuildMode}", 'AutonomySim.sln' -Wait -NoNewWindow -ErrorAction Stop
}
if (!$?) { exit $LASTEXITCODE } # exit on error
if ( ! $? ) { exit $LastExitCode } # exit on error
return $null
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/clean.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ function CleanBuild {
Remove-Item -Path $LibPaths -Force -Recurse
# Run MSBuild Clean for Debug and Release.
Start-Process -FilePath 'msbuild.exe' -ArgumentList "/p:Platform=x64", '/p:Configuration=Debug', '/t:Clean', 'AutonomySim.sln' -Wait -NoNewWindow
if (!$?) { exit $LASTEXITCODE } # exit on error
if ( ! $? ) { exit $LastExitCode } # exit on error
Start-Process -FilePath 'msbuild.exe' -ArgumentList "/p:Platform=x64", '/p:Configuration=Release', '/t:Clean', 'AutonomySim.sln' -Wait -NoNewWindow
if (!$?) { exit $LASTEXITCODE } # exit on error
if ( ! $? ) { exit $LastExitCode } # exit on error
return $null
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/git_commit_all.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function Update-GitRepositories {
Start-Process -FilePath 'git.exe' -ArgumentList 'commit', "-m ${CommitMessage}" -Wait -NoNewWindow
Start-Process -FilePath 'git.exe' -ArgumentList 'push' -Wait -NoNewWindow
# Exit on error; $LastExitCode = $true || $false
if (!$?) {
if ( ! $? ) {
Write-Error "Usage: ${SCRIPT_DIR}\git_commit_all.ps1 <repo root> <commit message>" -ErrorAction Continue
Invoke-Fail -ErrorMessage "Error: Failed to update git repositories."
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/mod_rpclib.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function Build-RpcLib {
else {
Start-Process -FilePath 'cmake.exe' -ArgumentList '--build', '.', "--config ${BUILD_MODE}" -Wait -NoNewWindow
}
if (!$?) { exit $LASTEXITCODE } # exit on subprocess error
if ( ! $? ) { exit $LastExitCode } # exit on subprocess error
Set-Location "$PROJECT_DIR"
if ( $Verbose.IsPresent ) { Write-Output "Current directory: ${PROJECT_DIR}" }
# Copy rpclib binaries and include folder inside AutonomyLib folder
Expand Down

0 comments on commit 04fb8e7

Please sign in to comment.