diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index d3b1d7941..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) + - script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) displayName: make prepare - - script: make all CONFIGURATION=$(Build.Configuration) + - 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/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 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)