From fb68c8f79f5505f8e0446b833b186bcd74cf4f4f Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 27 Feb 2017 14:35:13 -0500 Subject: [PATCH 1/2] [msbuild] Ignore .DS_Store files when cloning asset catalogs Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=52851 The problem here is that the .DS_Store file was included in the .csproj file but did not exist on disk, so when we went to clone that file into the obj/ dir before running actool on it, File.Copy() would fail because the file did not actually exist. Since these files are worthless anyway, we can safely ignore them. Also added logic to verify that files exist before copying them in order to report a better error than an exception stack trace. --- .../Tasks/ACToolTaskBase.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs index c0eb70a0fb0d..9fdac2f774c0 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs @@ -297,6 +297,10 @@ public override bool Execute () for (int i = 0; i < ImageAssets.Length; i++) { var vpath = BundleResource.GetVirtualProjectPath (ProjectDir, ImageAssets[i], !string.IsNullOrEmpty (SessionId)); + // Ignore MacOS .DS_Store files... + if (Path.GetFileName (vpath).Equals (".DS_Store", StringComparison.OrdinalIgnoreCase)) + continue; + // get the parent (which will typically be .appiconset, .launchimage, .imageset, .iconset, etc) var catalog = Path.GetDirectoryName (vpath); @@ -336,6 +340,10 @@ public override bool Execute () var clone = false; ITaskItem item; + // Ignore MacOS .DS_Store files... + if (Path.GetFileName (vpath).Equals (".DS_Store", StringComparison.OrdinalIgnoreCase)) + continue; + foreach (var catalog in clones) { if (vpath.Length > catalog.Length && vpath[catalog.Length] == '/' && vpath.StartsWith (catalog, StringComparison.Ordinal)) { clone = true; @@ -344,17 +352,24 @@ public override bool Execute () } if (clone) { - var path = Path.Combine (intermediateCloneDir, vpath); - var dir = Path.GetDirectoryName (path); + var dest = Path.Combine (intermediateCloneDir, vpath); + var src = ImageAssets[i].GetMetadata ("FullPath"); + var dir = Path.GetDirectoryName (dest); Directory.CreateDirectory (dir); - File.Copy (ImageAssets[i].GetMetadata ("FullPath"), path, true); + + if (!File.Exists (src)) { + Log.LogError (null, null, null, src, 0, 0, 0, 0, "File not found: {0}", src); + return false; + } + + File.Copy (src, dest, true); // filter out everything except paths containing a Contents.json file since our main processing loop only cares about these if (Path.GetFileName (vpath) != "Contents.json") continue; - item = new TaskItem (path); + item = new TaskItem (dest); ImageAssets[i].CopyMetadataTo (item); item.SetMetadata ("Link", vpath); } else { From 9c37444b809411477716c1b9f66a312122416c89 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 27 Feb 2017 14:55:52 -0500 Subject: [PATCH 2/2] Reorder some operations to avoid unnecessary work in failure case --- .../Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs index 9fdac2f774c0..12c5c3996381 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ACToolTaskBase.cs @@ -352,17 +352,18 @@ public override bool Execute () } if (clone) { - var dest = Path.Combine (intermediateCloneDir, vpath); var src = ImageAssets[i].GetMetadata ("FullPath"); - var dir = Path.GetDirectoryName (dest); - - Directory.CreateDirectory (dir); if (!File.Exists (src)) { Log.LogError (null, null, null, src, 0, 0, 0, 0, "File not found: {0}", src); return false; } + var dest = Path.Combine (intermediateCloneDir, vpath); + var dir = Path.GetDirectoryName (dest); + + Directory.CreateDirectory (dir); + File.Copy (src, dest, true); // filter out everything except paths containing a Contents.json file since our main processing loop only cares about these