Skip to content

Commit 87bb898

Browse files
jonathanpeppersdellis1972
authored andcommitted
[Xamarin.Android.Build.Tasks] prevent _BuildLibraryProjectImportsCache always running (#2132)
When testing a build with no changes, I started noticing: Building target "_BuildLibraryImportsCache" completely. Input file "App7\bin\Debug\netstandard2.0\App7.dll" is newer than output file "obj\Debug\90\libraryimports.cache". What was weird, is that earlier in the build log: Did not copy from file "bin\Debug\netstandard2.0\App7.dll" to file "bin\Debug\App7.dll" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match. So the NetStandard assembly didn't change. When I looked at these files: 8/31/2018 11:02 AM App7.dll 8/31/2018 10:09 AM resourcepaths.cache Weird? It looks like `resourcepaths.cache`'s timestamp needs to be updated? Then I looked and noticed that the timestamp of `resourcepaths.cache` would only be updated if the XML changed. My *first* attempt to fix this: - I made `XDocumentExtensions.SaveIfChanged` return a `bool` indicating if the file changed. - I changed the `GetImportedLibraries` task so that it would update the timestamp in cases where the file didn't change. Unfortunately, that made `_UpdateAndroidResgen` run all the time, which would be even worse! So my *second* attempt was much better: - Add a `$(_AndroidLibraryImportsCache).stamp` file, to use as the `Outputs` of `_BuildLibraryImportsCache`. - This file's timestamp can operate independently of `$(_AndroidLibraryImportsCache)` `_BuildLibraryImportsCache` now builds incrementally and gets skipped properly: Skipping target "_BuildLibraryImportsCache" because all output files are up-to-date with respect to the input files. It seems to me this problem was always occurring on builds with no changes. So this will likely help any incremental build. Before this change: 146 ms _BuildLibraryImportsCache 1 calls Total time: 2.824s After this change: 4 ms _BuildLibraryImportsCache 1 calls Total time: 2.698s I also updated an existing test to make sure the `_BuildLibraryImportsCache` target isn't running all the time.
1 parent 63b5d6d commit 87bb898

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ public void CheckTimestamps ([Values (true, false)] bool isRelease)
318318
var targetsToBeSkipped = new [] {
319319
isRelease ? "_LinkAssembliesShrink" : "_LinkAssembliesNoShrink",
320320
"_UpdateAndroidResgen",
321+
"_BuildLibraryImportsCache",
321322
};
322323
foreach (var targetName in targetsToBeSkipped) {
323324
Assert.IsTrue (b.Output.IsTargetSkipped (targetName), $"`{targetName}` should be skipped!");

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,14 @@ because xbuild doesn't support framework reference assemblies.
14471447

14481448
<Target Name="_BuildLibraryImportsCache"
14491449
Inputs="$(MSBuildProjectFullPath);@(ReferencePath);@(ReferenceDependencyPaths);$(_AndroidBuildPropertiesCache)"
1450-
Outputs="$(_AndroidLibraryImportsCache)">
1450+
Outputs="$(_AndroidLibraryImportsCache).stamp">
14511451
<GetImportedLibraries TargetDirectory="$(_AndroidLibrayProjectIntermediatePath)"
14521452
CacheFile="$(_AndroidLibraryImportsCache)">
14531453
</GetImportedLibraries>
1454+
<Touch Files="$(_AndroidLibraryImportsCache).stamp" AlwaysCreate="True" />
1455+
<ItemGroup>
1456+
<FileWrites Include="$(_AndroidLibraryImportsCache).stamp" />
1457+
</ItemGroup>
14541458
</Target>
14551459

14561460
<Target Name="_GetLibraryImports" DependsOnTargets="$(_GetLibraryImportsDependsOnTargets)">
@@ -3071,6 +3075,7 @@ because xbuild doesn't support framework reference assemblies.
30713075
<Delete Files="$(_AndroidResourceDesignerFile)" Condition=" '$(AndroidUseIntermediateDesignerFile)' == 'True' " />
30723076
<Delete Files="$(_AndroidBuildPropertiesCache)" />
30733077
<Delete Files="$(_AndroidLibraryImportsCache)" />
3078+
<Delete Files="$(_AndroidLibraryImportsCache).stamp" />
30743079
<Delete Files="$(_AndroidStaticResourcesFlag)" />
30753080
<Delete Files="$(_AndroidLibraryProjectImportsCache)" />
30763081
<Delete Files="$(_AndroidLibrayProjectAssemblyMapFile)" />

0 commit comments

Comments
 (0)