Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] _CompileJava shouldn't always run (do…
Browse files Browse the repository at this point in the history
…tnet#2598)

Commit b90d3ab altered where we generate the Guid for
`$XAMARIN_BUILD_ID`.  This change resulted in the `_CompileJava`
target running on every build, because the Guid and the resulting
`AndroidEnvironment.java` file changed on every build.

`$XAMARIN_BUILD_ID` should only change when an apk is built.  This is
so the same id can be written to both the apk and the msym archive.

There was also a problem on windows where the design time build would
trigger the `_GeneratePackageManagerJava` target to run.  This was
down to the the following file being updated

	<Project>.csproj.CoreCompileInputs.cache

This would cause a cascade because once `_GeneratePackageManagerJava`
ran, this would then trigger `_CompileJava` and then other targets.

Looking at the `<GeneratePackageManagerJava/>` task we don't actually
use the assemblies directly within the tast.  We just need a list of
the assembly names.  A lot of the time we are running this task if an
assembly changes when we don't really need to.  What we actually need
to do is run the task when assemblies are either added or removed
from the list.

To that end we now store a hash of the `@(ResolvedAssemblies)`
ItemGroup in `$(IntermediateOutputPath)resolvedassemblies.hash`.
This hash is updated when the `ResolveAssemblies` target is run.
We can then use that hash file as an input to the
`_GeneratePackageManagerJava` target to ensure that we only run
`_GeneratePackageManagerJava` when the list changes.

An additional change was to write the `$XAMARIN_BUILD_ID` to a file
so that it can be stored between builds.  This is needed because
if the `_GeneratePackageManagerJava` target is skipped (due to an up
to date build) during the package creation, the `$(_XamarinBuildId)`
property would be empty.  The `$(_XamarinBuildId)` value is required
for the `<CreateMsymManifest/>` task, so we need to be able to store
this value between builds and read it in when required.  Reading
directly from a `txt` file is quicker than pulling the information
from the `XamarinAndroidEnvironmentVariables.java` file
which `_GeneratePackageManagerJava` produces.
  • Loading branch information
dellis1972 authored and jonpryor committed Jan 17, 2019
1 parent 1f57040 commit 0d8942f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void AddEnvironment ()
}

if (!havebuildId)
WriteEnvironment ("XAMARIN_BUILD_ID", buildId.ToString ());
WriteEnvironment ("XAMARIN_BUILD_ID", BuildId);

if (!haveHttpMessageHandler) {
if (HttpClientHandlerType == null)
Expand Down
34 changes: 32 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidIntermediateDesignTimeBuildDirectory>$(IntermediateOutputPath)designtime\</_AndroidIntermediateDesignTimeBuildDirectory>
<_AndroidLibraryFlatArchivesDirectory>$(IntermediateOutputPath)flata\</_AndroidLibraryFlatArchivesDirectory>
<_AndroidStampDirectory>$(IntermediateOutputPath)stamp\</_AndroidStampDirectory>
<_AndroidBuildIdFile>$(IntermediateOutputPath)buildid.txt</_AndroidBuildIdFile>
<_ResolvedUserAssembliesHashFile>$(IntermediateOutputPath)resolvedassemblies.hash</_ResolvedUserAssembliesHashFile>

<!-- $(EnableProguard) is an obsolete property that should be removed at some stage. -->
<AndroidEnableProguard Condition=" '$(AndroidEnableProguard)' == '' ">$(EnableProguard)</AndroidEnableProguard>
Expand Down Expand Up @@ -1940,6 +1942,18 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="ResolvedSymbols" ItemName="ResolvedSymbols" />
<Output TaskParameter="ResolvedDoNotPackageAttributes" ItemName="_ResolvedDoNotPackageAttributes" />
</ResolveAssemblies>
<Hash ItemsToHash="@(ResolvedAssemblies)">
<Output TaskParameter="HashResult" PropertyName="_ResolvedUserAssembliesHash" />
</Hash>
<WriteLinesToFile
File="$(_ResolvedUserAssembliesHashFile)"
Lines="$(_ResolvedUserAssembliesHash)"
Overwrite="true"
WriteOnlyWhenDifferent="true"
/>
<ItemGroup>
<FileWrites Include="$(_ResolvedUserAssembliesHashFile)" />
</ItemGroup>
</Target>

<Target Name="_CreatePackageWorkspace">
Expand Down Expand Up @@ -2368,7 +2382,7 @@ because xbuild doesn't support framework reference assemblies.

<Target Name="_GeneratePackageManagerJava"
DependsOnTargets="_GetAddOnPlatformLibraries;_AddStaticResources;$(_AfterAddStaticResources);_PrepareAssemblies"
Inputs="$(MSBuildAllProjects);@(_ResolvedAssemblies);@(_ResolvedUserAssemblies);$(MSBuildProjectFile);$(_AndroidBuildPropertiesCache)"
Inputs="$(MSBuildAllProjects);$(_ResolvedUserAssembliesHashFile);$(MSBuildProjectFile);$(_AndroidBuildPropertiesCache)"
Outputs="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp">
<!-- Create java needed for Mono runtime -->
<GeneratePackageManagerJava
Expand All @@ -2387,10 +2401,20 @@ because xbuild doesn't support framework reference assemblies.
TlsProvider="$(AndroidTlsProvider)"
Debug="$(AndroidIncludeDebugSymbols)"
AndroidSequencePointsMode="$(_SequencePointsMode)"
EnableSGenConcurrent="$(AndroidEnableSGenConcurrent)">
EnableSGenConcurrent="$(AndroidEnableSGenConcurrent)"
>
<Output TaskParameter="BuildId" PropertyName="_XamarinBuildId" />
</GeneratePackageManagerJava>
<Touch Files="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp" AlwaysCreate="True" />
<WriteLinesToFile
File="$(_AndroidBuildIdFile)"
Lines="$(_XamarinBuildId)"
Overwrite="true"
WriteOnlyWhenDifferent="true"
/>
<ItemGroup>
<FileWrites Include="$(_AndroidBuildIdFile)" />
</ItemGroup>
</Target>

<PropertyGroup>
Expand Down Expand Up @@ -2986,6 +3010,10 @@ because xbuild doesn't support framework reference assemblies.
DestinationFolder="$(OutDir)$(_AndroidPackage).apk.mSYM\%(_SymbolicateFiles.RecursiveDir)"
SkipUnchangedFiles="true"
/>

<ReadLinesFromFile File="$(_AndroidBuildIdFile)" Condition="Exists('$(_AndroidBuildIdFile)') And '$(_XamarinBuildId)' == ''">
<Output TaskParameter="Lines" PropertyName="_XamarinBuildId"/>
</ReadLinesFromFile>

<CreateMsymManifest
Condition=" '$(_XamarinBuildId)' != '' And '$(MonoSymbolArchive)' == 'True' "
Expand Down Expand Up @@ -3246,6 +3274,8 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="$(_AndroidAapt2VersionFile)" />
<Delete Files="$(IntermediateOutputPath)R.txt" />
<Delete Files="$(_AndroidMainDexListFile)" />
<Delete Files="$(_AndroidBuildIdFile)" />
<Delete Files="$(_ResolvedUserAssembliesHashFile)" />
</Target>

<Target Name="_CollectMonoAndroidOutputs" DependsOnTargets="_ValidateAndroidPackageProperties">
Expand Down

0 comments on commit 0d8942f

Please sign in to comment.