Skip to content

Commit 76507e8

Browse files
authored
[XABT] Remove support for $(_AndroidGenerateNativeAssembly) = false (typemaps). (#10001)
Context: #9292 In #9292, we removed support for the "instant run" feature. This feature required the use of typemaps that existed outside of the "native" assemblies ($(_AndroidGenerateNativeAssembly) = false). This support is no longer needed, and in fact causes a build error if it is used: Xamarin.Android.Common.targets(2132,3): error XA3006: Could not compile native assembly file: typemaps.x86_64.ll As such, clean up our codebase to remove support for this. Additionally, unused fields in the Module[Debug|Release]Data and TypeMap[Debug|Release]Entry data classes were removed to help make it clearer what data is required to generate typemaps.
1 parent a078ab0 commit 76507e8

File tree

4 files changed

+15
-281
lines changed

4 files changed

+15
-281
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/GenerateTypeMappings.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using Java.Interop.Tools.Cecil;
7-
using Java.Interop.Tools.Diagnostics;
87
using Microsoft.Android.Build.Tasks;
98
using Microsoft.Build.Framework;
109
using Microsoft.Build.Utilities;
@@ -21,9 +20,6 @@ public class GenerateTypeMappings : AndroidTask
2120

2221
public bool Debug { get; set; }
2322

24-
[Required]
25-
public bool GenerateNativeAssembly { get; set; }
26-
2723
[Required]
2824
public string IntermediateOutputDirectory { get; set; } = "";
2925

@@ -50,18 +46,10 @@ public override bool RunTask ()
5046
);
5147

5248
NativeCodeGenState? templateCodeGenState = null;
53-
bool typemapsAreAbiAgnostic = Debug && !GenerateNativeAssembly;
54-
bool first = true;
5549

5650
foreach (var kvp in nativeCodeGenStates) {
57-
if (!first && typemapsAreAbiAgnostic) {
58-
Log.LogDebugMessage ("Typemaps: it's a debug build and type maps are ABI-agnostic, not processing more ABIs");
59-
break;
60-
}
61-
6251
NativeCodeGenState state = kvp.Value;
6352
templateCodeGenState = state;
64-
first = false;
6553
WriteTypeMappings (state);
6654
}
6755

@@ -89,9 +77,7 @@ void WriteTypeMappings (NativeCodeGenState state)
8977
}
9078

9179
var tmg = new TypeMapGenerator (Log, state, androidRuntime);
92-
if (!tmg.Generate (Debug, SkipJniAddNativeMethodRegistrationAttributeScan, TypemapOutputDirectory, GenerateNativeAssembly)) {
93-
throw new XamarinAndroidException (4308, Properties.Resources.XA4308);
94-
}
80+
tmg.Generate (Debug, SkipJniAddNativeMethodRegistrationAttributeScan, TypemapOutputDirectory);
9581

9682
string abi = MonoAndroidHelper.ArchToAbi (state.TargetArch);
9783
var items = new List<ITaskItem> ();

src/Xamarin.Android.Build.Tasks/Utilities/TypeMapCecilAdapter.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#nullable enable
22
using System;
33
using System.Collections.Generic;
4-
using System.IO;
5-
using System.Text;
64
using Java.Interop.Tools.Cecil;
75
using Mono.Cecil;
86

