From 04fb8e79b3ccaefcf2d4ec5b4530c2a9c1d34e92 Mon Sep 17 00:00:00 2001 From: admercs Date: Mon, 26 Feb 2024 11:06:51 -0800 Subject: [PATCH] update scripts --- .../Environments/Blocks/scripts/package.ps1 | 129 ++++++++++++------ scripts/build.ps1 | 9 +- scripts/clean.ps1 | 4 +- scripts/git_commit_all.ps1 | 2 +- scripts/mod_rpclib.psm1 | 2 +- 5 files changed, 94 insertions(+), 52 deletions(-) diff --git a/UnrealPlugin/Unreal/Environments/Blocks/scripts/package.ps1 b/UnrealPlugin/Unreal/Environments/Blocks/scripts/package.ps1 index 27f7ba1b..fc7b42e6 100644 --- a/UnrealPlugin/Unreal/Environments/Blocks/scripts/package.ps1 +++ b/UnrealPlugin/Unreal/Environments/Blocks/scripts/package.ps1 @@ -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\ directory. @@ -16,20 +16,20 @@ 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 ) ### @@ -37,53 +37,94 @@ param( ### # 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 diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 7ad892e8..41b4a21f 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -99,6 +99,7 @@ $CMAKE_VERSION = Get-ProgramVersion -Program 'cmake' ### Functions ### +# Compile AutonomySim.sln, which will also compile MavLinkCom. function Build-Solution { [OutputType()] param( @@ -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 } diff --git a/scripts/clean.ps1 b/scripts/clean.ps1 index 63a7ed35..ac574619 100644 --- a/scripts/clean.ps1 +++ b/scripts/clean.ps1 @@ -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 } diff --git a/scripts/git_commit_all.ps1 b/scripts/git_commit_all.ps1 index 61ba7d45..4ad5b3ef 100644 --- a/scripts/git_commit_all.ps1 +++ b/scripts/git_commit_all.ps1 @@ -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 " -ErrorAction Continue Invoke-Fail -ErrorMessage "Error: Failed to update git repositories." } diff --git a/scripts/mod_rpclib.psm1 b/scripts/mod_rpclib.psm1 index 74a3221c..30f5fa49 100644 --- a/scripts/mod_rpclib.psm1 +++ b/scripts/mod_rpclib.psm1 @@ -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