From 5a96c0e7176fdd526edda8058906abd280b43c43 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 31 Mar 2023 18:23:50 +0200 Subject: [PATCH] Add AOT cache invalidation when AOT Mode gets changed for next iterative cook --- .../Cooker/Steps/PrecompileAssembliesStep.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp b/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp index 549da870a..a23ebcdfb 100644 --- a/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp +++ b/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp @@ -2,6 +2,7 @@ #include "PrecompileAssembliesStep.h" #include "Engine/Platform/FileSystem.h" +#include "Engine/Platform/File.h" #include "Engine/Core/Config/BuildSettings.h" #include "Engine/Engine/Globals.h" #include "Editor/Scripting/ScriptsBuilder.h" @@ -16,6 +17,24 @@ void PrecompileAssembliesStep::OnBuildStarted(CookingData& data) // Redirect C# assemblies to intermediate cooking directory (processed by ILC) data.ManagedCodeOutputPath = data.CacheDirectory / TEXT("AOTAssemblies"); + + // Reset any AOT cache from previous run if the AOT mode has changed (eg. Mono AOT -> ILC on Desktop) + const String aotModeCacheFilePath = data.ManagedCodeOutputPath / TEXT("AOTMode.txt"); + const String aotModeCacheValue = StringUtils::ToString((int32)aotMode); + if (FileSystem::DirectoryExists(data.ManagedCodeOutputPath)) + { + String cachedData; + File::ReadAllText(aotModeCacheFilePath, cachedData); + if (cachedData != aotModeCacheValue) + { + FileSystem::DeleteDirectory(data.ManagedCodeOutputPath); + } + } + if (!FileSystem::DirectoryExists(data.ManagedCodeOutputPath)) + { + FileSystem::CreateDirectory(data.ManagedCodeOutputPath); + File::WriteAllText(aotModeCacheFilePath, aotModeCacheValue, Encoding::ANSI); + } } bool PrecompileAssembliesStep::Perform(CookingData& data)