Skip to content

Commit

Permalink
introduce select_since for backwards incompatible dependencies in c…
Browse files Browse the repository at this point in the history
…lion
  • Loading branch information
LeFrosch committed Nov 26, 2024
1 parent 4886caf commit 45b03a5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
15 changes: 11 additions & 4 deletions clwb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ load(
"//testing:test_defs.bzl",
"intellij_unit_test_suite",
)
load(":build_defs.bzl", "select_since")
load(":test_defs.bzl", "clwb_integration_test")

licenses(["notice"])
Expand All @@ -34,14 +35,20 @@ intellij_plugin_library(
name = "plugin_library",
optional_plugin_xmls = [
"optional_clwb_oclang",
"//clwb/src/com/google/idea/blaze/clwb/radler:plugin_xml",
],
] + select_since(
"2024.3",
["//clwb/src/com/google/idea/blaze/clwb/radler:plugin_xml"],
default = [],
),
plugin_xmls = ["src/META-INF/clwb.xml"],
visibility = PLUGIN_PACKAGES_VISIBILITY,
deps = [
":clwb_lib",
"//clwb/src/com/google/idea/blaze/clwb/radler:lib",
],
] + select_since(
"2024.3",
["//clwb/src/com/google/idea/blaze/clwb/radler:lib"],
default = [],
),
)

optional_plugin_xml(
Expand Down
48 changes: 48 additions & 0 deletions clwb/build_defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load("//intellij_platform_sdk:build_defs.bzl", "INDIRECT_IJ_PRODUCTS")

SUPPORTED_VERSIONS = {
"clion-oss-oldest-stable": INDIRECT_IJ_PRODUCTS["clion-oss-oldest-stable"],
"clion-oss-latest-stable": INDIRECT_IJ_PRODUCTS["clion-oss-latest-stable"],
"clion-oss-under-dev": INDIRECT_IJ_PRODUCTS["clion-oss-under-dev"],
}

def _version_to_number(version):
"""
Turns a clion version `clion-20xx.x` to an integer. Used for comparing clion versions.
"""

# take the last six characters of the version `20xx.x `
version = version[-6:]

# replace the dot with a 0
version = version.replace(".", "0")

return int(version)

def select_since(since, value, default = None):
"""
Returns a select that based on targeted clion version. The select returns the `value` if the target version is
bigger or equal to the specified `version`. If a default value is defined this value is returned otherwise.
Might be good replacement for sdkcompat if only future versions are targeted.
Args:
since: the minimum supported version
value: the value to select if the current target version is bigger or equal than `since
default: a optional default value
"""

select_params = dict()

for name, version in SUPPORTED_VERSIONS.items():
if _version_to_number(version) >= _version_to_number(since):
select_params["//intellij_platform_sdk:" + version] = value
select_params["//intellij_platform_sdk:" + name] = value

if default != None:
select_params["//conditions:default"] = default

return select(
select_params,
no_match_error = "unsupported clion version, min version: clion-" + since,
)

0 comments on commit 45b03a5

Please sign in to comment.