Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] use designtimebuild.props
Browse files Browse the repository at this point in the history
Context: #1933
Context: #1943

One of the issues I noticed while debugging the issue with #1933 is
that `$(IntermediateOutputPath)build.props` gets invalidated if
`$(DesignTimeBuild)` changes. `build.props` triggers alot of targets
to build completely again, so this is pretty bad for our build times
in an IDE...

Design-Time Builds can run quite frequently in VS Windows, and we
don't want to rebuild a bunch of things unnecessarily when the user
switches back to a regular build.

So a solution, is to use a `designtimebuild.props` that works
independantly of `build.props`. This prevents some slower targets from
running when they shouldn't, such as `_UpdateAndroidResgen`.

I added a test to validate these changes, which also verify that
`IncrementalClean` isn't deleting these files.
  • Loading branch information
jonathanpeppers committed Jul 12, 2018
1 parent 0ab8ec1 commit df00b0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,41 @@ public void FooMethod () {
}
}

[Test]
public void SwitchBetweenDesignTimeBuild ()
{
var proj = new XamarinAndroidApplicationProject ();

using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "first *regular* build should have succeeded.");
var build_props = b.Output.GetIntermediaryPath ("build.props");
var designtimebuild_props = b.Output.GetIntermediaryPath ("designtimebuild.props");
FileAssert.Exists (build_props, "build.props should exist after a first `Build`.");
FileAssert.DoesNotExist (designtimebuild_props, "designtimebuild.props should *not* exist after a first `Build`.");

b.Target = "Compile";
Assert.IsTrue (b.Build (proj, parameters: new [] { "DesignTimeBuild=True" }), "first design-time build should have succeeded.");
FileAssert.Exists (build_props, "build.props should exist after a design-time build.");
FileAssert.Exists (designtimebuild_props, "designtimebuild.props should exist after a design-time build.");

b.Target = "Build";
Assert.IsTrue (b.Build (proj), "second *regular* build should have succeeded.");
FileAssert.Exists (build_props, "build.props should exist after the second `Build`.");
FileAssert.Exists (designtimebuild_props, "designtimebuild.props should exist after the second `Build`.");

//NOTE: none of these targets should run, since we have not actually changed anything!
Assert.IsTrue (b.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "`_UpdateAndroidResgen` should be skipped!");
//TODO: I would like to add this assertion, but it requires: https://github.com/xamarin/xamarin-android/pull/1930
//Assert.IsTrue (b.Output.IsTargetSkipped ("_LinkAssembliesNoShrink"), "`_LinkAssembliesNoShrink` should be skipped!");

b.Target = "Clean";
Assert.IsTrue (b.Build (proj), "clean should have succeeded.");

FileAssert.DoesNotExist (build_props, "build.props should *not* exist after `Clean`.");
FileAssert.DoesNotExist (designtimebuild_props, "designtimebuild.props should *not* exist after `Clean`.");
}
}

[Test]
public void BuildPropsBreaksConvertResourcesCases ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidSequencePointsMode Condition=" '$(_AndroidSequencePointsMode)' == ''">None</_AndroidSequencePointsMode>
<_InstantRunEnabled Condition=" '$(_InstantRunEnabled)' == '' ">False</_InstantRunEnabled>
<_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props</_AndroidBuildPropertiesCache>
<_AndroidDesignTimeBuildPropertiesCache>$(IntermediateOutputPath)designtimebuild.props</_AndroidDesignTimeBuildPropertiesCache>

<AndroidGenerateJniMarshalMethods Condition=" '$(AndroidGenerateJniMarshalMethods)' == '' ">False</AndroidGenerateJniMarshalMethods>

Expand Down Expand Up @@ -426,6 +427,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidResourcePathsCache Condition=" '$(DesignTimeBuild)' == 'true' And !Exists ('$(_AndroidResourcePathsCache)') ">$(_AndroidResourcePathsDesignTimeCache)</_AndroidResourcePathsCache>
<_AndroidLibraryImportsCache Condition=" '$(DesignTimeBuild)' == 'true' And !Exists ('$(_AndroidLibraryImportsCache)') ">$(_AndroidLibraryImportsDesignTimeCache)</_AndroidLibraryImportsCache>
<_AndroidLibraryProjectImportsCache Condition=" '$(DesignTimeBuild)' == 'true' And !Exists ('$(_AndroidLibraryProjectImportsCache)') ">$(_AndroidLibraryProjectImportsDesignTimeCache)</_AndroidLibraryProjectImportsCache>
<_AndroidBuildPropertiesCache Condition=" '$(DesignTimeBuild)' == 'true' ">$(_AndroidDesignTimeBuildPropertiesCache)</_AndroidBuildPropertiesCache>
</PropertyGroup>
<MakeDir Directories="$(_AndroidDesignTimeResDirIntermediate)" Condition=" '$(DesignTimeBuild)' == 'true' " />
</Target>
Expand Down Expand Up @@ -3033,6 +3035,7 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="$(_AndroidLintConfigFile)" />
<Delete Files="$(_AndroidResourceDesignerFile)" Condition=" '$(AndroidUseIntermediateDesignerFile)' == 'True' " />
<Delete Files="$(_AndroidBuildPropertiesCache)" />
<Delete Files="$(_AndroidDesignTimeBuildPropertiesCache)" />
<Delete Files="$(_AndroidLibraryImportsCache)" />
<Delete Files="$(_AndroidStaticResourcesFlag)" />
<Delete Files="$(_AndroidLibraryProjectImportsCache)" />
Expand Down

0 comments on commit df00b0f

Please sign in to comment.