From 22b0b1c974392653f7e2f99b07ceb5b14a9fec43 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 11 Jan 2019 04:00:35 -0600 Subject: [PATCH] [Xamarin.Android.Build.Tasks] designer needs full paths in libraryprojectimports.cache (#2607) The Xamarin.Android designer uses the paths found in `libraryprojectimports.cache`, and recently was coming up with some odd paths in test failures: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\obj\Debug\90\lp\2\jl\res Looking at the contents of `libraryprojectimports.cache`, some of the paths were no longer full paths: ... obj\Debug\81\lp\6\jl\res obj\Debug\81\lp\9\jl\res obj\Debug\81\lp\11\jl\res obj\Debug\81\lp\12\jl\res obj\Debug\81\lp\13\jl\res obj\Debug\81\lp\14\jl\res ... In 02c07ed, we inadvertently lost the full paths when LINQ was removed. Things worked fine during regular builds, but not within the context of the designer. Changes: - Anywhere we add to `resolvedResourceDirectories`, should use `Path.GetFullPath` - Same with `resolvedAssetDirectories` - Fixed a place where an `assemblyDir` variable made more sense to be named `assetsDir`. --- .../Tasks/ResolveLibraryProjectImports.cs | 22 +++++++++---------- .../Xamarin.Android.Build.Tests/BuildTest.cs | 9 ++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 9f5cd4019bd..0759870fcdc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -214,7 +214,7 @@ void Extract ( //string binAssemblyDir = Path.Combine (importsDir, "bin", "assets"); #endif string resDir = Path.Combine (importsDir, "res"); - string assemblyDir = Path.Combine (importsDir, "assets"); + string assetsDir = Path.Combine (importsDir, "assets"); // Skip already-extracted resources. var stamp = new FileInfo (Path.Combine (outdir.FullName, assemblyIdentName + ".stamp")); @@ -229,15 +229,15 @@ void Extract ( resolvedAssetDirectories.Add (binAssemblyDir); #endif if (Directory.Exists (resDir)) { - var taskItem = new TaskItem (resDir, new Dictionary { + var taskItem = new TaskItem (Path.GetFullPath (resDir), new Dictionary { { OriginalFile, assemblyPath }, }); if (assembliesToSkip.Contains (assemblyFileName)) taskItem.SetMetadata (SkipAndroidResourceProcessing, "True"); resolvedResourceDirectories.Add (taskItem); } - if (Directory.Exists (assemblyDir)) - resolvedAssetDirectories.Add (assemblyDir); + if (Directory.Exists (assetsDir)) + resolvedAssetDirectories.Add (Path.GetFullPath (assetsDir)); foreach (var env in Directory.EnumerateFiles (outDirForDll, "__AndroidEnvironment__*", SearchOption.TopDirectoryOnly)) { resolvedEnvironments.Add (env); } @@ -350,15 +350,15 @@ void Extract ( resolvedAssetDirectories.Add (binAssemblyDir); #endif if (Directory.Exists (resDir)) { - var taskItem = new TaskItem (resDir, new Dictionary { + var taskItem = new TaskItem (Path.GetFullPath (resDir), new Dictionary { { OriginalFile, assemblyPath } }); if (assembliesToSkip.Contains (assemblyFileName)) taskItem.SetMetadata (SkipAndroidResourceProcessing, "True"); resolvedResourceDirectories.Add (taskItem); } - if (Directory.Exists (assemblyDir)) - resolvedAssetDirectories.Add (assemblyDir); + if (Directory.Exists (assetsDir)) + resolvedAssetDirectories.Add (Path.GetFullPath (assetsDir)); } } @@ -382,12 +382,12 @@ void Extract ( var stamp = new FileInfo (Path.Combine (outdir.FullName, Path.GetFileNameWithoutExtension (aarFile.ItemSpec) + ".stamp")); if (stamp.Exists && stamp.LastWriteTimeUtc > new FileInfo (aarFile.ItemSpec).LastWriteTimeUtc) { if (Directory.Exists (resDir)) - resolvedResourceDirectories.Add (new TaskItem (resDir, new Dictionary { + resolvedResourceDirectories.Add (new TaskItem (Path.GetFullPath (resDir), new Dictionary { { OriginalFile, Path.GetFullPath (aarFile.ItemSpec) }, { SkipAndroidResourceProcessing, "True" }, })); if (Directory.Exists (assetsDir)) - resolvedAssetDirectories.Add (assetsDir); + resolvedAssetDirectories.Add (Path.GetFullPath (assetsDir)); continue; } // temporarily extracted directory will look like: @@ -415,12 +415,12 @@ void Extract ( } } if (Directory.Exists (resDir)) - resolvedResourceDirectories.Add (new TaskItem (resDir, new Dictionary { + resolvedResourceDirectories.Add (new TaskItem (Path.GetFullPath (resDir), new Dictionary { { OriginalFile, Path.GetFullPath (aarFile.ItemSpec) }, { SkipAndroidResourceProcessing, "True" }, })); if (Directory.Exists (assetsDir)) - resolvedAssetDirectories.Add (assetsDir); + resolvedAssetDirectories.Add (Path.GetFullPath (assetsDir)); } foreach (var f in outdir.EnumerateFiles ("*.jar", SearchOption.AllDirectories) .Select (fi => fi.FullName)) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index ecc76d82a52..4f9ca5185fd 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -2153,6 +2153,15 @@ public void AarContentExtraction ([Values (false, true)] bool useAapt2) var count = doc.Elements ("Paths").Elements ("ResolvedResourceDirectories").Count (); Assert.AreEqual (expectedCount, count, "The same number of resource directories should have been resolved."); + //NOTE: the designer requires the paths to be full paths + foreach (var paths in doc.Elements ("Paths")) { + foreach (var element in paths.Elements ()) { + var path = element.Value; + if (!string.IsNullOrEmpty (path)) { + Assert.IsTrue (path == Path.GetFullPath (path), $"`{path}` is not a full path!"); + } + } + } } }