diff --git a/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp b/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp index c0a8e452a..1fdb1e7c0 100644 --- a/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp +++ b/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp @@ -10,9 +10,10 @@ #include "Engine/Serialization/JsonTools.h" #include "Engine/Serialization/JsonWriters.h" #include "Editor/Cooker/PlatformTools.h" +#include "Engine/Engine/Globals.h" #include "Editor/Editor.h" #include "Editor/ProjectInfo.h" -#include "Engine/Engine/Globals.h" +#include "Editor/Utilities/EditorUtilities.h" #if PLATFORM_MAC #include #endif @@ -127,7 +128,7 @@ bool CompileScriptsStep::DeployBinaries(CookingData& data, const String& path, c const String dst = dstPath / StringUtils::GetFileName(file); if (dst == file) continue; - if (FileSystem::CopyFile(dst, file)) + if (EditorUtilities::CopyFileIfNewer(dst, file)) { data.Error(String::Format(TEXT("Failed to copy file from {0} to {1}."), file, dst)); return true; diff --git a/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp b/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp index 472a3cca6..626b532a6 100644 --- a/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp +++ b/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp @@ -59,6 +59,7 @@ bool PrecompileAssembliesStep::Perform(CookingData& data) data.StepProgress(infoMsg, 0); // Override Newtonsoft.Json with AOT-version (one that doesn't use System.Reflection.Emit) + // TODO: remove it since EngineModule does properly reference AOT lib now EditorUtilities::CopyFileIfNewer(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.dll"), Globals::StartupFolder / TEXT("Source/Platforms/DotNet/AOT/Newtonsoft.Json.dll")); FileSystem::DeleteFile(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.xml")); FileSystem::DeleteFile(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.pdb")); diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetAOT.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetAOT.cs index e421b6999..96551a91d 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetAOT.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetAOT.cs @@ -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) diff --git a/Source/Tools/Flax.Build/Build/EngineModule.cs b/Source/Tools/Flax.Build/Build/EngineModule.cs index 679a558d2..5fc470665 100644 --- a/Source/Tools/Flax.Build/Build/EngineModule.cs +++ b/Source/Tools/Flax.Build/Build/EngineModule.cs @@ -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"); } } diff --git a/Source/Tools/Flax.Build/Utilities/Utilities.cs b/Source/Tools/Flax.Build/Utilities/Utilities.cs index 0ce5c8b7b..917b8aa77 100644 --- a/Source/Tools/Flax.Build/Utilities/Utilities.cs +++ b/Source/Tools/Flax.Build/Utilities/Utilities.cs @@ -144,24 +144,51 @@ namespace Flax.Build return new TwoWayEnumerator(source.GetEnumerator()); } + /// + /// File copy modes. + /// + public enum CopyMode + { + /// + /// Copies the file to the destination, fails if it already exists. + /// + New, + + /// + /// If destination file exists, it will be overriden. + /// + OverrideIfExists, + + /// + /// If destination file exists, has the same size and is newer than source file, it won't be overriden (avoids unnecessary copies). + /// + OverrideIfNewer, + } + /// /// Copies the file. /// /// The source file path. /// The destination file path. - /// if the destination file can be overwritten; otherwise, . - public static void FileCopy(string srcFilePath, string dstFilePath, bool overwrite = true) + /// Copy operation modes. + 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 } } + /// + /// Copies the file. + /// + /// The source file path. + /// The destination file path. + /// if the destination file can be overwritten; otherwise, . + public static void FileCopy(string srcFilePath, string dstFilePath, bool overwrite) + { + FileCopy(srcFilePath, dstFilePath, overwrite ? CopyMode.OverrideIfExists : CopyMode.New); + } + /// /// Copies the directories. ///