From 647659e8b164feb63c71692a71a9149045da4a71 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 21 Sep 2018 08:59:49 -0500 Subject: [PATCH] [Xamarin.Android.Build.Tasks] fix _CompileJava running too often (#2207) Context: https://github.com/xamarin/xamarin-android/pull/2088 Context: https://github.com/xamarin/xamarin-android/pull/2129 Context: https://github.com/xamarin/xamarin-android/pull/2199 In 4deec52e, I fixed the #deletebinobj problem we discovered. However... I introduced a regression to incremental builds, I noticed that the `_CompileJava` target is now running on a second build with no changes. Third build? oddly it gets skipped... It seems to be due to our use of flag files: 1. `_UpdateAndroidResgen` updates `R.cs.flag` and uses the file as an output 2. `_GenerateJavaDesignerForComponent` now uses `R.cs.flag` as an input 3. `_GenerateJavaStubs` *also* updates the timestamp on `R.cs.flag`. This was added in 970da9ef, as a workaround for our two instances of `ConvertResourcesCases`. 4. `_GenerateJavaDesignerForComponent` will now run again on the next build. Since 1886e6f1 eliminated the second call to `ConvertResourcesCases`, we don't need to update `R.cs.flag` in no. 3 any longer. Removing the call to `` `R.cs.flag` in `_GenerateJavaStubs` fixed the issue, and I added some assertions in relevant tests to check that the `_CompileJava` and `_GenerateJavaDesignerForComponent` targets aren't running on incremental builds. --- .../Xamarin.Android.Build.Tests/BuildTest.cs | 20 ++++++++++++++----- .../Xamarin.Android.Common.targets | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) 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 b8972553c7e..91549f06ed1 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 @@ -192,11 +192,19 @@ public void SwitchBetweenDesignTimeBuild () FileAssert.Exists (designtime_build_props, "designtime/build.props should exist after the second `Build`."); //NOTE: none of these targets should run, since we have not actually changed anything! - Assert.IsTrue (b.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "`_UpdateAndroidResgen` should be skipped!"); - //TODO: We would like for this assertion to work, but the item group changes between DTB and regular builds - // $(IntermediateOutputPath)designtime\Resource.designer.cs -> Resources\Resource.designer.cs - // And so the built assembly changes between DTB and regular build, triggering `_LinkAssembliesNoShrink` - //Assert.IsTrue (b.Output.IsTargetSkipped ("_LinkAssembliesNoShrink"), "`_LinkAssembliesNoShrink` should be skipped!"); + var targetsToBeSkipped = new [] { + //TODO: We would like for this assertion to work, but the item group changes between DTB and regular builds + // $(IntermediateOutputPath)designtime\Resource.designer.cs -> Resources\Resource.designer.cs + // And so the built assembly changes between DTB and regular build, triggering `_LinkAssembliesNoShrink` + //"_LinkAssembliesNoShrink", + "_UpdateAndroidResgen", + "_GenerateJavaDesignerForComponent", + "_BuildLibraryImportsCache", + "_CompileJava", + }; + foreach (var targetName in targetsToBeSkipped) { + Assert.IsTrue (b.Output.IsTargetSkipped (targetName), $"`{targetName}` should be skipped!"); + } b.Target = "Clean"; Assert.IsTrue (b.Build (proj), "clean should have succeeded."); @@ -318,7 +326,9 @@ public void CheckTimestamps ([Values (true, false)] bool isRelease) var targetsToBeSkipped = new [] { isRelease ? "_LinkAssembliesShrink" : "_LinkAssembliesNoShrink", "_UpdateAndroidResgen", + "_GenerateJavaDesignerForComponent", "_BuildLibraryImportsCache", + "_CompileJava", }; foreach (var targetName in targetsToBeSkipped) { Assert.IsTrue (b.Output.IsTargetSkipped (targetName), $"`{targetName}` should be skipped!"); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index a26a6beee58..ee75ad8118e 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2250,7 +2250,7 @@ because xbuild doesn't support framework reference assemblies. ResourceDirectories="$(MonoAndroidResDirIntermediate);@(LibraryResourceDirectories)" ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)" /> - +