Skip to content

Commit

Permalink
[GR-47930] Improve SDK lookup in intellijinit.
Browse files Browse the repository at this point in the history
PullRequest: mx/1659
  • Loading branch information
dougxc committed Sep 16, 2023
2 parents f0c8c7c + 78780aa commit ec9740f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
- name: Style dependencies
run: |
cat common.json |
jq -r '.deps.common.packages | to_entries[] | select(.key | startswith("pip:")) | (.key | split(":")[1]) + .value' |
jq -r '.pip | to_entries[] | .key + .value' |
xargs pip install
- run: pylint --version
- name: Download and set up Eclipse dependency
run: |
ECLIPSE_ORG_VERSION=$(cat common.json | jq -r '.downloads.eclipse.eclipse_org.version')
ECLIPSE_ORG_TIMESTAMP=$(cat common.json | jq -r '.downloads.eclipse.eclipse_org.timestamp')
ECLIPSE_ORG_VERSION=$(cat common.json | jq -r '.eclipse.short_version')
ECLIPSE_ORG_TIMESTAMP=$(cat common.json | jq -r '.eclipse.timestamp')
wget --no-verbose https://archive.eclipse.org/eclipse/downloads/drops4/R-${ECLIPSE_ORG_VERSION}-${ECLIPSE_ORG_TIMESTAMP}/eclipse-SDK-${ECLIPSE_ORG_VERSION}-linux-gtk-x86_64.tar.gz -O $ECLIPSE_TAR
tar -C ${{ github.workspace }}/.. -xf $ECLIPSE_TAR
- name: mx gate
Expand Down
15 changes: 13 additions & 2 deletions ci/common.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ local common_json = import "../common.json";
# JDK definitions
# ***************
local variants(name) = [name, name + "Debug", name + "-llvm"],
# gets the JDK major version from a labsjdk version string (e.g., "ce-21+35-jvmci-23.1-b15" -> 21)
local parse_labsjdk_version(version) =
assert std.startsWith(version, "ce-") || std.startsWith(version, "ee-") : "Unsupported labsjdk version: " + version;
local number_prefix(str) =
if std.length(str) == 0 || std.length(std.findSubstr(str[0], "0123456789")) == 0 then
""
else
str[0] + number_prefix(str[1:])
;
std.parseInt(number_prefix(version[3:]))
,
local jdks_data = {
oraclejdk11: common_json.jdks["oraclejdk11"] + { jdk_version:: 11 },
} + {
Expand All @@ -24,8 +35,8 @@ local common_json = import "../common.json";
[name]: common_json.jdks[name] + { jdk_version:: 21 }
for name in ["oraclejdk21"] + variants("labsjdk-ce-21") + variants("labsjdk-ee-21")
} + {
[name]: common_json.jdks[name] + { jdk_version:: 22 }
for name in variants("labsjdk-ce-22") + variants("labsjdk-ee-22")
[name]: common_json.jdks[name] + { jdk_version:: parse_labsjdk_version(self.version)}
for name in variants("labsjdk-ce-latest") + variants("labsjdk-ee-latest")
},
assert std.assertEqual(std.objectFields(common_json.jdks), std.objectFields(jdks_data)),

Expand Down
14 changes: 7 additions & 7 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "6.46.1",
"mx_version": "6.49.1",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down Expand Up @@ -42,12 +42,12 @@
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15-sulong", "platformspecific": true },

"labsjdk-ce-22": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01", "platformspecific": true },
"labsjdk-ce-22Debug": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-debug", "platformspecific": true },
"labsjdk-ce-22-llvm": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-sulong", "platformspecific": true },
"labsjdk-ee-22": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01", "platformspecific": true },
"labsjdk-ee-22Debug": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01-debug", "platformspecific": true },
"labsjdk-ee-22-llvm": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01-sulong", "platformspecific": true }
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01", "platformspecific": true },
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-debug", "platformspecific": true },
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-sulong", "platformspecific": true },
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01", "platformspecific": true },
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01-debug", "platformspecific": true },
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01-sulong", "platformspecific": true }
},

"eclipse": {
Expand Down
2 changes: 1 addition & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18789,7 +18789,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.50.0") # GR-48667 Scan SuiteClasses for @AddExports
version = VersionSpec("6.50.1") # GR-47930 - Improve SDK lookup in intellijinit.

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down
18 changes: 15 additions & 3 deletions mx_ide_intellij.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def intellijinit(args, refreshOnly=False, doFsckProjects=True, mx_python_modules

def intellij_read_sdks():
sdks = dict()
if mx.is_linux() or mx.is_openbsd() or mx.is_sunos() or mx.is_windows():
# https://www.jetbrains.com/help/idea/2023.2/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html
if mx.is_linux() or mx.is_openbsd() or mx.is_sunos():
xmlSdks = glob.glob(os.path.expanduser("~/.IdeaIC*/config/options/jdk.table.xml")) + \
glob.glob(os.path.expanduser("~/.IntelliJIdea*/config/options/jdk.table.xml")) + \
glob.glob(os.path.expanduser("~/.config/JetBrains/IdeaIC*/options/jdk.table.xml")) + \
Expand All @@ -117,6 +118,12 @@ def intellij_read_sdks():
glob.glob(os.path.expanduser("~/Library/Application Support/JetBrains/IntelliJIdea*/options/jdk.table.xml")) + \
glob.glob(os.path.expanduser("~/Library/Preferences/IdeaIC*/options/jdk.table.xml")) + \
glob.glob(os.path.expanduser("~/Library/Preferences/IntelliJIdea*/options/jdk.table.xml"))
elif mx.is_windows():
xmlSdks = \
glob.glob(os.path.expandvars("%APPDATA%/JetBrains/IdeaIC*/options/jdk.table.xml")) + \
glob.glob(os.path.expandvars("%APPDATA%/JetBrains/IntelliJIdea*/options/jdk.table.xml")) + \
glob.glob(os.path.expandvars("%LOCALAPPDATA%/JetBrains/IdeaIC*/options/jdk.table.xml")) + \
glob.glob(os.path.expandvars("%LOCALAPPDATA%/JetBrains/IntelliJIdea*/options/jdk.table.xml"))
else:
mx.warn(f"Location of IntelliJ SDK definitions on {mx.get_os()} is unknown")
return sdks
Expand All @@ -132,7 +139,12 @@ def verSort(path):
xmlSdks.sort(key=verSort, reverse=True)

sdk_version_regexes = {
intellij_java_sdk_type: re.compile(r'^java\s+version\s+"([^"]+)"$|^(Oracle OpenJDK )?version\s+(.+)$|^([\d._]+)$'),
# Examples:
# java version "21"
# GraalVM version 21 (vendor name may change)
intellij_java_sdk_type: re.compile(r'^java\s+version\s+"([^"]+)"$|'
r'^(?:.+ )?version\s+(.+)$|'
r'^([\d._]+)$'),
intellij_python_sdk_type: re.compile(r'^Python\s+(.+)$'),

# Examples:
Expand Down Expand Up @@ -170,7 +182,7 @@ def verSort(path):
sdk_version = sdk.find("version").get("value")
match = version_re.match(sdk_version)
if match:
version = match.group(1)
version = next(filter(None, match.groups()), None)
lang = sdk_languages[kind]
if kind == intellij_python_sdk_type:
import mx_enter
Expand Down

0 comments on commit ec9740f

Please sign in to comment.