Last active
December 17, 2024 07:23
-
-
Save sbseltzer/0e52dc4126c819e6d3fc2faf7ddcc4c1 to your computer and use it in GitHub Desktop.
Example of a prebuild file for an Unreal plugin that replaces preprocessor code marked up with version information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$EngineVersionData = ((Get-Content $Env:EngineDir/Build/Build.version) | ConvertFrom-JSON) | |
$EngineVersion = "$($EngineVersionData.MajorVersion).$($EngineVersionData.MinorVersion)" | |
function IsDecimal($value){ | |
Try{ | |
[System.Decimal]$value | Out-Null | |
$true | |
} Catch { | |
$false | |
} | |
} | |
function ReplaceVersionMacrosForVersion($file, $version_decimal, $version_macro) | |
{ | |
$disabled_text = "#if 0 // " + $version_macro | |
$enabled_text = "#if 1 // " + $version_macro | |
$content = (Get-Content $file) | |
if ([System.Decimal]$EngineVersion -ge [System.Decimal]$version_decimal) | |
{ | |
if ($content -like "*$disabled_text*") | |
{ | |
Write-Output "Enabling $version_macro block in $file" | |
$content -replace $disabled_text, $enabled_text | Out-File $file | |
} | |
} | |
else | |
{ | |
if ($content -like "*$enabled_text*") | |
{ | |
Write-Output "Disabling $version_macro block in $file" | |
$content -replace $enabled_text, $disabled_text | Out-File $file | |
} | |
} | |
} | |
function ReplaceVersionMacros($file) | |
{ | |
ReplaceVersionMacrosForVersion $file "4.17" "UE_4_17_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.18" "UE_4_18_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.19" "UE_4_19_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.20" "UE_4_20_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.21" "UE_4_21_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.22" "UE_4_22_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.23" "UE_4_23_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.24" "UE_4_24_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.25" "UE_4_25_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.26" "UE_4_26_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "4.27" "UE_4_27_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "5.0" "UE_5_0_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "5.1" "UE_5_1_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "5.2" "UE_5_2_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "5.3" "UE_5_3_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "5.4" "UE_5_4_OR_LATER" | |
ReplaceVersionMacrosForVersion $file "5.5" "UE_5_5_OR_LATER" | |
} | |
if (IsDecimal($EngineVersion)) | |
{ | |
Get-ChildItem -Path "$Env:PluginDir\Source\" -Recurse -Include *.h,*.cpp,*.c,*.inl,*.hpp | | |
Foreach-Object { | |
ReplaceVersionMacros($_.FullName) | |
} | |
} | |
else | |
{ | |
Write-Output "Failed to recognize Engine Version: $EngineVersion" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment