Skip to content

Commit

Permalink
[build] Prefer JDK-17 (#1291)
Browse files Browse the repository at this point in the history
Context: dotnet/android@df68c20
Context: 7a32bb9
Context: https://bugs.openjdk.org/browse/JDK-8223291

dotnet/android requires JDK-17, as of dotnet/android@df68c208.

Update the dotnet/java-interop build to prefer JDK-17, for consistency.

Additionally, *replace* use of `javac -source X -target X` with
`javac --release X`, as this removes a build warning:

	EXEC : warning : [options] system modules path not set in conjunction with -source 11

Unfortunately, using a new JDK version invariably breaks the
`Xamarin.Android.Tools.Bytecode-Tests` -- despite `javac` targeting
the same JDK version! -- so update the tests accordingly.
(What is this new `Enum.$values()` method?  Why reorder
`JavaType$1` and `JavaType$ASC`?)

Finally, update the expected XML output in `tests/java-source-utils`.
JDK-8223291, which was a change in XML output between JDK-8 and JDK-9,
which we worked around in 7a32bb9, has been fixed.  The fix
apparently means that XML output now matches JDK-8 (yay?), but also
means XML output differs from JDK-11 (boo!).  Unfortunately, this
means that `tests/java-source-utils` tests will now only pass on
JDK 14+, i.e. JDK-17+…
  • Loading branch information
jonpryor authored Jan 11, 2025
1 parent b966c15 commit 4f06201
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 238 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">11</JavacSourceVersion>
<JavacTargetVersion Condition=" '$(JavacTargetVersion)' == '' ">11</JavacTargetVersion>
<_BootClassPath Condition=" '$(JreRtJarPath)' != '' ">-bootclasspath "$(JreRtJarPath)"</_BootClassPath>
<_JavacSourceOptions>-source $(JavacSourceVersion) -target $(JavacTargetVersion) $(_BootClassPath)</_JavacSourceOptions>
<_JavacSourceOptions>--release $(JavacTargetVersion) $(_BootClassPath)</_JavacSourceOptions>
</PropertyGroup>
<PropertyGroup>
<XamarinAndroidToolsFullPath>$([System.IO.Path]::GetFullPath ('$(XamarinAndroidToolsDirectory)'))</XamarinAndroidToolsFullPath>
Expand Down
2 changes: 1 addition & 1 deletion build-tools/scripts/Prepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PropertyGroup>
<_MaxJdk>$(MaxJdkVersion)</_MaxJdk>
<_MaxJdk Condition=" '$(_MaxJdk)' == '' ">$(JI_MAX_JDK)</_MaxJdk>
<JdksRoot Condition=" '$(JdksRoot)' == '' And '$(JAVA_HOME_11_X64)' != '' And Exists($(JAVA_HOME_11_X64)) ">$(JAVA_HOME_11_X64)</JdksRoot>
<JdksRoot Condition=" '$(JdksRoot)' == '' And '$(JAVA_HOME_17_X64)' != '' And Exists($(JAVA_HOME_17_X64)) ">$(JAVA_HOME_17_X64)</JdksRoot>
<JdksRoot Condition=" '$(JdksRoot)' == '' And '$(JAVA_HOME_11_X64)' != '' And Exists($(JAVA_HOME_11_X64)) ">$(JAVA_HOME_11_X64)</JdksRoot>
</PropertyGroup>
<JdkInfo
JdksRoot="$(JdksRoot)"
Expand Down
7 changes: 6 additions & 1 deletion tests/Xamarin.Android.Tools.Bytecode-Tests/JavaEnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void ClassFileDescription ()
new ExpectedTypeDeclaration {
MajorVersion = 0x37,
MinorVersion = 0,
ConstantPoolCount = 53,
ConstantPoolCount = 55,
AccessFlags = ClassAccessFlags.Final | ClassAccessFlags.Super | ClassAccessFlags.Enum,
FullName = "com/xamarin/JavaEnum",
Superclass = new TypeInfo ("java/lang/Enum", "Ljava/lang/Enum<Lcom/xamarin/JavaEnum;>;"),
Expand Down Expand Up @@ -71,6 +71,11 @@ public void ClassFileDescription ()
AccessFlags = MethodAccessFlags.Public,
ReturnDescriptor = "I",
},
new ExpectedMethodDeclaration {
Name = "$values",
AccessFlags = MethodAccessFlags.Private | MethodAccessFlags.Static | MethodAccessFlags.Synthetic,
ReturnDescriptor = "[Lcom/xamarin/JavaEnum;",
},
new ExpectedMethodDeclaration {
Name = "<clinit>",
AccessFlags = MethodAccessFlags.Static,
Expand Down
14 changes: 7 additions & 7 deletions tests/Xamarin.Android.Tools.Bytecode-Tests/JavaTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public void ClassFile_WithJavaType_class ()
new TypeInfo ("com/xamarin/IJavaInterface", "Lcom/xamarin/IJavaInterface<Ljava/lang/StringBuilder;Ljava/util/ArrayList<Ljava/lang/StringBuilder;>;Ljava/util/List<Ljava/lang/String;>;>;"),
},
InnerClasses = {
new ExpectedInnerClassInfo {
InnerClassName = "com/xamarin/JavaType$1",
OuterClassName = null,
InnerName = null,
AccessFlags = 0,
},
new ExpectedInnerClassInfo {
InnerClassName = "com/xamarin/JavaType$ASC",
OuterClassName = "com/xamarin/JavaType",
Expand All @@ -59,12 +65,6 @@ public void ClassFile_WithJavaType_class ()
InnerName = "MyStringList",
AccessFlags = 0,
},
new ExpectedInnerClassInfo {
InnerClassName = "com/xamarin/JavaType$1",
OuterClassName = null,
InnerName = null,
AccessFlags = 0,
},
new ExpectedInnerClassInfo {
InnerClassName = "com/xamarin/JavaType$RNC$RPNC",
OuterClassName = "com/xamarin/JavaType$RNC",
Expand Down Expand Up @@ -149,7 +149,7 @@ public void ClassFile_WithJavaType_class ()
Name = "STATIC_FINAL_STRING",
Descriptor = "Ljava/lang/String;",
AccessFlags = FieldAccessFlags.Public | FieldAccessFlags.Static | FieldAccessFlags.Final,
ConstantValue = "String(stringIndex=190 Utf8=\"Hello, \\\"embedded\0Nulls\" and \ud83d\udca9!\")",
ConstantValue = "String(stringIndex=101 Utf8=\"Hello, \\\"embedded\0Nulls\" and \ud83d\udca9!\")",
},
new ExpectedFieldDeclaration {
Name = "STATIC_FINAL_BOOL_FALSE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void ClassFile ()
new ExpectedTypeDeclaration {
MajorVersion = 0x37,
MinorVersion = 0,
ConstantPoolCount = 13,
ConstantPoolCount = 12,
AccessFlags = ClassAccessFlags.Module,
FullName = "module-info",
}.Assert (c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import org.junit.Test;

import jdk.nashorn.internal.AssertsEnabled;

import static org.junit.Assert.*;

public class JavaSourceUtilsOptionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ private static void testWritePackages(final JniPackagesInfo packagesInfo, final

generator.writePackages(packagesInfo);
generator.close();
// try (FileOutputStream o = new FileOutputStream(assertDescription + "-jonp.xml")) {
// bytes.writeTo(o);
// }

final File actual = new File(assertDescription + "-jonp.xml");
try (FileOutputStream o = new FileOutputStream(actual)) {
bytes.writeTo(o);
}
assertEquals(assertDescription, expected, bytes.toString());
actual.delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
<class jni-signature="Lexample/UnresolvedTypes;" name="UnresolvedTypes">
<method jni-return="L.*UnresolvedReturnType;" jni-signature="([L.*example.name.UnresolvedParameterType;)L.*UnresolvedReturnType;" name="method" return=".*UnresolvedReturnType">
<parameter jni-type="[L.*example.name.UnresolvedParameterType;" name="parameter" type=".*example.name.UnresolvedParameterType..."/>
<javadoc>
<![CDATA[Method using unresolvable types. As such, we make do.
<javadoc><![CDATA[Method using unresolvable types. As such, we make do.
JNI Sig: method.([L.*example.name.UnresolvedParameterType;)L.*UnresolvedReturnType;]]>
</javadoc>
JNI Sig: method.([L.*example.name.UnresolvedParameterType;)L.*UnresolvedReturnType;]]></javadoc>
</method>
</class>
</package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,39 @@
<api api-source="java-source-utils">
<package jni-name="" name="">
<class jni-signature="LA;" name="A">
<javadoc>
<![CDATA[jni-sig=LA;]]>
</javadoc>
<javadoc><![CDATA[jni-sig=LA;]]></javadoc>
<constructor jni-signature="(ILjava/lang/String;)V">
<parameter jni-type="I" name="one" type="int"/>
<parameter jni-type="Ljava/lang/String;" name="two" type="java.lang.String"/>
<javadoc>
<![CDATA[jni-sig=<init>.(ILjava/lang/String;)V]]>
</javadoc>
<javadoc><![CDATA[jni-sig=<init>.(ILjava/lang/String;)V]]></javadoc>
</constructor>
<field jni-signature="I" name="field">
<javadoc>
<![CDATA[jni-sig=field.I]]>
</javadoc>
<javadoc><![CDATA[jni-sig=field.I]]></javadoc>
</field>
<method jni-return="V" jni-signature="(Ljava/lang/Object;J)V" name="m" return="void">
<parameter jni-type="Ljava/lang/Object;" name="value" type="T"/>
<parameter jni-type="J" name="x" type="long"/>
<javadoc>
<![CDATA[jni-sig=m.(Ljava/lang/Object;J)V]]>
</javadoc>
<javadoc><![CDATA[jni-sig=m.(Ljava/lang/Object;J)V]]></javadoc>
</method>
</class>
<interface jni-signature="LI;" name="I">
<javadoc>
<![CDATA[jni-sig=LI;]]>
</javadoc>
<javadoc><![CDATA[jni-sig=LI;]]></javadoc>
<method jni-return="Ljava/lang/Object;" jni-signature="(Ljava/util/List;)Ljava/lang/Object;" name="m" return="T">
<parameter jni-type="Ljava/util/List;" name="x" type="java.util.List&lt;T&gt;"/>
<javadoc>
<![CDATA[jni-sig=m.(Ljava/util/List;)Ljava/lang/Object;]]>
</javadoc>
<javadoc><![CDATA[jni-sig=m.(Ljava/util/List;)Ljava/lang/Object;]]></javadoc>
</method>
</interface>
</package>
<package jni-name="before/example" name="before.example"/>
<package jni-name="example" name="example">
<interface jni-signature="Lexample/Exampleable;" name="Exampleable">
<javadoc>
<![CDATA[jni-sig=Lexample/Exampleable;]]>
</javadoc>
<javadoc><![CDATA[jni-sig=Lexample/Exampleable;]]></javadoc>
<method jni-return="V" jni-signature="(Ljava/lang/String;)V" name="example" return="void">
<parameter jni-type="Ljava/lang/String;" name="e" type="java.lang.String"/>
<javadoc>
<![CDATA[jni-sig=example.(Ljava/lang/String;)V]]>
</javadoc>
<javadoc><![CDATA[jni-sig=example.(Ljava/lang/String;)V]]></javadoc>
</method>
<method jni-return="V" jni-signature="()V" name="noParameters" return="void">
<javadoc>
<![CDATA[jni-sig=noParameters.()V]]>
</javadoc>
<javadoc><![CDATA[jni-sig=noParameters.()V]]></javadoc>
</method>
</interface>
</package>
Expand Down
Loading

0 comments on commit 4f06201

Please sign in to comment.