From bcd73a96b10c3faa1b89dc7241c94fdecd2f670f Mon Sep 17 00:00:00 2001 From: Ratin Gao Date: Fri, 12 Jan 2024 23:47:05 +0800 Subject: [PATCH] [LibExtractTask] Fix debug information section linked when `StripDebugInfo` specified, and skip up-to-date items --- Source/3rdParty/C4Lib | 2 +- Source/Tasks/LibExtractTask.cs | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Source/3rdParty/C4Lib b/Source/3rdParty/C4Lib index 9c3d99f..5af9b56 160000 --- a/Source/3rdParty/C4Lib +++ b/Source/3rdParty/C4Lib @@ -1 +1 @@ -Subproject commit 9c3d99f157e469b0f9810f56a86b591319404cd8 +Subproject commit 5af9b5692259339bb435e8bccb4a1113b7d8b4f0 diff --git a/Source/Tasks/LibExtractTask.cs b/Source/Tasks/LibExtractTask.cs index 1d47ef3..3c9f8bc 100644 --- a/Source/Tasks/LibExtractTask.cs +++ b/Source/Tasks/LibExtractTask.cs @@ -30,9 +30,20 @@ public override Boolean Execute() { try { + DateTime TempTime, LastWriteTime; + + LastWriteTime = new FileInfo(Source).LastWriteTime; + TempTime = new FileInfo(BuildEngine.ProjectFileOfTaskNode).LastWriteTime; + if (LastWriteTime < TempTime) + { + LastWriteTime = TempTime; + } + XmlDocument doc = new(); doc.Load(Source); + Log.LogMessage(MessageImportance.High, "Project: " + BuildEngine.ProjectFileOfTaskNode); + if (doc.DocumentElement == null) { throw new InvalidDataException("Invalid XML file: " + Source); @@ -74,6 +85,10 @@ public override Boolean Execute() throw new FileNotFoundException("Multiple " + LibName + " found in specified directories"); } + if (LastWriteTime < Libs[0].LastWriteTime) + { + LastWriteTime = Libs[0].LastWriteTime; + } Byte[] LibData = File.ReadAllBytes(Libs[0].FullName); ArchiveFile Ar = new(LibData); DirectoryInfo OutputLibDirectoryInfo = Directory.CreateDirectory(OutputDirectory + Path.DirectorySeparatorChar + Libs[0].Name); @@ -102,8 +117,15 @@ public override Boolean Execute() String OutputObjectFilePath = OutputLibDirectoryInfo.FullName + Path.DirectorySeparatorChar + Path.GetFileName(ExtractImport.Name); - Byte[] ObjectData = ExtractImport.Data; + FileInfo OutputObject = new(OutputObjectFilePath); + if (OutputObject.Exists && OutputObject.LastWriteTime > LastWriteTime) + { + ExtractedObjectFiles.Add(OutputObjectFilePath); + Log.LogMessage(MessageImportance.High, "\t-> " + OutputObjectFilePath + " is up-to-date"); + continue; + } + Byte[] ObjectData = ExtractImport.Data; if (StripDebugInfo) { IMAGE_FILE_HEADER FileHeader = Rtl.RawToStruct(Rtl.ArrayResize(ObjectData, Marshal.SizeOf())); @@ -119,6 +141,7 @@ public override Boolean Execute() if (SectionHeader.Name.SequenceEqual(".debug$T"u8.ToArray())) { SectionHeader.Name = [0, 0, 0, 0, 0, 0, 0, 0]; + SectionHeader.Characteristics |= (UInt32)IMAGE_SCN.LNK_REMOVE; Rtl.StructToRaw(SectionHeader).CopyTo(ObjectData, SectionHeaderIndex); } SectionHeaderIndex += Marshal.SizeOf();