diff options
Diffstat (limited to 'share/qbs/modules/java/utils.js')
-rw-r--r-- | share/qbs/modules/java/utils.js | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/share/qbs/modules/java/utils.js b/share/qbs/modules/java/utils.js index 8fb9661fa..a59b8d41d 100644 --- a/share/qbs/modules/java/utils.js +++ b/share/qbs/modules/java/utils.js @@ -79,7 +79,7 @@ function findJdkPath(hostOS, arch, environmentPaths, searchPaths) { return environmentPaths[i]; } - if (hostOS.contains("windows")) { + if (hostOS.includes("windows")) { var rootKey = jdkRootRegistryKey(useWow64Key(arch)); if (rootKey) { var current = Utilities.getNativeSetting(rootKey, "CurrentVersion"); // 1.8 etc. @@ -94,27 +94,55 @@ function findJdkPath(hostOS, arch, environmentPaths, searchPaths) { return undefined; } - if (hostOS.contains("macos")) { + if (hostOS.includes("macos")) { var p = new Process(); try { // We filter by architecture here so that we'll get a compatible JVM for JNI use. var args = []; + var canonicalArch; if (arch) { // Hardcoding apple/macosx/macho here is fine because we know we're on macOS - args.push("--arch", - Utilities.canonicalTargetArchitecture(arch, undefined, - "apple", "macosx", "macho")); + canonicalArch = Utilities.canonicalTargetArchitecture(arch, undefined, "apple", + "macosx", "macho"); + args.push("--arch", canonicalArch); } // --failfast doesn't print the default JVM if nothing matches the filter(s). var status = p.exec("/usr/libexec/java_home", args.concat(["--failfast"])); - return status === 0 ? p.readStdOut().trim() : undefined; + if (status === 0) + return p.readStdOut().trim(); + + // It has been obvserved that java_home fails for any architecture that is passed, + // so try without the filter and look up the JDK architecture manually. + if (!canonicalArch) + return undefined; + + if (p.exec("/usr/libexec/java_home", ["--failfast"]) !== 0) + return undefined; + var jdkPath = p.readStdOut().trim(); + var releaseFile = new TextFile(jdkPath + "/release", TextFile.ReadOnly); + var line; + while ((line = releaseFile.readLine())) { + if (!line.startsWith("OS_ARCH=")) + continue; + var firstQuote = line.indexOf('"'); + if (firstQuote === -1) + break; + var secondQuote = line.indexOf('"', firstQuote + 1); + if (secondQuote === -1) + break; + var archFromFile = line.substring(firstQuote + 1, secondQuote); + if (archFromFile !== canonicalArch) + break; + return jdkPath; + } + return undefined; } finally { p.close(); } } - if (hostOS.contains("unix")) { + if (hostOS.includes("unix")) { var requiredTools = ["javac", "java", "jar"]; for (i = 0; i < searchPaths.length; ++i) { function fullToolPath(tool) { @@ -246,7 +274,7 @@ function helperFullyQualifiedNames(type) { ]; if (type === "java") { return names.filter(function (name) { - return !name.contains("$"); + return !name.includes("$"); }); } else if (type === "class") { return names; |