From 5d8f7710d9a51b24b01a4d0fa3ec21bb4c83adc9 Mon Sep 17 00:00:00 2001 From: Jonathan Dick Date: Mon, 2 Mar 2020 15:04:00 -0500 Subject: [PATCH] Targets / Task improvements: - Move item group metadata logic into targets file - Always try and use output items from task for filewrites and includes, otherwise use wildcard lookup once if target is skipped - Fix UWP incremental builds --- Resizetizer.NT/ResizetizeSharedImages.cs | 36 ++++--------- Resizetizer.NT/Resizetizer.NT.targets | 66 +++++++++++++++++------- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/Resizetizer.NT/ResizetizeSharedImages.cs b/Resizetizer.NT/ResizetizeSharedImages.cs index 746f620..9e66d24 100644 --- a/Resizetizer.NT/ResizetizeSharedImages.cs +++ b/Resizetizer.NT/ResizetizeSharedImages.cs @@ -21,11 +21,11 @@ public class ResizetizeSharedImages : Task, ILogger public ITaskItem[] SharedImages { get; set; } - public string IsMacEnabled { get; set; } = "false"; - [Output] public ITaskItem[] CopiedResources { get; set; } + public string IsMacEnabled { get;set; } + public override bool Execute() { Svg.SvgDocument.SkipGdiPlusCapabilityCheck = true; @@ -39,7 +39,7 @@ public override bool Execute() var originalScaleDpi = DpiPath.GetOriginal(PlatformType); - var fileWrites = new List(); + var resizedImages = new List(); System.Threading.Tasks.Parallel.ForEach(images, img => { @@ -56,7 +56,7 @@ public override bool Execute() foreach (var dpi in dpis) { var r = resizer.Resize(dpi); - fileWrites.Add(r); + resizedImages.Add(r); } } else @@ -64,42 +64,24 @@ public override bool Execute() op = "Copy"; // Otherwise just copy the thing over to the 1.0 scale var dest = Resizer.CopyFile(img, originalScaleDpi, IntermediateOutputPath, PlatformType.ToLower().Equals("android")); - fileWrites.Add(dest); + resizedImages.Add(dest); } opStopwatch.Stop(); Log.LogMessage(MessageImportance.Low, $"{op} took {opStopwatch.ElapsedMilliseconds}ms"); }); - - // var touchFile = Path.Combine(IntermediateOutputPath, "..", "resizetizer.stamp"); - // using (var touch = File.Open(touchFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) - // touch.Close(); - // File.SetLastWriteTimeUtc(touchFile, DateTime.UtcNow); - Log.LogMessage($"IsMacEnabled? {IsMacEnabled}"); - var copiedResources = new List(); - foreach (var f in fileWrites) + foreach (var f in resizedImages) { var attr = new Dictionary(); string itemSpec = Path.GetFullPath(f); - if (PlatformType.Equals("ios", StringComparison.OrdinalIgnoreCase)) - { - var fn = Path.GetFileName(itemSpec); - attr.Add("LogicalName", fn); - if (bool.TryParse(IsMacEnabled, out bool isMac) && isMac) { - attr.Add("TargetPath", fn); - itemSpec = f; - } - } - else if (PlatformType.Equals("uwp", StringComparison.OrdinalIgnoreCase)) - { - attr.Add("TargetPath", Path.GetFileName(itemSpec)); - } - + if (bool.TryParse(IsMacEnabled, out bool isMac) && isMac) + itemSpec = f; + copiedResources.Add(new TaskItem(itemSpec, attr)); } diff --git a/Resizetizer.NT/Resizetizer.NT.targets b/Resizetizer.NT/Resizetizer.NT.targets index a21b113..27fc19c 100644 --- a/Resizetizer.NT/Resizetizer.NT.targets +++ b/Resizetizer.NT/Resizetizer.NT.targets @@ -78,24 +78,37 @@ - + SharedImages="@(SharedImage)"> + + + + <_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" /> + <_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(ResizetizerIntermediateOutputPath)**\*" /> + + + <_ResizetizerCollectedBundleResourceImages Include="@(_ResizetizerCollectedImages->'%(FullPath)')"> + %(_ResizetizerCollectedImages.Filename)%(_ResizetizerCollectedImages.Extension) + %(_ResizetizerCollectedImages.Filename)%(_ResizetizerCollectedImages.Extension) + + + + + + + + Files="@(_ResizetizerCollectedBundleResourceImages)" /> + - - - - - - + + + @@ -118,19 +131,25 @@ PlatformType="android" IntermediateOutputPath="$(ResizetizerIntermediateOutputPath)" SharedImages="@(SharedImage)"> - + - - + + + <_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" /> + <_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(ResizetizerIntermediateOutputPath)**\*" /> + $(IntermediateOutputPath)resizetizer.stamp + - + + + @@ -140,7 +159,7 @@ Inputs="@(SharedImage)" Outputs="$(IntermediateOutputPath)resizetizer.stamp" DependsOnTargets="ResizetizeCollectImages" - BeforeTargets="PrepareResourceNames"> + BeforeTargets="AssignTargetPaths"> @@ -151,16 +170,25 @@ PlatformType="uwp" IntermediateOutputPath="$(ResizetizerIntermediateOutputPath)" SharedImages="@(SharedImage)"> - + + + + + <_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" /> + <_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(ResizetizerIntermediateOutputPath)**\*" /> + + + %(_ResizetizerCollectedImages.Filename)%(_ResizetizerCollectedImages.Extension) + + + - - - +