aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2023-06-02 17:23:37 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2023-06-04 17:16:50 +0000
commit8d3df7e35c48f5e0696e0efc527e43acbaedc92c (patch)
treebfa2fc74ff5d1cb488d0634669ded1129be08d17 /share/qbs/modules
parentcd7b9f0546a985acf3e199c689aced4dbf43acfd (diff)
Java: Work around some macOS peculiarities
Namely, the java_home tool on my test machine - ignores the --version switch unless --failfast is given - fails for any architecture filter Change-Id: Ibac3189da3f795860b79290bdc8c863ef6861e61 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'share/qbs/modules')
-rw-r--r--share/qbs/modules/java/utils.js36
1 files changed, 32 insertions, 4 deletions
diff --git a/share/qbs/modules/java/utils.js b/share/qbs/modules/java/utils.js
index 9ee5932dc..a59b8d41d 100644
--- a/share/qbs/modules/java/utils.js
+++ b/share/qbs/modules/java/utils.js
@@ -99,16 +99,44 @@ function findJdkPath(hostOS, arch, environmentPaths, searchPaths) {
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();
}