From 32a698677be7b019a3a67141e9479c53a6ed9430 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 16 Mar 2018 17:53:15 +0000 Subject: [PATCH 1/6] [Xamarin.Android.Build.Tasks] DesignTimeBuild Improvements --- .../Xamarin.Android.Common.targets | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 283a0ec82f0..4f2c29db0dd 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -1107,9 +1107,21 @@ because xbuild doesn't support framework reference assemblies. Overwrite="true"/> + + <_ManagedUpdateAndroidResgenInputs> + $(MSBuildAllProjects); + @(AndroidResource); + @(ReferencePath); + @(_LibraryResourceDirectoryStamps); + @(_AdditonalAndroidResourceCachePaths->'%(Identity)\cache.stamp'); + $(_AndroidBuildPropertiesCache); + $(ProjectAssetsFile); + + + @@ -1188,7 +1200,7 @@ because xbuild doesn't support framework reference assemblies. '%(Identity)\cache.stamp'); - $(_AndroidBuildPropertiesCache) + $(_AndroidBuildPropertiesCache); + $(ProjectAssetsFile); + $(_AndroidResourcePathsCache); + $(_AndroidLibraryProjectImportsCache); + $(_AndroidLibraryImportsCache); From e5ea2b416e696865159d88c1af8957df5a061497 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 11:46:42 +0000 Subject: [PATCH 2/6] Updated test to expect to run --- .../Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs index 1b3e30e247c..6796146063c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs @@ -958,7 +958,7 @@ public string GetFoo () { Assert.IsTrue (libBuilder.Build (libProj, doNotCleanupOnUpdate: true, saveProject: false), "Library project should have built"); Assert.IsTrue (libBuilder.Output.IsTargetSkipped ("_CreateManagedLibraryResourceArchive"), "_CreateManagedLibraryResourceArchive should be skipped."); Assert.IsTrue (appBuilder.Build (appProj, doNotCleanupOnUpdate: true, saveProject: false), "Application Build should have succeeded."); - Assert.IsTrue (appBuilder.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "_UpdateAndroidResgen target should be skipped."); + Assert.IsFalse (appBuilder.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "_UpdateAndroidResgen target NOT should be skipped since Lib1 was updated."); theme.TextContent = () => @" #00000000 From b8825bc8d7a121e1f5f8043abb504613842235ab Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 12:58:05 +0000 Subject: [PATCH 3/6] ff --- .../Tasks/GetAdditionalResourcesFromAssemblies.cs | 8 +++++++- .../AndroidUpdateResourcesTest.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs index 7719f8a7fb6..b1163f094a7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs @@ -459,7 +459,13 @@ public override bool Execute () new XElement ("AdditionalNativeLibraryReferences", AdditionalNativeLibraryReferences.Select(e => new XElement ("AdditionalNativeLibraryReference", e))) )); - document.Save (CacheFile); + var tempFile = System.IO.Path.GetTempFileName (); + try { + document.Save (tempFile); + MonoAndroidHelper.CopyIfChanged (tempFile, CacheFile); + } finally { + File.Delete (tempFile); + } LogDebugTaskItems (" AdditionalAndroidResourcePaths: ", AdditionalAndroidResourcePaths); LogDebugTaskItems (" AdditionalJavaLibraryReferences: ", AdditionalJavaLibraryReferences); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs index 6796146063c..479b2b630d0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs @@ -958,7 +958,7 @@ public string GetFoo () { Assert.IsTrue (libBuilder.Build (libProj, doNotCleanupOnUpdate: true, saveProject: false), "Library project should have built"); Assert.IsTrue (libBuilder.Output.IsTargetSkipped ("_CreateManagedLibraryResourceArchive"), "_CreateManagedLibraryResourceArchive should be skipped."); Assert.IsTrue (appBuilder.Build (appProj, doNotCleanupOnUpdate: true, saveProject: false), "Application Build should have succeeded."); - Assert.IsFalse (appBuilder.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "_UpdateAndroidResgen target NOT should be skipped since Lib1 was updated."); + Assert.IsTrue (appBuilder.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "_UpdateAndroidResgen target should be skipped"); theme.TextContent = () => @" #00000000 From 8071660fe639f4b20a8243814c27ee35253e69aa Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 13:18:34 +0000 Subject: [PATCH 4/6] ff --- .../Tasks/GetImportedLibraries.cs | 8 +++++++- .../Tasks/ResolveLibraryProjectImports.cs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs index 79cfeddefc2..163cefb3f5d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs @@ -54,7 +54,13 @@ public override bool Execute () new XElement ("NativeLibraries", NativeLibraries.Select(e => new XElement ("NativeLibrary", e.ItemSpec))), new XElement ("Jars", Jars.Select(e => new XElement ("Jar", e.ItemSpec))) )); - document.Save (CacheFile); + var tempFile = System.IO.Path.GetTempFileName (); + try { + document.Save (tempFile); + MonoAndroidHelper.CopyIfChanged (tempFile, CacheFile); + } finally { + File.Delete (tempFile); + } } return true; diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 0aec9bd0635..6558043873e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -122,7 +122,13 @@ public override bool Execute () new XElement ("ResolvedResourceDirectoryStamps", ResolvedResourceDirectoryStamps.Select(e => new XElement ("ResolvedResourceDirectoryStamp", e))) )); - document.Save (CacheFile); + var tempFile = System.IO.Path.GetTempFileName (); + try { + document.Save (tempFile); + MonoAndroidHelper.CopyIfChanged (tempFile, CacheFile); + } finally { + File.Delete (tempFile); + } } assemblyMap.Save (AssemblyIdentityMapFile); From 771867cb45726133d1a7b447d560bb73910d2b9e Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 13:45:41 +0000 Subject: [PATCH 5/6] Only override the xml caches if they change --- .../Tasks/GetAdditionalResourcesFromAssemblies.cs | 8 +------- .../Tasks/GetImportedLibraries.cs | 8 +------- .../Tasks/ResolveLibraryProjectImports.cs | 8 +------- .../Utilities/XDocumentExtensions.cs | 11 +++++++++++ 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs index b1163f094a7..6a748c5b079 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs @@ -459,13 +459,7 @@ public override bool Execute () new XElement ("AdditionalNativeLibraryReferences", AdditionalNativeLibraryReferences.Select(e => new XElement ("AdditionalNativeLibraryReference", e))) )); - var tempFile = System.IO.Path.GetTempFileName (); - try { - document.Save (tempFile); - MonoAndroidHelper.CopyIfChanged (tempFile, CacheFile); - } finally { - File.Delete (tempFile); - } + document.SaveIfChanged (CacheFile); LogDebugTaskItems (" AdditionalAndroidResourcePaths: ", AdditionalAndroidResourcePaths); LogDebugTaskItems (" AdditionalJavaLibraryReferences: ", AdditionalJavaLibraryReferences); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs index 163cefb3f5d..bca2d908a7a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs @@ -54,13 +54,7 @@ public override bool Execute () new XElement ("NativeLibraries", NativeLibraries.Select(e => new XElement ("NativeLibrary", e.ItemSpec))), new XElement ("Jars", Jars.Select(e => new XElement ("Jar", e.ItemSpec))) )); - var tempFile = System.IO.Path.GetTempFileName (); - try { - document.Save (tempFile); - MonoAndroidHelper.CopyIfChanged (tempFile, CacheFile); - } finally { - File.Delete (tempFile); - } + document.SaveIfChanged (CacheFile); } return true; diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 6558043873e..ae418a63ae5 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -122,13 +122,7 @@ public override bool Execute () new XElement ("ResolvedResourceDirectoryStamps", ResolvedResourceDirectoryStamps.Select(e => new XElement ("ResolvedResourceDirectoryStamp", e))) )); - var tempFile = System.IO.Path.GetTempFileName (); - try { - document.Save (tempFile); - MonoAndroidHelper.CopyIfChanged (tempFile, CacheFile); - } finally { - File.Delete (tempFile); - } + document.SaveIfChanged (CacheFile); } assemblyMap.Save (AssemblyIdentityMapFile); diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs index 5bac4ba45a3..29f04f99010 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs @@ -27,6 +27,17 @@ public static string ToFullString (this XElement element) { return element.ToString (SaveOptions.DisableFormatting); } + + public static void SaveIfChanged (this XDocument document, string fileName) + { + var tempFile = System.IO.Path.GetTempFileName (); + try { + document.Save (tempFile); + MonoAndroidHelper.CopyIfChanged (tempFile, fileName); + } finally { + File.Delete (tempFile); + } + } } } From 3b1d7bc2a0d1da2c1125ba50e274771d1536f96c Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 13:55:39 +0000 Subject: [PATCH 6/6] ff --- .../Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs | 2 +- .../Utilities/XDocumentExtensions.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs index 479b2b630d0..1b3e30e247c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs @@ -958,7 +958,7 @@ public string GetFoo () { Assert.IsTrue (libBuilder.Build (libProj, doNotCleanupOnUpdate: true, saveProject: false), "Library project should have built"); Assert.IsTrue (libBuilder.Output.IsTargetSkipped ("_CreateManagedLibraryResourceArchive"), "_CreateManagedLibraryResourceArchive should be skipped."); Assert.IsTrue (appBuilder.Build (appProj, doNotCleanupOnUpdate: true, saveProject: false), "Application Build should have succeeded."); - Assert.IsTrue (appBuilder.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "_UpdateAndroidResgen target should be skipped"); + Assert.IsTrue (appBuilder.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "_UpdateAndroidResgen target should be skipped."); theme.TextContent = () => @" #00000000 diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs index 29f04f99010..f904f0a11c1 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Xml.Linq; using Microsoft.Build.Framework;