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

Use the new RegisterTaskObject API #7709

Merged
merged 7 commits into from
Jan 19, 2023
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
2 changes: 1 addition & 1 deletion external/xamarin-android-tools
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Aapt : AndroidAsyncTask
AssemblyIdentityMap assemblyMap = new AssemblyIdentityMap ();
string resourceDirectory;

Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4);
Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4, ProjectSpecificTaskObjectKey);

bool ManifestIsUpToDate (string manifestFile)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class Aapt2 : AndroidAsyncTask {
private static readonly int DefaultMaxAapt2Daemons = 6;
protected Dictionary<string, string> _resource_name_case_map;

Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4);
Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4, ProjectSpecificTaskObjectKey);

protected virtual int ProcessorCount => Environment.ProcessorCount;

Expand Down
22 changes: 11 additions & 11 deletions src/Xamarin.Android.Build.Tasks/Tasks/AndroidComputeResPaths.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// AndroidUpdateResDir.cs
//
//
// Author:
// Michael Hutchinson <[email protected]>
//
//
// Copyright (c) 2010 Novell, Inc. (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -41,18 +41,18 @@ public class AndroidComputeResPaths : AndroidTask

[Required]
public ITaskItem[] ResourceFiles { get; set; }

[Required]
public string IntermediateDir { get; set; }

public string Prefixes { get; set; }

public bool LowercaseFilenames { get; set; }

public string ProjectDir { get; set; }

public string AndroidLibraryFlatFilesDirectory { get; set; }

[Output]
public ITaskItem[] IntermediateFiles { get; set; }

