Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,9 @@ module Xamarin.Android.Tests
}

[Test]
public void DesignTimeBuildHasAndroidDefines ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime)
public void DesignTimeBuildHasAndroidDefines (
[Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime,
[Values (false, true)] bool disableImplicitFrameworkDefines)
{
bool isRelease = runtime == AndroidRuntime.NativeAOT;
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
Expand All @@ -977,6 +979,7 @@ public void DesignTimeBuildHasAndroidDefines ([Values (AndroidRuntime.CoreCLR, A
IsRelease = isRelease,
};
proj.SetRuntime (runtime);
proj.SetProperty ("DisableImplicitFrameworkDefines", disableImplicitFrameworkDefines.ToString ());
var androidDefines = new List<string> ();
for (int i = 1; i <= XABuildConfig.AndroidDefaultTargetDotnetApiLevel.Major; ++i) {
androidDefines.Add ($"!__ANDROID_{i}__");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,43 @@ public void ManifestMergerIncremental ([Values (AndroidRuntime.CoreCLR, AndroidR
}
}

[Test]
public void AndroidDefineConstantsAreOrderIndependent ()
{
var path = Path.Combine ("temp", TestName);
var lib = new XamarinAndroidLibraryProject {
ProjectName = "Library",
};
lib.SetProperty ("DisableImplicitFrameworkDefines", "true");
lib.Imports.Add (new Import ("DefineConstants.targets") {
TextContent = () => """
<Project>
<Target Name="_AddTestDefineConstant">
<PropertyGroup>
<DefineConstants>$(DefineConstants);TEST_DEFINE</DefineConstants>
</PropertyGroup>
</Target>
<Target Name="_WriteTestDefineConstants">
<WriteLinesToFile File="$(IntermediateOutputPath)define-constants.txt" Lines="$(DefineConstants)" Overwrite="true" />
</Target>
</Project>
"""
});

using (var builder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) {
builder.Target = "_ResolveMonoAndroidSdks,_AddTestDefineConstant,Compile,_WriteTestDefineConstants";
Assert.IsTrue (builder.Build (lib), "first library build should have succeeded.");
var firstDefineConstants = builder.Output.GetIntermediaryAsText ("define-constants.txt");

builder.Target = "_AddTestDefineConstant,_ResolveMonoAndroidSdks,Compile,_WriteTestDefineConstants";
Assert.IsTrue (builder.Build (lib, doNotCleanupOnUpdate: true, saveProject: false), "second library build should have succeeded.");
Assert.AreEqual (firstDefineConstants, builder.Output.GetIntermediaryAsText ("define-constants.txt"),
"DefineConstants should not depend on target execution order.");
Assert.IsFalse (builder.LastBuildOutput.Any (line => line.Contains ("Building target \"CoreCompile\" completely.")),
"CoreCompile should not run when define constants are reordered.");
Comment thread
jonathanpeppers marked this conversation as resolved.
}
}

[Test]
public void ProduceReferenceAssembly ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime)
{
Expand Down
12 changes: 8 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,6 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="AndroidDefineConstants" ItemName="AndroidDefineConstants" />
</GetAndroidDefineConstants>

<PropertyGroup>
<DefineConstants>$(DefineConstants);@(AndroidDefineConstants)</DefineConstants>
</PropertyGroup>

<!-- Setup $(AndroidApplicationJavaClass) -->
<PropertyGroup>
<AndroidApplicationJavaClass Condition="'$(AndroidApplicationJavaClass)' == '' And $(AndroidEnableMultiDex)">android.support.multidex.MultiDexApplication</AndroidApplicationJavaClass>
Expand All @@ -822,6 +818,14 @@ because xbuild doesn't support framework reference assemblies.
<Message Text="Application Java class: $(AndroidApplicationJavaClass)" />
</Target>

<Target Name="_AddAndroidDefineConstants"
BeforeTargets="BeforeCompile;CoreCompile"
DependsOnTargets="_ResolveMonoAndroidSdks;AddImplicitDefineConstants">
<PropertyGroup>
<DefineConstants>$(DefineConstants);@(AndroidDefineConstants)</DefineConstants>
</PropertyGroup>
</Target>

<Target Name="AndroidPrepareForBuild" DependsOnTargets="$(_OnResolveMonoAndroidSdks);$(AndroidPrepareForBuildDependsOn)" />

<!-- uploadflags.txt
Expand Down
Loading