From e74b611225267ed170dfbe01bc7cc44599bd5d7a Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 3 Jan 2019 14:02:12 +0000 Subject: [PATCH] [Xamarin.Android.Build.Tests] Fix Repeat Build Tests PR #2515 highlighted an issue with a few of our repeat build tests. Tests were failing because the `_Sign` target was being skipped. Looking at the build logs, `BuildApk` was being called. As was `_CreateBaseApk`, so what is going on? So it turns out that in `BuildApk` we use the `CopyZipIfChanged` method to move the temp zip file over to the actual one. In this case ... the zip was identical! So the "new" zip was not copied.. and so the `_Sign` task did not need to run. How can the zip be the same? It had an updated file? Well wrong.. we just touched the timestamp. In which case the zip ends up with the exact same CRC values for each file. We use the CRC to detect changes.. so no changes. So it turns out our build system was behaving as expected.. it was just our test was invalid. So the fix here is to update the tests to make sure we do change a file. This means the CRC's will change and the targets will run. --- .../AndroidUpdateResourcesTest.cs | 6 ++++-- .../Tests/Xamarin.Android.Build.Tests/BuildTest.cs | 6 ++++-- .../Tests/Xamarin.Android.Build.Tests/PackagingTest.cs | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) 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 636aa72022c..2aca414716b 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 @@ -23,13 +23,15 @@ public void RepetitiveBuild () if (Directory.Exists ("temp/RepetitiveBuild")) Directory.Delete ("temp/RepetitiveBuild", true); var proj = new XamarinAndroidApplicationProject (); - using (var b = CreateApkBuilder ("temp/RepetitiveBuild")) { + using (var b = CreateApkBuilder ("temp/RepetitiveBuild", cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) { b.Verbosity = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic; b.ThrowOnBuildFailure = false; Assert.IsTrue (b.Build (proj), "first build failed"); Assert.IsTrue (b.Build (proj), "second build failed"); Assert.IsTrue (b.Output.IsTargetSkipped ("_Sign"), "failed to skip some build"); - proj.AndroidResources.Last ().Timestamp = null; // means "always build" + var item = proj.AndroidResources.First (x => x.Include () == "Resources\\values\\Strings.xml"); + item.TextContent = () => proj.StringsXml.Replace ("${PROJECT_NAME}", "Foo"); + item.Timestamp = null; Assert.IsTrue (b.Build (proj), "third build failed"); Assert.IsFalse (b.Output.IsTargetSkipped ("_Sign"), "incorrectly skipped some build"); } 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 f57513aafce..759d1a9accb 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 @@ -978,7 +978,7 @@ public override void OnCreate() public void BasicApplicationRepetitiveBuild () { var proj = new XamarinAndroidApplicationProject (); - using (var b = CreateApkBuilder ("temp/BasicApplicationRepetitiveBuild", cleanupAfterSuccessfulBuild: false)) { + using (var b = CreateApkBuilder ("temp/BasicApplicationRepetitiveBuild", cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) { b.Verbosity = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic; b.ThrowOnBuildFailure = false; Assert.IsTrue (b.Build (proj), "first build failed"); @@ -991,7 +991,9 @@ public void BasicApplicationRepetitiveBuild () Assert.IsTrue ( b.Output.IsTargetSkipped ("_Sign"), "the _Sign target should not run"); - proj.AndroidResources.Last ().Timestamp = null; + var item = proj.AndroidResources.First (x => x.Include () == "Resources\\values\\Strings.xml"); + item.TextContent = () => proj.StringsXml.Replace ("${PROJECT_NAME}", "Foo"); + item.Timestamp = null; Assert.IsTrue (b.Build (proj), "third build failed"); Assert.IsFalse ( b.Output.IsTargetSkipped ("_Sign"), diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs index 873884083f0..5be56daff8e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs @@ -240,7 +240,9 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true, } } - proj.AndroidResources.First ().Timestamp = null; + var item = proj.AndroidResources.First (x => x.Include () == "Resources\\values\\Strings.xml"); + item.TextContent = () => proj.StringsXml.Replace ("${PROJECT_NAME}", "Foo"); + item.Timestamp = null; Assert.IsTrue (b.Build (proj), "Second build failed"); Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, " 0 Warning(s)"), "Second build should not contain warnings! Contains\n" +