Expand All @@ -63,7 +63,7 @@ public override bool RunTask ()
{
var intermediateFiles = new List<ITaskItem> (ResourceFiles.Length);
var resolvedFiles = new List<ITaskItem> (ResourceFiles.Length);

string[] prefixes = Prefixes != null ? Prefixes.Split (';') : null;
if (prefixes != null) {
for (int i = 0; i < prefixes.Length; i++) {
Expand Down Expand Up @@ -145,7 +145,7 @@ public override bool RunTask ()

IntermediateFiles = intermediateFiles.ToArray ();
ResolvedResourceFiles = resolvedFiles.ToArray ();
MonoAndroidHelper.SaveResourceCaseMap (BuildEngine4, nameCaseMap);
MonoAndroidHelper.SaveResourceCaseMap (BuildEngine4, nameCaseMap, ProjectSpecificTaskObjectKey);
return !Log.HasLoggedErrors;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ string RegisterGroupWidgets (ICollection<LayoutWidget> widgets)
{
string key = Guid.NewGuid ().ToString ();
LogDebugMessage ($"Registering {widgets?.Count} widgets for key {key}");
BuildEngine4.RegisterTaskObjectAssemblyLocal (key, widgets, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false);
BuildEngine4.RegisterTaskObjectAssemblyLocal (ProjectSpecificTaskObjectKey (key), widgets, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: false);
return key;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/ConvertCustomView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class ConvertCustomView : AndroidTask {
public ITaskItem [] Processed { get; set; }

Dictionary<string, string> _resource_name_case_map;
Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4);
Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4, ProjectSpecificTaskObjectKey);

public override bool RunTask ()
{
var acw_map = MonoAndroidHelper.LoadMapFile (BuildEngine4, AcwMapFile, StringComparer.Ordinal);
var acw_map = MonoAndroidHelper.LoadMapFile (BuildEngine4, Path.GetFullPath (AcwMapFile), StringComparer.Ordinal);
var customViewMap = MonoAndroidHelper.LoadCustomViewMapFile (BuildEngine4, CustomViewMapFile);
var processed = new HashSet<string> ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ConvertResourcesCases : AndroidTask
Dictionary<string,string> _resource_name_case_map;
Dictionary<string, HashSet<string>> customViewMap;

Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4);
Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4, ProjectSpecificTaskObjectKey);

public override bool RunTask ()
{
Expand Down Expand Up @@ -73,7 +73,7 @@ void FixupResources (ITaskItem item)
lastUpdate = File.GetLastWriteTimeUtc (AndroidConversionFlagFile);
}
Log.LogDebugMessage (" AndroidConversionFlagFile modified: {0}", lastUpdate);

var resourcedirectories = new List<string> ();
foreach (var dir in ResourceDirectories) {
if (dir == item)
Expand Down
4 changes: 2 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ bool CreateJavaSources (IEnumerable<TypeDefinition> javaTypes, TypeDefinitionCac
}

if (useMarshalMethods) {
BuildEngine4.RegisterTaskObjectAssemblyLocal (MarshalMethodsRegisterTaskKey, new MarshalMethodsState (classifier.MarshalMethods), RegisteredTaskObjectLifetime.Build);
BuildEngine4.RegisterTaskObjectAssemblyLocal (ProjectSpecificTaskObjectKey (MarshalMethodsRegisterTaskKey), new MarshalMethodsState (classifier.MarshalMethods), RegisteredTaskObjectLifetime.Build);
}

return ok;
Expand Down Expand Up @@ -575,7 +575,7 @@ void WriteTypeMappings (List<TypeDefinition> types, TypeDefinitionCache cache)
if (!tmg.Generate (Debug, SkipJniAddNativeMethodRegistrationAttributeScan, types, cache, TypemapOutputDirectory, GenerateNativeAssembly, out ApplicationConfigTaskState appConfState))
throw new XamarinAndroidException (4308, Properties.Resources.XA4308);
GeneratedBinaryTypeMaps = tmg.GeneratedBinaryTypeMaps.ToArray ();
BuildEngine4.RegisterTaskObjectAssemblyLocal (ApplicationConfigTaskState.RegisterTaskObjectKey, appConfState, RegisteredTaskObjectLifetime.Build);
BuildEngine4.RegisterTaskObjectAssemblyLocal (ProjectSpecificTaskObjectKey (ApplicationConfigTaskState.RegisterTaskObjectKey), appConfState, RegisteredTaskObjectLifetime.Build);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void Generate (JniRemappingAssemblyGenerator jniRemappingGenerator, int typeRepl
}

BuildEngine4.RegisterTaskObjectAssemblyLocal (
JniRemappingNativeCodeInfoKey,
ProjectSpecificTaskObjectKey (JniRemappingNativeCodeInfoKey),
new JniRemappingNativeCodeInfo (typeReplacementsCount, jniRemappingGenerator.ReplacementMethodIndexEntryCount),
RegisteredTaskObjectLifetime.Build
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void GenerateSourceForLayoutGroup (BindingGenerator generator, LayoutGroup group
if (!GetRequiredMetadata (item, CalculateLayoutCodeBehind.WidgetCollectionKeyMetadata, out collectionKey))
return;

ICollection<LayoutWidget> widgets = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<ICollection<LayoutWidget>> (collectionKey, RegisteredTaskObjectLifetime.Build);
ICollection<LayoutWidget> widgets = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<ICollection<LayoutWidget>> (ProjectSpecificTaskObjectKey (collectionKey), RegisteredTaskObjectLifetime.Build);
if ((widgets?.Count ?? 0) == 0) {
string inputPaths = String.Join ("; ", resourceItems.Select (i => i.ItemSpec));
LogCodedWarning ("XA4222", Properties.Resources.XA4222, inputPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ void AddEnvironment ()
}

bool haveRuntimeConfigBlob = !String.IsNullOrEmpty (RuntimeConfigBinFilePath) && File.Exists (RuntimeConfigBinFilePath);
var appConfState = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<ApplicationConfigTaskState> (ApplicationConfigTaskState.RegisterTaskObjectKey, RegisteredTaskObjectLifetime.Build);
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey, RegisteredTaskObjectLifetime.Build);
var appConfState = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<ApplicationConfigTaskState> (ProjectSpecificTaskObjectKey (ApplicationConfigTaskState.RegisterTaskObjectKey), RegisteredTaskObjectLifetime.Build);
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (ProjectSpecificTaskObjectKey (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey), RegisteredTaskObjectLifetime.Build);
var appConfigAsmGen = new ApplicationConfigNativeAssemblyGenerator (environmentVariables, systemProperties, Log) {
IsBundledApp = IsBundledApplication,
UsesMonoAOT = usesMonoAOT,
Expand Down Expand Up @@ -404,7 +404,7 @@ void AddEnvironment ()
};
appConfigAsmGen.Init ();

var marshalMethodsState = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<MarshalMethodsState> (GenerateJavaStubs.MarshalMethodsRegisterTaskKey, RegisteredTaskObjectLifetime.Build);
var marshalMethodsState = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<MarshalMethodsState> (ProjectSpecificTaskObjectKey (GenerateJavaStubs.MarshalMethodsRegisterTaskKey), RegisteredTaskObjectLifetime.Build);
MarshalMethodsNativeAssemblyGenerator marshalMethodsAsmGen;

if (enableMarshalMethods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override bool RunTask ()

var javaPlatformDirectory = Path.GetDirectoryName (JavaPlatformJarPath);

resource_fixup = MonoAndroidHelper.LoadMapFile (BuildEngine4, CaseMapFile, StringComparer.OrdinalIgnoreCase);
resource_fixup = MonoAndroidHelper.LoadMapFile (BuildEngine4, Path.GetFullPath (CaseMapFile), StringComparer.OrdinalIgnoreCase);

// Parse out the resources from the R.java file
CodeTypeDeclaration resources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool Run(DirectoryAssemblyResolver res)

string assemblyName = Path.GetFileNameWithoutExtension (OutputFile.ItemSpec);

resource_fixup = MonoAndroidHelper.LoadMapFile (BuildEngine4, CaseMapFile, StringComparer.OrdinalIgnoreCase);
resource_fixup = MonoAndroidHelper.LoadMapFile (BuildEngine4, Path.GetFullPath (CaseMapFile), StringComparer.OrdinalIgnoreCase);
// Generate an assembly which contains all the values in the provided
// R.txt file.
var mp = new ModuleParameters ();
Expand Down
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/GenerateRtxt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override bool RunTask ()
// Parse the Resource files and then generate an R.txt file
var writer = new RtxtWriter ();

var resource_fixup = MonoAndroidHelper.LoadMapFile (BuildEngine4, CaseMapFile, StringComparer.OrdinalIgnoreCase);
var resource_fixup = MonoAndroidHelper.LoadMapFile (BuildEngine4, Path.GetFullPath (CaseMapFile), StringComparer.OrdinalIgnoreCase);

var javaPlatformDirectory = Path.GetDirectoryName (JavaPlatformJarPath);
var parser = new FileResourceParser () { Log = Log, JavaPlatformDirectory = javaPlatformDirectory, ResourceFlagFile = ResourceFlagFile};
Expand Down
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Lint : AndroidToolTask
string text;
string type;

Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4);
Dictionary<string, string> resource_name_case_map => _resource_name_case_map ??= MonoAndroidHelper.LoadResourceCaseMap (BuildEngine4, ProjectSpecificTaskObjectKey);

[Required]
public string TargetDirectory { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ public void AllProjectsHaveSameOutputDirectory()
sb.Dispose ();
}

[Test]
public void BuildSolutionWithMultipleProjectsInParallel ()
{
var testPath = Path.Combine ("temp", "BuildSolutionWithMultipleProjects");
var sb = new SolutionBuilder("BuildSolutionWithMultipleProjects.sln") {
SolutionPath = Path.Combine (Root, testPath),
MaxCpuCount = 4,
};
for (int i=1; i <= 4; i++) {
var app1 = new XamarinAndroidApplicationProject () {
ProjectName = $"App{i}",
PackageName = $"com.companyname.App{i}",
AotAssemblies = true,
IsRelease = true,
};
app1.SetProperty ("AndroidEnableMarshalMethods", "True");
sb.Projects.Add (app1);
}
sb.BuildingInsideVisualStudio = false;
Assert.IsTrue (sb.Build (), "Build of solution should have succeeded");
Assert.IsTrue (sb.ReBuild (), "ReBuild of solution should have succeeded");
sb.Dispose ();
}

[Test]
public void JavacTaskDoesNotRunOnSecondBuild ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void Aapt2CompileFixesUpErrors ()
MonoAndroidHelper.SaveResourceCaseMap (engine, new Dictionary<string, string> {
{ $"layout{directorySeperator}main.axml", $"Layout{directorySeperator}Main.xml" },
{ $"values{directorySeperator}strings.xml", $"Values{directorySeperator}Strings.xml" },
});
}, (o) => { return (o, path);} );
var task = new Aapt2Compile {
BuildEngine = engine,
ToolPath = GetPathToAapt2 (),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public void RtxtGeneratorOutput ()
BuildEngine = engine,
RTxtFile = rTxt,
ResourceDirectory = resPath,
CaseMapFile = Path.Combine (Root, path, "case_map.txt"),
JavaPlatformJarPath = Path.Combine (AndroidSdkDirectory, "platforms", $"android-{platform}", "android.jar"),
ResourceFlagFile = Path.Combine (Root, path, "res.flag"),
AdditionalResourceDirectories = new string[] {
Expand Down Expand Up @@ -600,6 +601,7 @@ public void CompareAapt2AndManagedParserOutput ()
task.Namespace = "MonoAndroidApplication4.MonoAndroidApplication4";
task.NetResgenOutputFile = Path.Combine (Root, path, "Resource.designer.aapt2.cs");
task.ProjectDir = Path.Combine (Root, path);
task.CaseMapFile = Path.Combine (Root, path, "case_map.txt");
task.ResourceDirectory = Path.Combine (Root, path, "res") + Path.DirectorySeparatorChar;
task.Resources = new TaskItem [] {
new TaskItem (Path.Combine (Root, path, "res", "values", "strings.xml"), new Dictionary<string, string> () {
Expand Down Expand Up @@ -667,6 +669,7 @@ public void CompareAaptAndManagedParserOutputWithCustomIds ()
task.Namespace = "MonoAndroidApplication4.MonoAndroidApplication4";
task.NetResgenOutputFile = Path.Combine (Root, path, "Resource.designer.aapt.cs");
task.ProjectDir = Path.Combine (Root, path);
task.CaseMapFile = Path.Combine (Root, path, "case_map.txt");
task.ResourceDirectory = Path.Combine (Root, path, "res") + Path.DirectorySeparatorChar;
task.Resources = new TaskItem [] {
new TaskItem (Path.Combine (Root, path, "res", "values", "strings.xml"), new Dictionary<string, string> () {
Expand Down Expand Up @@ -806,6 +809,7 @@ int styleable ElevenAttributes_attr09 9
task.Namespace = "Foo.Foo";
task.NetResgenOutputFile = Path.Combine (Root, path, "Resource.designer.cs");
task.ProjectDir = Path.Combine (Root, path);
task.CaseMapFile = Path.Combine (Root, path, "case_map.txt");
task.ResourceDirectory = Path.Combine (Root, path, "res");
task.Resources = new TaskItem [] {};
task.IsApplication = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,11 @@ public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platfor

static readonly string ResourceCaseMapKey = $"{nameof (MonoAndroidHelper)}_ResourceCaseMap";

public static void SaveResourceCaseMap (IBuildEngine4 engine, Dictionary<string, string> map) =>
engine.RegisterTaskObjectAssemblyLocal (ResourceCaseMapKey, map, RegisteredTaskObjectLifetime.Build);
public static void SaveResourceCaseMap (IBuildEngine4 engine, Dictionary<string, string> map, Func<object, object> keyCallback) =>
engine.RegisterTaskObjectAssemblyLocal (keyCallback (ResourceCaseMapKey), map, RegisteredTaskObjectLifetime.Build);

public static Dictionary<string, string> LoadResourceCaseMap (IBuildEngine4 engine) =>
engine.GetRegisteredTaskObjectAssemblyLocal<Dictionary<string, string>> (ResourceCaseMapKey, RegisteredTaskObjectLifetime.Build) ?? new Dictionary<string, string> (0);
public static Dictionary<string, string> LoadResourceCaseMap (IBuildEngine4 engine, Func<object, object> keyCallback) =>
engine.GetRegisteredTaskObjectAssemblyLocal<Dictionary<string, string>> (keyCallback (ResourceCaseMapKey), RegisteredTaskObjectLifetime.Build) ?? new Dictionary<string, string> (0);

public static string FixUpAndroidResourcePath (string file, string resourceDirectory, string resourceDirectoryFullPath, Dictionary<string, string> resource_name_case_map)
{
Expand Down