-
Notifications
You must be signed in to change notification settings - Fork 568
[TrimmableTypeMap] Remove ManagedPeer from trimmable type map apps #11480
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
Open
simonrozsival
wants to merge
10
commits into
main
Choose a base branch
from
dev/simonrozsival/managedpeer-trimmable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−4
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
efbce2e
Remove ManagedPeer from trimmable type map apps
simonrozsival dbae16f
Disable ManagedPeer registration from Android runtime
simonrozsival f1f0c42
Address trimmable ManagedPeer review feedback
simonrozsival 6a24e88
Update Java.Interop ManagedPeer review coverage
simonrozsival 33c3a13
Disable ManagedPeer through Java.Interop runtime switch
simonrozsival f102337
Update Java.Interop ManagedPeer switch tests
simonrozsival e4039a4
Update Java.Interop ManagedPeer test fix
simonrozsival d1ea7d9
Update Java.Interop ManagedPeer switch fix
simonrozsival 51229e7
Merge origin/main and resolve PR conflicts
Copilot 63effbc
Merge branch 'main' into dev/simonrozsival/managedpeer-trimmable
simonrozsival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,15 @@ | |
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Text.RegularExpressions; | ||
| using Mono.Cecil; | ||
| using NUnit.Framework; | ||
| using Xamarin.Android.Tasks; | ||
| using Xamarin.Android.Tools; | ||
| using Xamarin.ProjectTools; | ||
| using Xamarin.Tools.Zip; | ||
|
|
||
| namespace Xamarin.Android.Build.Tests { | ||
| [TestFixture] | ||
|
|
@@ -319,6 +321,16 @@ public void TrimmableTypeMap_RuntimeArtifacts_ArePackagedInSdk () | |
| }) { | ||
| FileAssert.Exists (Path.Combine (toolsDir, file), $"{file} should exist in the SDK pack."); | ||
| } | ||
|
|
||
| var trimmableJar = Path.Combine (toolsDir, "java_runtime_trimmable.jar"); | ||
| using (var zip = ZipArchive.Open (trimmableJar, FileMode.Open)) { | ||
| zip.AssertDoesNotContainEntry (trimmableJar, "net/dot/jni/ManagedPeer.class"); | ||
| } | ||
|
|
||
| var trimmableDex = Path.Combine (toolsDir, "java_runtime_trimmable.dex"); | ||
| Assert.IsFalse ( | ||
| FileContainsAscii (trimmableDex, "Lnet/dot/jni/ManagedPeer;"), | ||
| "java_runtime_trimmable.dex should not contain the Java ManagedPeer type descriptor."); | ||
| } | ||
|
|
||
| // T1: end-to-end build coverage for [Export] and [ExportField] under trimmable. | ||
|
|
@@ -374,10 +386,11 @@ class ExportShapes : Java.Lang.Object { | |
| string? exportShapesText = null; | ||
| foreach (var f in allJavaFiles) { | ||
| var text = File.ReadAllText (f); | ||
| if (text.Contains ("EchoString") && text.Contains ("InitialFoo")) { | ||
| StringAssert.DoesNotContain ("net.dot.jni.ManagedPeer", text, | ||
| $"Trimmable generated Java source should not reference net.dot.jni.ManagedPeer: {f}"); | ||
| if (exportShapesJava == null && text.Contains ("EchoString") && text.Contains ("InitialFoo")) { | ||
| exportShapesJava = f; | ||
| exportShapesText = text; | ||
| break; | ||
| } | ||
| } | ||
| Assert.IsNotNull (exportShapesJava, | ||
|
|
@@ -408,6 +421,9 @@ class ExportShapes : Java.Lang.Object { | |
| var typemapDir = builder.Output.GetIntermediaryPath ("typemap"); | ||
| var typemapDlls = Directory.GetFiles (typemapDir, "*.TypeMap.dll"); | ||
| Assert.IsNotEmpty (typemapDlls, "Trimmable typemap should produce at least one *.TypeMap.dll."); | ||
|
|
||
| var apk = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk"); | ||
| AssertApkDexDoesNotContain (apk, "Lnet/dot/jni/ManagedPeer;"); | ||
| } | ||
|
|
||
| // T6: trim-warning baseline for [Export] under trimmable. | ||
|
|
@@ -516,6 +532,41 @@ public ConcreteProvider (Android.Content.Context context) : base (context) { } | |
| Assert.IsTrue (builder.Build (proj), "Build should have succeeded — abstract types with protected ctors should not cause XAGTT7009."); | ||
| } | ||
|
|
||
| static void AssertApkDexDoesNotContain (string apk, string value) | ||
| { | ||
| FileAssert.Exists (apk); | ||
| using var zip = ZipArchive.Open (apk, FileMode.Open); | ||
| var dexEntries = zip | ||
| .Where (entry => entry.FullName.StartsWith ("classes", StringComparison.Ordinal) && | ||
| entry.FullName.EndsWith (".dex", StringComparison.Ordinal)) | ||
| .ToArray (); | ||
| Assert.IsNotEmpty (dexEntries, $"{apk} should contain at least one dex file."); | ||
|
|
||
| foreach (var entry in dexEntries) { | ||
| Assert.IsFalse ( | ||
| EntryContainsAscii (entry, value), | ||
| $"{entry.FullName} should not contain {value}."); | ||
| } | ||
| } | ||
|
|
||
| static bool EntryContainsAscii (ZipEntry entry, string value) | ||
| { | ||
| using var stream = new MemoryStream (); | ||
| entry.Extract (stream); | ||
| return ContainsAscii (stream.ToArray (), value); | ||
| } | ||
|
|
||
| static bool FileContainsAscii (string file, string value) | ||
| { | ||
| return ContainsAscii (File.ReadAllBytes (file), value); | ||
| } | ||
|
|
||
| static bool ContainsAscii (byte [] data, string value) | ||
| { | ||
| var pattern = Encoding.ASCII.GetBytes (value); | ||
| return data.AsSpan ().IndexOf (pattern) >= 0; | ||
| } | ||
|
|
||
| static void AssertTrimmableTypeMapOutputs (string typemapDir) | ||
| { | ||
| DirectoryAssert.Exists (typemapDir); | ||
|
|
@@ -524,9 +575,9 @@ static void AssertTrimmableTypeMapOutputs (string typemapDir) | |
|
|
||
| var javaDir = Path.Combine (typemapDir, "java"); | ||
| DirectoryAssert.Exists (javaDir, "Trimmable JCW Java output directory should exist."); | ||
|
|
||
| var javaFiles = Directory.GetFiles (javaDir, "*.java", SearchOption.AllDirectories); | ||
| Assert.IsNotEmpty (javaFiles, "At least one trimmable JCW Java source file should be generated."); | ||
| Assert.IsNotEmpty (javaFiles, "At least one trimmable JCW Java source file should be generated."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Rule: Remove unused code (Postmortem |
||
| } | ||
| DynamicCodeSupportProfile BuildDynamicCodeSupportProfile (string typemapImplementation, bool? dynamicCodeSupport) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 Testing —
StringAssert.DoesNotContainwill fail and abort the loop on the first file that contains the string, so you won't see failures from subsequent files. If the goal is to check all generated Java files (which seems to be why thebreakwas removed), consider collecting violations first and asserting once at the end, e.g. withAssert.Multipleor by accumulating failures into a list. Current behavior is fine for catching the issue but may make debugging harder if multiple files are affected.Rule: Test assertions must be specific