Skip to content

Commit 928c455

Browse files
Temporarily allow native registration attributes in trimmable typemap
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c905061 commit 928c455

3 files changed

Lines changed: 7 additions & 60 deletions

File tree

src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,13 @@ void ScanAssembly (AssemblyIndex index, Dictionary<(string ManagedName, string A
210210

211211
var fullName = MetadataTypeNameResolver.GetFullName (typeDef, index.Reader);
212212

213-
// [JniAddNativeMethodRegistrationAttribute] is not supported by the trimmable typemap
214-
// by design (see XA4251). Detect the attribute *before* any per-type filters below
215-
// (array type, no JNI name, etc.) so the diagnostic fires uniformly regardless of
216-
// whether the type would otherwise have ended up in the typemap.
217-
//
218-
// Skip the per-method walk entirely for the overwhelmingly common case where
219-
// the assembly doesn't even reference the attribute type — the per-assembly
220-
// flag was computed cheaply in AssemblyIndex.Build.
221-
if (index.MayUseJniAddNativeMethodRegistrationAttribute &&
222-
!IsBuiltInJniAddNativeMethodRegistrationType (fullName, index) &&
223-
HasJniAddNativeMethodRegistrationAttribute (typeDef, index)) {
224-
logger?.LogJniAddNativeMethodRegistrationAttributeError (fullName);
225-
}
213+
// Temporarily allow [JniAddNativeMethodRegistrationAttribute] while we investigate
214+
// which scenarios fail later in the trimmable typemap pipeline.
215+
// if (index.MayUseJniAddNativeMethodRegistrationAttribute &&
216+
// !IsBuiltInJniAddNativeMethodRegistrationType (fullName, index) &&
217+
// HasJniAddNativeMethodRegistrationAttribute (typeDef, index)) {
218+
// logger?.LogJniAddNativeMethodRegistrationAttributeError (fullName);
219+
// }
226220

227221
// Determine the JNI name and whether this is a known Java peer.
228222
// Priority:

tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TrimmableTypeMapGeneratorTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,6 @@ public void Execute_WithTestFixtures_ProducesOutputs ()
7474
Assert.Contains (result.GeneratedAssemblies, a => a.Name == "_TestFixtures.TypeMap");
7575
}
7676

77-
[Fact]
78-
public void Execute_WithJniAddNativeMethodRegistrationAttribute_ReportsXA4251 ()
79-
{
80-
// TestFixtures.HandWrittenNativeRegistrationPeer carries [JniAddNativeMethodRegistrationAttribute].
81-
// The trimmable typemap does not support that attribute by design — the orchestrator must
82-
// emit XA4251 so MSBuild fails the build via HasLoggedErrors.
83-
using var peReader = CreateTestFixturePEReader ();
84-
CreateGenerator ().Execute (new List<(string, PEReader)> { ("TestFixtures", peReader) }, new Version (11, 0), new HashSet<string> ());
85-
Assert.Contains (logMessages, m => m.Contains ("XA4251") && m.Contains ("HandWrittenNativeRegistrationPeer"));
86-
}
87-
8877
[Fact]
8978
public void Execute_CollectsDeferredRegistrationTypes_ForAllApplicationAndInstrumentationSubtypes ()
9079
{

tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/JavaPeerScannerTests.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,42 +60,6 @@ public void Scan_MarksFrameworkAssemblyPeers ()
6060
Assert.All (peers, p => Assert.False (p.GenerateArrayEntries, $"{p.ManagedTypeName} should not emit array entries unless referenced from a non-framework assembly."));
6161
}
6262

63-
[Fact]
64-
public void Scan_JniAddNativeMethodRegistrationAttribute_LogsError ()
65-
{
66-
// The trimmable typemap refuses to support [JniAddNativeMethodRegistrationAttribute]
67-
// by design (XA4251). The scanner reports each offending type via the logger.
68-
var errors = new List<string> ();
69-
var logger = new RecordingLogger (errors);
70-
71-
using var scanner = new JavaPeerScanner (logger: logger);
72-
using var peReader = new PEReader (File.OpenRead (TestFixtureAssemblyPath));
73-
var reader = peReader.GetMetadataReader ();
74-
var assemblyName = reader.GetString (reader.GetAssemblyDefinition ().Name);
75-
_ = scanner.Scan (new List<(string, PEReader)> { (assemblyName, peReader) });
76-
77-
Assert.Contains (errors, e => e.Contains ("HandWrittenNativeRegistrationPeer"));
78-
Assert.Contains (errors, e => e.Contains ("NonPeerNativeRegistration"));
79-
Assert.DoesNotContain (errors, e => e.Contains ("OtherNamespaceNativeRegistration"));
80-
Assert.DoesNotContain (errors, e => e.Contains ("MyHelper"));
81-
}
82-
83-
sealed class RecordingLogger (List<string> errors) : ITrimmableTypeMapLogger
84-
{
85-
public void LogNoJavaPeerTypesFound () { }
86-
public void LogJavaPeerScanInfo (int assemblyCount, int peerCount) { }
87-
public void LogGeneratingJcwFilesInfo (int jcwPeerCount, int totalPeerCount) { }
88-
public void LogDeferredRegistrationTypesInfo (int typeCount) { }
89-
public void LogGeneratedTypeMapAssemblyInfo (string assemblyName, int typeCount) { }
90-
public void LogGeneratedRootTypeMapInfo (int assemblyReferenceCount) { }
91-
public void LogGeneratedTypeMapAssembliesInfo (int assemblyCount) { }
92-
public void LogGeneratedJcwFilesInfo (int sourceCount) { }
93-
public void LogRootingManifestReferencedTypeInfo (string javaTypeName, string managedTypeName) { }
94-
public void LogManifestReferencedTypeNotFoundWarning (string javaTypeName) { }
95-
public void LogJniAddNativeMethodRegistrationAttributeError (string managedTypeName) =>
96-
errors.Add ($"XA4251: {managedTypeName}");
97-
}
98-
9963
[Fact]
10064
public void Scan_TypeMetadata_IsCorrect ()
10165
{

0 commit comments

Comments
 (0)