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

Track Java.Interop.Tools.JavaCallableWrappers changes #8701

Merged
merged 5 commits into from
Feb 21, 2024
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/Java.Interop
25 changes: 17 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using Xamarin.Android.Tools;
using Microsoft.Android.Build.Tasks;
using Java.Interop.Tools.JavaCallableWrappers.Adapters;

namespace Xamarin.Android.Tasks
{
Expand Down Expand Up @@ -463,6 +464,16 @@ bool CreateJavaSources (IEnumerable<JavaType> newJavaTypes, TypeDefinitionCache
bool hasExportReference = ResolvedAssemblies.Any (assembly => Path.GetFileName (assembly.ItemSpec) == "Mono.Android.Export.dll");
bool generateOnCreateOverrides = int.Parse (AndroidSdkPlatform) <= 10;

var reader_options = new CallableWrapperReaderOptions {
DefaultApplicationJavaClass = ApplicationJavaClass,
DefaultGenerateOnCreateOverrides = generateOnCreateOverrides,
DefaultMonoRuntimeInitialization = monoInit,
MethodClassifier = classifier,
};
var writer_options = new CallableWrapperWriterOptions {
CodeGenerationTarget = JavaPeerStyle.XAJavaInterop1
};

bool ok = true;
foreach (JavaType jt in newJavaTypes) {
TypeDefinition t = jt.Type; // JCW generator doesn't care about ABI-specific types or token ids
Expand All @@ -473,23 +484,21 @@ bool CreateJavaSources (IEnumerable<JavaType> newJavaTypes, TypeDefinitionCache

using (var writer = MemoryStreamPool.Shared.CreateStreamWriter ()) {
try {
var jti = new JavaCallableWrapperGenerator (t, Log.LogWarning, cache, classifier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't pass in Log.LogWarning(), I wondered if we lost the ability to log warnings. But then I looked at the java.interop diff to see all the warnings commented out.

Is this something being worked on for a future PR? Just curious.

Copy link
Contributor Author

@jpobst jpobst Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I know of. I assume these warnings were disabled for a reason?

But it would be pretty easy to add a logger property to CallableWrapperReaderOptions and/or CallableWrapperWriterOptions in the future if someone wanted to add more logging.

GenerateOnCreateOverrides = generateOnCreateOverrides,
ApplicationJavaClass = ApplicationJavaClass,
MonoRuntimeInitialization = monoInit,
};
var jcw_type = CecilImporter.CreateType (t, cache, reader_options);

jcw_type.Generate (writer, writer_options);

jti.Generate (writer);
if (useMarshalMethods) {
if (classifier.FoundDynamicallyRegisteredMethods (t)) {
Log.LogWarning ($"Type '{t.GetAssemblyQualifiedName (cache)}' will register some of its Java override methods dynamically. This may adversely affect runtime performance. See preceding warnings for names of dynamically registered methods.");
}
}

writer.Flush ();

var path = jti.GetDestinationPath (outputPath);
var path = jcw_type.GetDestinationPath (outputPath);
Files.CopyIfStreamChanged (writer.BaseStream, path);
if (jti.HasExport && !hasExportReference)
if (jcw_type.HasExport && !hasExportReference)
Diagnostic.Error (4210, Properties.Resources.XA4210);
} catch (XamarinAndroidException xae) {
ok = false;
Expand Down