Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tests] Fix Repeat Build Tests (#2582)
Browse files Browse the repository at this point in the history
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, the `BuildApk` target was being called,
as was the `_CreateBaseApk` target, so what is going on?

It turns out that in the `<BuildApk/>` task we use the
`MonoAndroidHelper.CopyIfZipChanged()` method to move the temp zip
file over to the actual one.  In this case, the zip was identical!
Thus the "new" zip was not copied, and the `_Sign` target did not
need to run.

How can the zip be the same?  Didn't it have an updated file?
Not quite; we just touched the timestamp.  In this case the zip ends
up with the exact same CRC values for each file.  We use the CRC to
detect changes, so no changes were detected.  It turns out our build
system was behaving as expected, it was just our test was invalid.

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.
  • Loading branch information
dellis1972 authored and jonpryor committed Jan 3, 2019
1 parent a30dd21 commit 324e615
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down

0 comments on commit 324e615

Please sign in to comment.