Skip to content

Commit df00b0f

Browse files
[Xamarin.Android.Build.Tasks] use designtimebuild.props
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.
1 parent 0ab8ec1 commit df00b0f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,41 @@ public void FooMethod () {
120120
}
121121
}
122122

123+
[Test]
124+
public void SwitchBetweenDesignTimeBuild ()
125+
{
126+
var proj = new XamarinAndroidApplicationProject ();
127+
128+
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
129+
Assert.IsTrue (b.Build (proj), "first *regular* build should have succeeded.");
130+
var build_props = b.Output.GetIntermediaryPath ("build.props");
131+
var designtimebuild_props = b.Output.GetIntermediaryPath ("designtimebuild.props");
132+
FileAssert.Exists (build_props, "build.props should exist after a first `Build`.");
133+
FileAssert.DoesNotExist (designtimebuild_props, "designtimebuild.props should *not* exist after a first `Build`.");
134+
135+
b.Target = "Compile";
136+
Assert.IsTrue (b.Build (proj, parameters: new [] { "DesignTimeBuild=True" }), "first design-time build should have succeeded.");
137+
FileAssert.Exists (build_props, "build.props should exist after a design-time build.");
138+
FileAssert.Exists (designtimebuild_props, "designtimebuild.props should exist after a design-time build.");
139+
140+
b.Target = "Build";
141+
Assert.IsTrue (b.Build (proj), "second *regular* build should have succeeded.");
142+
FileAssert.Exists (build_props, "build.props should exist after the second `Build`.");
143+
FileAssert.Exists (designtimebuild_props, "designtimebuild.props should exist after the second `Build`.");
144+
145+
//NOTE: none of these targets should run, since we have not actually changed anything!
146+
Assert.IsTrue (b.Output.IsTargetSkipped ("_UpdateAndroidResgen"), "`_UpdateAndroidResgen` should be skipped!");
147+
//TODO: I would like to add this assertion, but it requires: https://github.com/xamarin/xamarin-android/pull/1930
148+
//Assert.IsTrue (b.Output.IsTargetSkipped ("_LinkAssembliesNoShrink"), "`_LinkAssembliesNoShrink` should be skipped!");
149+
150+
b.Target = "Clean";
151+
Assert.IsTrue (b.Build (proj), "clean should have succeeded.");
152+
153+
FileAssert.DoesNotExist (build_props, "build.props should *not* exist after `Clean`.");
154+
FileAssert.DoesNotExist (designtimebuild_props, "designtimebuild.props should *not* exist after `Clean`.");
155+
}
156+
}
157+
123158
[Test]
124159
public void BuildPropsBreaksConvertResourcesCases ()
125160
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
305305
<_AndroidSequencePointsMode Condition=" '$(_AndroidSequencePointsMode)' == ''">None</_AndroidSequencePointsMode>
306306
<_InstantRunEnabled Condition=" '$(_InstantRunEnabled)' == '' ">False</_InstantRunEnabled>
307307
<_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props</_AndroidBuildPropertiesCache>
308+
<_AndroidDesignTimeBuildPropertiesCache>$(IntermediateOutputPath)designtimebuild.props</_AndroidDesignTimeBuildPropertiesCache>
308309

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

@@ -426,6 +427,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
426427
<_AndroidResourcePathsCache Condition=" '$(DesignTimeBuild)' == 'true' And !Exists ('$(_AndroidResourcePathsCache)') ">$(_AndroidResourcePathsDesignTimeCache)</_AndroidResourcePathsCache>
427428
<_AndroidLibraryImportsCache Condition=" '$(DesignTimeBuild)' == 'true' And !Exists ('$(_AndroidLibraryImportsCache)') ">$(_AndroidLibraryImportsDesignTimeCache)</_AndroidLibraryImportsCache>
428429
<_AndroidLibraryProjectImportsCache Condition=" '$(DesignTimeBuild)' == 'true' And !Exists ('$(_AndroidLibraryProjectImportsCache)') ">$(_AndroidLibraryProjectImportsDesignTimeCache)</_AndroidLibraryProjectImportsCache>
430+
<_AndroidBuildPropertiesCache Condition=" '$(DesignTimeBuild)' == 'true' ">$(_AndroidDesignTimeBuildPropertiesCache)</_AndroidBuildPropertiesCache>
429431
</PropertyGroup>
430432
<MakeDir Directories="$(_AndroidDesignTimeResDirIntermediate)" Condition=" '$(DesignTimeBuild)' == 'true' " />
431433
</Target>
@@ -3033,6 +3035,7 @@ because xbuild doesn't support framework reference assemblies.
30333035
<Delete Files="$(_AndroidLintConfigFile)" />
30343036
<Delete Files="$(_AndroidResourceDesignerFile)" Condition=" '$(AndroidUseIntermediateDesignerFile)' == 'True' " />
30353037
<Delete Files="$(_AndroidBuildPropertiesCache)" />
3038+
<Delete Files="$(_AndroidDesignTimeBuildPropertiesCache)" />
30363039
<Delete Files="$(_AndroidLibraryImportsCache)" />
30373040
<Delete Files="$(_AndroidStaticResourcesFlag)" />
30383041
<Delete Files="$(_AndroidLibraryProjectImportsCache)" />

0 commit comments

Comments
 (0)