Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] use designtime/build.props #1957

Merged
merged 1 commit into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Resource.designer.cs
logcat-*.txt
apk-sizes-*.txt
*.rawproto
*.binlog
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,43 @@ 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 designtime_build_props = b.Output.GetIntermediaryPath (Path.Combine ("designtime", "build.props"));
FileAssert.Exists (build_props, "build.props should exist after a first `Build`.");
FileAssert.DoesNotExist (designtime_build_props, "designtime/build.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 (designtime_build_props, "designtime/build.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 (designtime_build_props, "designtime/build.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: We would like for this assertion to work, but the <Compile /> item group changes between DTB and regular builds
// $(IntermediateOutputPath)designtime\Resource.designer.cs -> Resources\Resource.designer.cs
// And so the built assembly changes between DTB and regular build, triggering `_LinkAssembliesNoShrink`
//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.Exists (designtime_build_props, "designtime/build.props should exist after `Clean`.");
}
}

[Test]
public void BuildPropsBreaksConvertResourcesCases ()
{
Expand Down
18 changes: 10 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidProguardInputJarFilter>(!META-INF/MANIFEST.MF)</_AndroidProguardInputJarFilter>
<_AndroidAapt2VersionFile>$(IntermediateOutputPath)aapt2.version</_AndroidAapt2VersionFile>
<_AndroidNuGetStampFile>$(IntermediateOutputPath)$(MSBuildProjectName).nuget.stamp</_AndroidNuGetStampFile>
<_AndroidIntermediateDesignTimeBuildDirectory>$(IntermediateOutputPath)designtime\</_AndroidIntermediateDesignTimeBuildDirectory>

<!-- $(EnableProguard) is an obsolete property that should be removed at some stage. -->
<AndroidEnableProguard Condition="'$(AndroidEnableProguard)'==''">$(EnableProguard)</AndroidEnableProguard>
Expand Down Expand Up @@ -305,6 +306,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>$(_AndroidIntermediateDesignTimeBuildDirectory)build.props</_AndroidDesignTimeBuildPropertiesCache>

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

Expand Down Expand Up @@ -426,8 +428,9 @@ 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' " />
<MakeDir Directories="$(_AndroidIntermediateDesignTimeBuildDirectory)" Condition=" '$(DesignTimeBuild)' == 'true' " />
</Target>

<PropertyGroup>
Expand Down Expand Up @@ -1147,11 +1150,10 @@ because xbuild doesn't support framework reference assemblies.
<_AndroidStaticResourcesFlag>$(IntermediateOutputPath)static.flag</_AndroidStaticResourcesFlag>
<_AndroidResourcesCacheFile>$(IntermediateOutputPath)mergeresources.cache</_AndroidResourcesCacheFile>
<AndroidUseManagedDesignTimeResourceGenerator Condition=" '$(AndroidUseManagedDesignTimeResourceGenerator)' == '' " >True</AndroidUseManagedDesignTimeResourceGenerator>
<_AndroidDesignTimeResDirIntermediate>$(IntermediateOutputPath)designtime\</_AndroidDesignTimeResDirIntermediate>
<_AndroidResourcePathsDesignTimeCache>$(_AndroidDesignTimeResDirIntermediate)resourcepaths.cache</_AndroidResourcePathsDesignTimeCache>
<_AndroidLibraryImportsDesignTimeCache>$(_AndroidDesignTimeResDirIntermediate)libraryimports.cache</_AndroidLibraryImportsDesignTimeCache>
<_AndroidLibraryProjectImportsDesignTimeCache>$(_AndroidDesignTimeResDirIntermediate)libraryprojectimports.cache</_AndroidLibraryProjectImportsDesignTimeCache>
<_AndroidManagedResourceDesignerFile>$(_AndroidDesignTimeResDirIntermediate)$(_AndroidResourceDesigner)</_AndroidManagedResourceDesignerFile>
<_AndroidResourcePathsDesignTimeCache>$(_AndroidIntermediateDesignTimeBuildDirectory)resourcepaths.cache</_AndroidResourcePathsDesignTimeCache>
<_AndroidLibraryImportsDesignTimeCache>$(_AndroidIntermediateDesignTimeBuildDirectory)libraryimports.cache</_AndroidLibraryImportsDesignTimeCache>
<_AndroidLibraryProjectImportsDesignTimeCache>$(_AndroidIntermediateDesignTimeBuildDirectory)libraryprojectimports.cache</_AndroidLibraryProjectImportsDesignTimeCache>
<_AndroidManagedResourceDesignerFile>$(_AndroidIntermediateDesignTimeBuildDirectory)$(_AndroidResourceDesigner)</_AndroidManagedResourceDesignerFile>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -1216,7 +1218,7 @@ because xbuild doesn't support framework reference assemblies.
Inputs="$(_ManagedUpdateAndroidResgenInputs);$(_AndroidResourcePathsCache);$(_AndroidLibraryProjectImportsCache);$(_AndroidLibraryImportsCache);"
Outputs="$(_AndroidManagedResourceDesignerFile)"
DependsOnTargets="_CreatePropertiesCache;_ExtractLibraryProjectImports;_CreateAdditionalResourceCache">
<MakeDir Directories="$(_AndroidDesignTimeResDirIntermediate)" />
<MakeDir Directories="$(_AndroidIntermediateDesignTimeBuildDirectory)" />
<!-- Parse primary R.java and create Resources.Designer.cs -->
<GenerateResourceDesigner
ContinueOnError="$(DesignTimeBuild)"
Expand Down Expand Up @@ -2985,7 +2987,7 @@ because xbuild doesn't support framework reference assemblies.
</Target>

<Target Name="_CleanDesignTimeIntermediateDir">
<RemoveDirFixed Directories="$(_AndroidDesignTimeResDirIntermediate)" Condition="Exists ('$(_AndroidDesignTimeResDirIntermediate)')" />
<RemoveDirFixed Directories="$(_AndroidIntermediateDesignTimeBuildDirectory)" Condition="Exists ('$(_AndroidIntermediateDesignTimeBuildDirectory)')" />
</Target>

<Target Name="_CleanGeneratedDeploymentFiles">
Expand Down