Skip to content

Commit ba85244

Browse files
committed
Address review feedback.
1 parent eae6b50 commit ba85244

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FindTypeMapObjectsStep.cs

+2-16
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,17 @@ public void ProcessAssembly (AssemblyDefinition assembly, StepContext context)
4141
};
4242

4343
if (Debug) {
44-
var (javaToManaged, managedToJava) = TypeMapCecilAdapter.GetDebugNativeEntries (types, Context, out var foundJniNativeRegistration);
44+
var (javaToManaged, managedToJava, foundJniNativeRegistration) = TypeMapCecilAdapter.GetDebugNativeEntries (types, Context);
4545

4646
xml.JavaToManagedDebugEntries.AddRange (javaToManaged);
4747
xml.ManagedToJavaDebugEntries.AddRange (managedToJava);
4848
xml.FoundJniNativeRegistration = foundJniNativeRegistration;
49-
50-
if (!xml.HasDebugEntries) {
51-
Log.LogDebugMessage ($"No Java types found in '{assembly.Name.Name}'");
52-
TypeMapObjectsXmlFile.WriteEmptyFile (destinationTypeMapXml, Log);
53-
return;
54-
}
5549
} else {
5650
var genState = TypeMapCecilAdapter.GetReleaseGenerationState (types, Context, out var foundJniNativeRegistration);
5751
xml.ModuleReleaseData = genState.TempModules.SingleOrDefault ().Value;
58-
59-
if (xml.ModuleReleaseData == null) {
60-
Log.LogDebugMessage ($"No Java types found in '{assembly.Name.Name}'");
61-
TypeMapObjectsXmlFile.WriteEmptyFile (destinationTypeMapXml, Log);
62-
return;
63-
}
6452
}
6553

66-
xml.Export (destinationTypeMapXml);
67-
68-
Log.LogDebugMessage ($"Wrote '{destinationTypeMapXml}', {xml.JavaToManagedDebugEntries.Count} JavaToManagedDebugEntries, {xml.ManagedToJavaDebugEntries.Count} ManagedToJavaDebugEntries, FoundJniNativeRegistration: {xml.FoundJniNativeRegistration}");
54+
xml.Export (destinationTypeMapXml, Log);
6955
}
7056

7157
List<TypeDefinition> ScanForJavaTypes (AssemblyDefinition assembly)

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ class TypeMapCecilAdapter
1616
{
1717
public static (List<TypeMapDebugEntry> javaToManaged, List<TypeMapDebugEntry> managedToJava) GetDebugNativeEntries (NativeCodeGenState state)
1818
{
19-
var (javaToManaged, managedToJava) = GetDebugNativeEntries (state.AllJavaTypes, state.TypeCache, out var foundJniNativeRegistration);
19+
var (javaToManaged, managedToJava, foundJniNativeRegistration) = GetDebugNativeEntries (state.AllJavaTypes, state.TypeCache);
2020

2121
state.JniAddNativeMethodRegistrationAttributePresent = foundJniNativeRegistration;
2222

2323
return (javaToManaged, managedToJava);
2424
}
2525

26-
public static (List<TypeMapDebugEntry> javaToManaged, List<TypeMapDebugEntry> managedToJava) GetDebugNativeEntries (List<TypeDefinition> types, TypeDefinitionCache cache, out bool foundJniNativeRegistration)
26+
public static (List<TypeMapDebugEntry> javaToManaged, List<TypeMapDebugEntry> managedToJava, bool foundJniNativeRegistration) GetDebugNativeEntries (List<TypeDefinition> types, TypeDefinitionCache cache)
2727
{
2828
var javaDuplicates = new Dictionary<string, List<TypeMapDebugEntry>> (StringComparer.Ordinal);
2929
var javaToManaged = new List<TypeMapDebugEntry> ();
3030
var managedToJava = new List<TypeMapDebugEntry> ();
31-
foundJniNativeRegistration = false;
31+
var foundJniNativeRegistration = false;
3232

3333
foreach (var td in types) {
3434
foundJniNativeRegistration = JniAddNativeMethodRegistrationAttributeFound (foundJniNativeRegistration, td);
@@ -42,7 +42,7 @@ public static (List<TypeMapDebugEntry> javaToManaged, List<TypeMapDebugEntry> ma
4242

4343
SyncDebugDuplicates (javaDuplicates);
4444

45-
return (javaToManaged, managedToJava);
45+
return (javaToManaged, managedToJava, foundJniNativeRegistration);
4646
}
4747

4848
public static ReleaseGenerationState GetReleaseGenerationState (NativeCodeGenState state)

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Xamarin.Android.Tasks;
1717

1818
class TypeMapObjectsXmlFile
1919
{
20-
static XmlWriterSettings settings = new XmlWriterSettings {
20+
static readonly XmlWriterSettings settings = new XmlWriterSettings {
2121
Indent = true,
2222
NewLineOnAttributes = false,
2323
OmitXmlDeclaration = true,
@@ -35,8 +35,13 @@ class TypeMapObjectsXmlFile
3535

3636
public bool WasScanned { get; private set; }
3737

38-
public void Export (string filename)
38+
public void Export (string filename, TaskLoggingHelper log)
3939
{
40+
if (!HasDebugEntries && ModuleReleaseData == null) {
41+
WriteEmptyFile (filename, log);
42+
return;
43+
}
44+
4045
using var sw = MemoryStreamPool.Shared.CreateStreamWriter ();
4146

4247
using (var xml = XmlWriter.Create (sw, settings))
@@ -45,6 +50,8 @@ public void Export (string filename)
4550
sw.Flush ();
4651

4752
Files.CopyIfStreamChanged (sw.BaseStream, filename);
53+
54+
log.LogDebugMessage ($"Wrote '{filename}', {JavaToManagedDebugEntries.Count} JavaToManagedDebugEntries, {ManagedToJavaDebugEntries.Count} ManagedToJavaDebugEntries, FoundJniNativeRegistration: {FoundJniNativeRegistration}");
4855
}
4956

5057
void Export (XmlWriter xml)

0 commit comments

Comments
 (0)