From 201f78e1f022cce423283508942851c98444872c Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 19 Apr 2021 13:29:58 -0400 Subject: [PATCH 1/3] Bump to xamarin/xamarin-android-tools/main@d92fc3e3 Context: https://developercommunity.visualstudio.com/t/illegal-character-exception-in-xamarinandroid-afte/1363149 Changes: https://github.com/xamarin/xamarin-android-tools/compare/554d45a166a02da0ca1d0d9ca895eaa650fb648a...d92fc3e3a27e8240551baa813b15d6bf006a5620 * xamarin/xamarin-android-tools@d92fc3e: [Xamarin.Android.Tools.AndroidSdk] Probe for AdoptOpenJDK Locations (#115) * xamarin/xamarin-android-tools@dca30d9: [Xamarin.Android.Tools.AndroidSdk] Probe for Zulu JDK (#114) * xamarin/xamarin-android-tools@237642c: [Xamarin.Android.Tools.AndroidSdk] Probe for Microsoft OpenJDK dirs (#113) * xamarin/xamarin-android-tools@e618e00: [Xamarin.Android.Tools.AndroidSdk] Fix quotes in %PATH% or %PATHEXT% (#112) --- external/xamarin-android-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/xamarin-android-tools b/external/xamarin-android-tools index 554d45a16..d92fc3e3a 160000 --- a/external/xamarin-android-tools +++ b/external/xamarin-android-tools @@ -1 +1 @@ -Subproject commit 554d45a166a02da0ca1d0d9ca895eaa650fb648a +Subproject commit d92fc3e3a27e8240551baa813b15d6bf006a5620 From 80f2c9c532de80ae43bb65a356c1838e4fd9c7d6 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 19 Apr 2021 14:51:46 -0400 Subject: [PATCH 2/3] Avoid JDK 14. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=4666262&view=logs&j=54b9b405-417c-5884-5043-18b5f5d9acb9&t=ac76063e-e016-5aec-2585-53fde878edd6 The build is breaking: _BuildJava: "/Users/runner/work/1/s/build-tools/gradle/gradlew" -d --stacktrace --no-daemon -PjavaSourceVer=1.8 -PjavaTargetVer=1.8 jar … [ERROR] [system.err] java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 [ERROR] [system.err] at org.codehaus.groovy.vmplugin.VMPluginFactory.(VMPluginFactory.java:43) Java.Interop/main builds using adoptopenjdk-8.jdk, while this build is failing with adoptopenjdk-14, as inferred from: gcc -g -shared -m64 -fPIC -o bin/TestRelease/libNativeTiming.dylib tests/NativeTiming/timing.c -I/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/include/darwin Build with `make prepare all JI_MAX_JDK=11`, so that we avoid AdoptOpenJDK 14. --- build-tools/automation/azure-pipelines.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index d3b1d7941..e9ca86dd3 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -108,10 +108,10 @@ jobs: - template: templates\install-dependencies.yaml - - script: make prepare CONFIGURATION=$(Build.Configuration) + - script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=11 displayName: make prepare - - script: make all CONFIGURATION=$(Build.Configuration) + - script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=11 displayName: make all - script: | From 2eb540c154b935b20b8c4fd543b8c147f9f24f9b Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 19 Apr 2021 15:30:35 -0400 Subject: [PATCH 3/3] Require JDK 8 on CI? XML output changed between JDK 8 and JDK 11, breaking some unit tests. Constrain CI to using JDK 8, so that tests pass. Additionally, *for consistency*, update `TestJVM` to look for `JdkInfo.props`. If found, use the `$(JdkJvmPath)` value at `/Project/Chooose/When/PropertyGroup/JdkJvmPath` instead of using `JdkInfo.GetKnownSystemJdkInfos()`, so that the JVM that we built against is also used for unit test execution. --- build-tools/automation/azure-pipelines.yaml | 9 +++-- .../automation/templates/core-build.yaml | 2 +- build-tools/scripts/Prepare.targets | 6 ++- tests/TestJVM/TestJVM.cs | 40 +++++++++++++++++-- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index e9ca86dd3..25b80de03 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -18,6 +18,7 @@ pr: variables: RunningOnCI: true Build.Configuration: Release + MaxJdkVersion: 8 DotNetCoreVersion: 5.0.103 HostedMacImage: macOS-10.15 HostedWinVS2019: Hosted Windows 2019 with VS2019 @@ -108,15 +109,15 @@ jobs: - template: templates\install-dependencies.yaml - - script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=11 + - script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) displayName: make prepare - - script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=11 + - script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) displayName: make all - script: | r=0 - make run-all-tests CONFIGURATION=$(Build.Configuration) || r=$? + make run-all-tests CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) || r=$? jar cf xatb.jar -C tests/Xamarin.Android.Tools.Bytecode-Tests/obj/*/classes . zip -r bin.zip bin exit $r @@ -158,7 +159,7 @@ jobs: - template: templates\install-dependencies.yaml - - script: make prepare-core CONFIGURATION=$(Build.Configuration) + - script: make prepare-core CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) displayName: make prepare-core - template: templates\core-build.yaml diff --git a/build-tools/automation/templates/core-build.yaml b/build-tools/automation/templates/core-build.yaml index b631aed7c..7910222a5 100644 --- a/build-tools/automation/templates/core-build.yaml +++ b/build-tools/automation/templates/core-build.yaml @@ -6,7 +6,7 @@ steps: displayName: Prepare Solution inputs: projects: Java.Interop.sln - arguments: '-c $(Build.Configuration) -target:Prepare' + arguments: '-c $(Build.Configuration) -target:Prepare -p:MaxJdkVersion=$(MaxJdkVersion)' - task: DotNetCoreCLI@2 displayName: Build Solution diff --git a/build-tools/scripts/Prepare.targets b/build-tools/scripts/Prepare.targets index 771ac189e..71f7e70d3 100644 --- a/build-tools/scripts/Prepare.targets +++ b/build-tools/scripts/Prepare.targets @@ -7,10 +7,14 @@ + + <_MaxJdk>$(MaxJdkVersion) + <_MaxJdk Condition=" '$(_MaxJdk)' == '' ">$(JI_MAX_JDK) + diff --git a/tests/TestJVM/TestJVM.cs b/tests/TestJVM/TestJVM.cs index 8c0ff44cd..ba039b68b 100644 --- a/tests/TestJVM/TestJVM.cs +++ b/tests/TestJVM/TestJVM.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Threading; using System.Text; +using System.Xml.Linq; using Xamarin.Android.Tools; @@ -47,14 +48,47 @@ static TextWriter GetLogOutput (string envVar, string prefix, Assembly caller) static string GetJvmLibraryPath () { - var env = Environment.GetEnvironmentVariable ("JI_JVM_PATH"); - if (!string.IsNullOrEmpty (env)) - return env; + var jdkDir = ReadJavaSdkDirectoryFromJdkInfoProps (); + if (jdkDir != null) { + return jdkDir; + } var jdk = JdkInfo.GetKnownSystemJdkInfos () .FirstOrDefault (); return jdk?.JdkJvmPath; } + static string ReadJavaSdkDirectoryFromJdkInfoProps () + { + var location = typeof (TestJVM).Assembly.Location; + var binDir = Path.GetDirectoryName (Path.GetDirectoryName (location)); + var testDir = Path.GetFileName (Path.GetDirectoryName (location)); + if (!testDir.StartsWith ("Test", StringComparison.OrdinalIgnoreCase)) { + return null; + } + var buildName = testDir.Replace ("Test", "Build"); + if (buildName.Contains ('-')) { + buildName = buildName.Substring (0, buildName.IndexOf ('-')); + } + var jdkPropFile = Path.Combine (binDir, buildName, "JdkInfo.props"); + if (!File.Exists (jdkPropFile)) { + return null; + } + + var msbuild = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003"); + + var jdkProps = XDocument.Load (jdkPropFile); + var jdkJvmPath = jdkProps.Elements () + .Elements (msbuild + "Choose") + .Elements (msbuild + "When") + .Elements (msbuild + "PropertyGroup") + .Elements (msbuild + "JdkJvmPath") + .FirstOrDefault (); + if (jdkJvmPath == null) { + return null; + } + return jdkJvmPath.Value; + } + Dictionary typeMappings; public TestJVM (string[] jars = null, Dictionary typeMappings = null)