Fix AOT libs cooking to avoid file dirtying for more accurate iterative cooking

This commit is contained in:
Wojtek Figat
2025-11-26 00:02:40 -08:00
parent 92254eefcc
commit bea75f51bd
5 changed files with 48 additions and 7 deletions

View File

@@ -462,7 +462,7 @@ namespace Flax.Build
else
{
// Copy to the destination folder
Utilities.FileCopy(assemblyPath, Path.Combine(dotnetOutputPath, assemblyFileName));
Utilities.FileCopy(assemblyPath, Path.Combine(dotnetOutputPath, assemblyFileName), Utilities.CopyMode.OverrideIfNewer);
}
};
if (Configuration.MaxConcurrency > 1 && Configuration.ConcurrencyProcessorScale > 0.0f && !dotnetAotDebug)

View File

@@ -42,7 +42,8 @@ namespace Flax.Build
BinaryModuleName = "FlaxEngine";
options.ScriptingAPI.Defines.Add("FLAX");
options.ScriptingAPI.Defines.Add("FLAX_ASSERTIONS");
options.ScriptingAPI.FileReferences.Add(Utilities.RemovePathRelativeParts(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "DotNet", "Newtonsoft.Json.dll")));
var newtonsoftJsonPath = options.Platform?.HasDynamicCodeExecutionSupport ?? true ? "Newtonsoft.Json.dll" : "AOT/Newtonsoft.Json.dll";
options.ScriptingAPI.FileReferences.Add(Utilities.RemovePathRelativeParts(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "DotNet", newtonsoftJsonPath)));
options.ScriptingAPI.SystemReferences.Add("System.ComponentModel.TypeConverter");
}
}

View File

@@ -144,24 +144,51 @@ namespace Flax.Build
return new TwoWayEnumerator<T>(source.GetEnumerator());
}
/// <summary>
/// File copy modes.
/// </summary>
public enum CopyMode
{
/// <summary>
/// Copies the file to the destination, fails if it already exists.
/// </summary>
New,
/// <summary>
/// If destination file exists, it will be overriden.
/// </summary>
OverrideIfExists,
/// <summary>
/// If destination file exists, has the same size and is newer than source file, it won't be overriden (avoids unnecessary copies).
/// </summary>
OverrideIfNewer,
}
/// <summary>
/// Copies the file.
/// </summary>
/// <param name="srcFilePath">The source file path.</param>
/// <param name="dstFilePath">The destination file path.</param>
/// <param name="overwrite"><see langword="true" /> if the destination file can be overwritten; otherwise, <see langword="false" />.</param>
public static void FileCopy(string srcFilePath, string dstFilePath, bool overwrite = true)
/// <param name="mode">Copy operation modes.</param>
public static void FileCopy(string srcFilePath, string dstFilePath, CopyMode mode = CopyMode.OverrideIfExists)
{
if (string.IsNullOrEmpty(srcFilePath))
throw new ArgumentNullException(nameof(srcFilePath));
if (string.IsNullOrEmpty(dstFilePath))
throw new ArgumentNullException(nameof(dstFilePath));
if (mode == CopyMode.OverrideIfNewer &&
File.Exists(dstFilePath) &&
File.GetLastWriteTime(srcFilePath) <= File.GetLastWriteTime(dstFilePath) &&
new FileInfo(dstFilePath).Length == new FileInfo(srcFilePath).Length)
return;
Log.Verbose(srcFilePath + " -> " + dstFilePath);
try
{
File.Copy(srcFilePath, dstFilePath, overwrite);
File.Copy(srcFilePath, dstFilePath, mode != CopyMode.New);
}
catch (Exception ex)
{
@@ -173,6 +200,17 @@ namespace Flax.Build
}
}
/// <summary>
/// Copies the file.
/// </summary>
/// <param name="srcFilePath">The source file path.</param>
/// <param name="dstFilePath">The destination file path.</param>
/// <param name="overwrite"><see langword="true" /> if the destination file can be overwritten; otherwise, <see langword="false" />.</param>
public static void FileCopy(string srcFilePath, string dstFilePath, bool overwrite)
{
FileCopy(srcFilePath, dstFilePath, overwrite ? CopyMode.OverrideIfExists : CopyMode.New);
}
/// <summary>
/// Copies the directories.
/// </summary>