Skip to content

Commit

Permalink
Targets / Task improvements:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Redth committed Mar 2, 2020
1 parent dc79dd5 commit 5d8f771
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 46 deletions.
36 changes: 9 additions & 27 deletions Resizetizer.NT/ResizetizeSharedImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +39,7 @@ public override bool Execute()

var originalScaleDpi = DpiPath.GetOriginal(PlatformType);

var fileWrites = new List<string>();
var resizedImages = new List<string>();

System.Threading.Tasks.Parallel.ForEach(images, img =>
{
Expand All @@ -56,50 +56,32 @@ public override bool Execute()
foreach (var dpi in dpis)
{
var r = resizer.Resize(dpi);
fileWrites.Add(r);
resizedImages.Add(r);
}
}
else
{
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<TaskItem>();

foreach (var f in fileWrites)
foreach (var f in resizedImages)
{
var attr = new Dictionary<string, string>();
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));
}

Expand Down
66 changes: 47 additions & 19 deletions Resizetizer.NT/Resizetizer.NT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,37 @@
<ResizetizeSharedImages
PlatformType="ios"
IntermediateOutputPath="$(ResizetizerIntermediateOutputPath)"
SharedImages="@(SharedImage)"
IsMacEnabled="$(IsMacEnabled)">
<Output TaskParameter="CopiedResources" ItemName="ResizetizedImages" />
SharedImages="@(SharedImage)">
</ResizetizeSharedImages>

<ItemGroup>
<!-- Get Images that were generated -->
<!-- Either from the task, or if the task was skipped (up to date), use the wildcard lookup -->
<_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" />
<_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(ResizetizerIntermediateOutputPath)**\*" />

<!-- Batch the collectd items into BundleResource which iOS expects -->
<_ResizetizerCollectedBundleResourceImages Include="@(_ResizetizerCollectedImages->'%(FullPath)')">
<LogicalName>%(_ResizetizerCollectedImages.Filename)%(_ResizetizerCollectedImages.Extension)</LogicalName>
<TargetPath>%(_ResizetizerCollectedImages.Filename)%(_ResizetizerCollectedImages.Extension)</TargetPath>
</_ResizetizerCollectedBundleResourceImages>

<!-- iOS Expects images in this group -->
<BundleResource Include="@(_ResizetizerCollectedBundleResourceImages)" />
</ItemGroup>

<!-- If on Windows, using build host, copy the files over to build server host too -->
<CopyFilesToBuildServer
Condition="'$(IsMacEnabled)'=='true'"
SessionId="$(BuildSessionId)"
Files="@(ResizetizedImages)" />
Files="@(_ResizetizerCollectedBundleResourceImages)" />

<!-- Touch/create our stamp file for outputs -->
<Touch Files="$(IntermediateOutputPath)resizetizer.stamp" AlwaysCreate="True" />

<ItemGroup>
<!-- If we had any images, add that obj/ folder as a resource directory -->
<BundleResource Include="@(ResizetizedImages)" />

<FileWrites Condition="Exists ('$(ResizetizerIntermediateOutputPath)') And '@(CopiedResources)' == '' " Include="$(ResizetizerIntermediateOutputPath)**\*" />

<!-- Include our images and stamp file as filewrites so they don't get rm'd -->
<ItemGroup>
<FileWrites Include="@(_ResizetizerCollectedBundleResourceImages)" />
<FileWrites Include="$(IntermediateOutputPath)resizetizer.stamp" />
</ItemGroup>

Expand All @@ -118,19 +131,25 @@
PlatformType="android"
IntermediateOutputPath="$(ResizetizerIntermediateOutputPath)"
SharedImages="@(SharedImage)">
<Output TaskParameter="CopiedResources" ItemName="FileWrites" />
<!-- <Output TaskParameter="CopiedResources" ItemName="FileWrites" /> -->
</ResizetizeSharedImages>

<Touch Files="$(IntermediateOutputPath)resizetizer.stamp" AlwaysCreate="True" />

<ItemGroup>
<!-- Get Images that were generated -->
<!-- Either from the task, or if the task was skipped (up to date), use the wildcard lookup -->
<_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" />
<_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(ResizetizerIntermediateOutputPath)**\*" />

<!-- If we had any images, add that obj/ folder as a resource directory -->
<LibraryResourceDirectories Condition="Exists ('$(ResizetizerIntermediateOutputPath)')" Include="$(ResizetizerIntermediateOutputPath)">
<StampFile>$(IntermediateOutputPath)resizetizer.stamp</StampFile>
</LibraryResourceDirectories>
</ItemGroup>

<FileWrites Condition="Exists ('$(ResizetizerIntermediateOutputPath)') And '@(CopiedResources)' == '' " Include="$(ResizetizerIntermediateOutputPath)**\*" />
<Touch Files="$(IntermediateOutputPath)resizetizer.stamp" AlwaysCreate="True" />

<ItemGroup>
<FileWrites Include="@(_ResizetizerCollectedImages)" />
<FileWrites Include="$(IntermediateOutputPath)resizetizer.stamp" />
</ItemGroup>
</Target>
Expand All @@ -140,7 +159,7 @@
Inputs="@(SharedImage)"
Outputs="$(IntermediateOutputPath)resizetizer.stamp"
DependsOnTargets="ResizetizeCollectImages"
BeforeTargets="PrepareResourceNames">
BeforeTargets="AssignTargetPaths">

<!-- Where in obj/ to store these -->
<PropertyGroup>
Expand All @@ -151,16 +170,25 @@
PlatformType="uwp"
IntermediateOutputPath="$(ResizetizerIntermediateOutputPath)"
SharedImages="@(SharedImage)">
<Output TaskParameter="CopiedResources" ItemName="ResizetizedImages" />
<!-- <Output TaskParameter="CopiedResources" ItemName="FileWrites" /> -->
</ResizetizeSharedImages>

<ItemGroup>
<!-- Get Images that were generated -->
<!-- Either from the task, or if the task was skipped (up to date), use the wildcard lookup -->
<_ResizetizerCollectedImages Condition="'@(CopiedResources)' != ''" Include="@(CopiedResources)" />
<_ResizetizerCollectedImages Condition="'@(CopiedResources)' == ''" Include="$(ResizetizerIntermediateOutputPath)**\*" />

<ContentWithTargetPath Include="@(_ResizetizerCollectedImages)">
<TargetPath>%(_ResizetizerCollectedImages.Filename)%(_ResizetizerCollectedImages.Extension)</TargetPath>
</ContentWithTargetPath>
</ItemGroup>

<Touch Files="$(IntermediateOutputPath)resizetizer.stamp" AlwaysCreate="True" />

<ItemGroup>
<!-- If we had any images, add that obj/ folder as a resource directory -->
<ContentWithTargetPath Include="@(ResizetizedImages)" />

<FileWrites Condition="Exists ('$(ResizetizerIntermediateOutputPath)') And '@(CopiedResources)' == '' " Include="$(ResizetizerIntermediateOutputPath)**\*" />
<FileWrites Include="@(_ResizetizerCollectedImages)" />

<FileWrites Include="$(IntermediateOutputPath)resizetizer.stamp" />
</ItemGroup>
Expand Down

0 comments on commit 5d8f771

Please sign in to comment.