9-
using ModuleDebugData = Xamarin.Android.Tasks.TypeMapGenerator.ModuleDebugData;
107
using ModuleReleaseData = Xamarin.Android.Tasks.TypeMapGenerator.ModuleReleaseData;
118
using ReleaseGenerationState = Xamarin.Android.Tasks.TypeMapGenerator.ReleaseGenerationState;
129
using TypeMapDebugEntry = Xamarin.Android.Tasks.TypeMapGenerator.TypeMapDebugEntry;
@@ -17,59 +14,6 @@ namespace Xamarin.Android.Tasks;
1714
// Converts types from Mono.Cecil to the format used by the typemap generator.
1815
class TypeMapCecilAdapter
1916
{
20-
const string TypemapExtension = ".typemap";
21-
22-
public static Dictionary<string, ModuleDebugData> GetDebugModules (NativeCodeGenState state, string typemapFilesOutputDirectory, Encoding outputEncoding, out int maxModuleFileNameWidth)
23-
{
24-
var modules = new Dictionary<string, ModuleDebugData> (StringComparer.Ordinal);
25-
maxModuleFileNameWidth = 0;
26-
int maxModuleNameWidth = 0;
27-
28-
var javaDuplicates = new Dictionary<string, List<TypeMapDebugEntry>> (StringComparer.Ordinal);
29-
foreach (TypeDefinition td in state.AllJavaTypes) {
30-
UpdateApplicationConfig (state, td);
31-
string moduleName = td.Module.Assembly.Name.Name;
32-
ModuleDebugData module;
33-
34-
if (!modules.TryGetValue (moduleName, out module)) {
35-
string outputFileName = $"{moduleName}{TypemapExtension}";
36-
module = new ModuleDebugData {
37-
EntryCount = 0,
38-
JavaNameWidth = 0,
39-
ManagedNameWidth = 0,
40-
JavaToManagedMap = new List<TypeMapDebugEntry> (),
41-
ManagedToJavaMap = new List<TypeMapDebugEntry> (),
42-
OutputFilePath = Path.Combine (typemapFilesOutputDirectory, outputFileName),
43-
ModuleName = moduleName,
44-
ModuleNameBytes = outputEncoding.GetBytes (moduleName),
45-
};
46-
47-
if (module.ModuleNameBytes.Length > maxModuleNameWidth)
48-
maxModuleNameWidth = module.ModuleNameBytes.Length;
49-
50-
if (outputFileName.Length > maxModuleFileNameWidth)
51-
maxModuleFileNameWidth = outputFileName.Length;
52-
53-
modules.Add (moduleName, module);
54-
}
55-
56-
TypeMapDebugEntry entry = GetDebugEntry (td, state.TypeCache);
57-
HandleDebugDuplicates (javaDuplicates, entry, td, state.TypeCache);
58-
if (entry.JavaName.Length > module.JavaNameWidth)
59-
module.JavaNameWidth = (uint) entry.JavaName.Length + 1;
60-
61-
if (entry.ManagedName.Length > module.ManagedNameWidth)
62-
module.ManagedNameWidth = (uint) entry.ManagedName.Length + 1;
63-
64-
module.JavaToManagedMap.Add (entry);
65-
module.ManagedToJavaMap.Add (entry);
66-
}
67-
68-
SyncDebugDuplicates (javaDuplicates);
69-
70-
return modules;
71-
}
72-
7317
public static (List<TypeMapDebugEntry> javaToManaged, List<TypeMapDebugEntry> managedToJava) GetDebugNativeEntries (NativeCodeGenState state)
7418
{
7519
var javaToManaged = new List<TypeMapDebugEntry> ();
@@ -102,7 +46,6 @@ public static ReleaseGenerationState GetReleaseGenerationState (NativeCodeGenSta
10246
return genState;
10347
}
10448

105-
10649
static void ProcessReleaseType (NativeCodeGenState state, ReleaseGenerationState genState, TypeDefinition td)
10750
{
10851
UpdateApplicationConfig (state, td);
@@ -141,7 +84,6 @@ static void ProcessReleaseType (NativeCodeGenState state, ReleaseGenerationState
14184
JavaName = javaName,
14285
ManagedTypeName = td.FullName,
14386
Token = td.MetadataToken.ToUInt32 (),
144-
AssemblyNameIndex = genState.KnownAssemblies [GetAssemblyName (td)],
14587
SkipInJavaToManaged = ShouldSkipInJavaToManaged (td),
14688
};
14789

0 commit comments

Comments
 (0)