Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] _CreateAapt2VersionCache slow due to …
Browse files Browse the repository at this point in the history
…wildcard usage (#2124)

Fixes: #2121

There were a number of performance issues with the
`_CreateAapt2VersionCache` target.

Firstly the wildcards were processing the *entire*
`$(IntermediateOutputPath)` tree!  What they should have been doing
was targeting specific directories, e.g. the root of
`$(IntermediateOutputPath)` and the directories under
`$(IntermediateOutputPath)\lp`.

Secondly the target did not have a `Condition` to stop it from
running if the versions matched, so that has been added.

Thirdly, even if a target is NOT run, MSBuild will still evaluate the
`<PropertyGroup/>`s and `<ItemGroup/>`s within the Target, so we need
to add a `Conditon` on the `@(_CompiledFlataArchive)` and
`@(_CompiledFlataStamp)` items as well to prevent evaluation and
corresponding directory traversal.

With these in place the time when this target is reduced to 1ms.
  • Loading branch information
dellis1972 authored and jonpryor committed Sep 5, 2018
1 parent 1886e6f commit 35ad986
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<Target Name="_CreateAapt2VersionCache"
DependsOnTargets="_ReadAapt2VersionCache"
AfterTargets="_SetLatestTargetFrameworkVersion"
Condition="'$(_AndroidUseAapt2)' == 'True'"
Condition="'$(_AndroidUseAapt2)' == 'True' And '$(_Aapt2Version)' != '@(_Aapt2VersionCache)'"
>
<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists('$(IntermediateOutputPath)')" />
<WriteLinesToFile
Expand All @@ -794,9 +794,10 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
Lines="$(_Aapt2Version)"
Overwrite="true"
/>
<ItemGroup>
<_CompiledFlataArchive Include="$(IntermediateOutputPath)\**\*.flata"/>
<_CompiledFlataStamp Include="$(IntermediateOutputPath)\**\compiled.stamp"/>
<ItemGroup Condition="'$(_Aapt2Version)' != '@(_Aapt2VersionCache)'">
<_CompiledFlataArchive Include="$(_AndroidLibrayProjectIntermediatePath)**\*.flata" />
<_CompiledFlataArchive Include="$(IntermediateOutputPath)\*.flata" />
<_CompiledFlataStamp Include="$(_AndroidLibrayProjectIntermediatePath)**\compiled.stamp" />
</ItemGroup>
<Delete Files="@(_CompiledFlataArchive);@(_CompiledFlataStamp)" Condition="'$(_Aapt2Version)' != '@(_Aapt2VersionCache)'" />
</Target>
Expand Down

0 comments on commit 35ad986

Please # to comment.