Skip to content

Commit ea5c68a

Browse files
jonathanpeppersjonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] _LinkAssembliesNoShrink timestamps (#2028)
Context: https://github.com/xamarin/monodroid/pull/821 Context: 3d999d3#diff-42a9402e6466c65d49d0ee7caf21f327R164 Since commit 3d999d3, a test is failing downstream in monodroid that is testing the following scenario: 1. With `Fast Deployment` enabled, run `/t:Install` 2. Make a small code change 3. Run `/t:Install` again 4. Assemblies are getting uploaded to the device that should already be up to date! 3d999d3 was addressing a symptom of the problem, but not the root cause. The `OutputStep` of the linker has various uses of [`File.Copy()`][0], which preserves the timestamp of the source file: > The attributes of the original file are retained in the copied file. File timestamps are considered "attributes of the original file". The solution, then, is to run the `<Touch/>` MSBuild task on the linker's output. This will create appropriate timestamps, and a portion of the changes in 3d999d3 are no longer needed. I updated the `CheckTimestamps()` test to validate `Debug` and `Release` configurations, so the `_LinkAssembliesShrink` target is also tested in this manner. It turns out `_LinkAssembliesShrink` is currently working fine, since it uses `$(_AndroidLinkFlag)` as its `Outputs` Target attribute. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.io.file.copy?view=netframework-4.7.2#System_IO_File_Copy_System_String_System_String_
1 parent 69d78d0 commit ea5c68a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ bool Execute (DirectoryAssemblyResolver res)
160160
// We cannot just copy the linker output from *current* run output, because
161161
// it always renew the assemblies, in *different* binary values, whereas
162162
// the dll in the OptionalDestinationDirectory must retain old and unchanged.
163-
if (File.Exists (assemblyDestination)) {
164-
MonoAndroidHelper.SetLastAccessAndWriteTimeUtc (assemblyDestination, DateTime.UtcNow, Log);
163+
if (File.Exists (assemblyDestination))
165164
continue;
166-
}
167165
} else {
168166
// Prefer fixup assemblies if exists, otherwise just copy the original.
169167
copysrc = Path.Combine (OutputDirectory, filename);

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ public void TargetFrameworkMonikerAssemblyAttributesPath ()
205205
}
206206

207207
[Test]
208-
public void CheckTimestamps ()
208+
public void CheckTimestamps ([Values (true, false)] bool isRelease)
209209
{
210210
var start = DateTime.UtcNow.AddSeconds (-1);
211-
var proj = new XamarinAndroidApplicationProject ();
212-
using (var b = CreateApkBuilder ("temp/CheckTimestamps")) {
211+
var proj = new XamarinAndroidApplicationProject {
212+
IsRelease = isRelease,
213+
};
214+
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
213215
//To be sure we are at a clean state, delete bin/obj
214216
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
215217
if (Directory.Exists (intermediate))
@@ -240,7 +242,8 @@ public void CheckTimestamps ()
240242

241243
//One last build with no changes
242244
Assert.IsTrue (b.Build (proj), "third build should have succeeded.");
243-
Assert.IsTrue (b.Output.IsTargetSkipped ("_LinkAssembliesNoShrink"), "`_LinkAssembliesNoShrink` should be skipped!");
245+
string targetName = isRelease ? "_LinkAssembliesShrink" : "_LinkAssembliesNoShrink";
246+
Assert.IsTrue (b.Output.IsTargetSkipped (targetName), $"`{targetName}` should be skipped!");
244247
}
245248
}
246249

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,13 @@ because xbuild doesn't support framework reference assemblies.
20782078
LinkOnlyNewerThan="$(_AndroidLinkFlag)"
20792079
ResolvedAssemblies="@(ResolvedAssemblies)" />
20802080

2081-
<!-- We don't have to depend on flag file for NoShrink, but it is used to check timestamp -->
2081+
<!--NOTE: the linker's use of File.Copy requires us to update the timestamps of output files -->
2082+
<ItemGroup>
2083+
<_FilesToTouch Include="$(MonoAndroidIntermediateAssemblyTempDir)*" />
2084+
</ItemGroup>
2085+
<Touch Files="@(_FilesToTouch)" />
2086+
2087+
<!-- We don't have to depend on flag file for NoShrink, but it is used to check timestamp -->
20822088
<Touch Files="$(_AndroidLinkFlag)" AlwaysCreate="true" />
20832089
</Target>
20842090

0 commit comments

Comments
 (0)