mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Bazel/Kotlin: fix version comparison logic, add default version printing
This commit is contained in:
@@ -145,7 +145,7 @@ _resources = [
|
||||
name = "%s-standalone" % _common_extractor_name_prefix,
|
||||
actual = "%s-standalone-%s" % (
|
||||
_common_extractor_name_prefix,
|
||||
kotlin_extractor_defaults.version,
|
||||
kotlin_extractor_defaults.extractor_version,
|
||||
),
|
||||
visibility = ["//visibility:public"],
|
||||
),
|
||||
@@ -153,7 +153,7 @@ _resources = [
|
||||
name = "%s-embeddable" % _common_extractor_name_prefix,
|
||||
actual = "%s-embeddable-%s" % (
|
||||
_common_extractor_name_prefix,
|
||||
kotlin_extractor_defaults.version,
|
||||
kotlin_extractor_defaults.extractor_version,
|
||||
),
|
||||
visibility = ["//visibility:public"],
|
||||
),
|
||||
@@ -162,7 +162,7 @@ _resources = [
|
||||
actual = "%s-%s-%s" % (
|
||||
_common_extractor_name_prefix,
|
||||
kotlin_extractor_defaults.variant,
|
||||
kotlin_extractor_defaults.version,
|
||||
kotlin_extractor_defaults.extractor_version,
|
||||
),
|
||||
visibility = ["//visibility:public"],
|
||||
),
|
||||
@@ -180,4 +180,13 @@ _resources = [
|
||||
) for variant in ("standalone", "embeddable") for version in VERSIONS],
|
||||
visibility = ["//visibility:public"],
|
||||
),
|
||||
genrule(
|
||||
name = "default-version-printer",
|
||||
outs = ["print-default-version.sh"],
|
||||
cmd = "echo echo %s > $@" % kotlin_extractor_defaults.version,
|
||||
),
|
||||
sh_binary(
|
||||
name = "print-default-version",
|
||||
srcs = [":default-version-printer"],
|
||||
),
|
||||
) if not _for_embeddable else None
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
load("//java/kotlin-extractor:versions.bzl", "DEFAULT_FALLBACK_VERSION", "VERSIONS", "version_less")
|
||||
load("//java/kotlin-extractor:versions.bzl", "DEFAULT_VERSION", "VERSIONS", "version_less")
|
||||
load("//misc/bazel:lfs.bzl", "lfs_smudge")
|
||||
|
||||
_kotlin_dep_build = """
|
||||
@@ -71,33 +71,38 @@ _embeddable_source = repository_rule(implementation = _embeddable_source_impl)
|
||||
def _get_default_version(repository_ctx):
|
||||
default_version = repository_ctx.getenv("CODEQL_KOTLIN_SINGLE_VERSION")
|
||||
if default_version:
|
||||
if default_version not in VERSIONS:
|
||||
fail("overriding CODEQL_KOTLIN_SINGLE_VERSION=%s not known, must be one of:\n %s" %
|
||||
(default_version, " ".join(VERSIONS)))
|
||||
return default_version
|
||||
kotlinc = repository_ctx.which("kotlinc")
|
||||
if not kotlinc:
|
||||
return DEFAULT_FALLBACK_VERSION
|
||||
return DEFAULT_VERSION
|
||||
res = repository_ctx.execute([kotlinc, "-version"])
|
||||
if not res:
|
||||
fail("kotlinc -version failed: %s" % res.stderr)
|
||||
out = res.stderr.split(" ")
|
||||
if len(out) < 3:
|
||||
fail("malformed kotlinc -version output: %s" % res.stdout)
|
||||
host_version = out[2]
|
||||
for version in reversed(VERSIONS):
|
||||
if version_less(version, host_version) or version == host_version:
|
||||
return version
|
||||
fail("no relevant version found for host version %s among:\n %s" % (host_version, " ".join(VERSIONS)))
|
||||
return out[2]
|
||||
|
||||
def _get_available_version(version):
|
||||
for available_version in reversed(VERSIONS):
|
||||
if not version_less(version, available_version):
|
||||
return available_version
|
||||
fail("no available version found for version %s among:\n %s" % (version, " ".join(VERSIONS)))
|
||||
|
||||
def _defaults_impl(repository_ctx):
|
||||
default_version = _get_default_version(repository_ctx)
|
||||
default_variant = "standalone"
|
||||
if repository_ctx.getenv("CODEQL_KOTLIN_SINGLE_VERSION_EMBEDDABLE") in ("true", "1"):
|
||||
default_variant = "embeddable"
|
||||
available_version = _get_available_version(default_version)
|
||||
info = struct(
|
||||
version = default_version,
|
||||
variant = default_variant,
|
||||
extractor_version = available_version,
|
||||
)
|
||||
repository_ctx.file(
|
||||
"defaults.bzl",
|
||||
"kotlin_extractor_defaults = struct(version = '%s', variant = '%s')\n" % (default_version, default_variant),
|
||||
"kotlin_extractor_defaults = %s\n" % repr(info),
|
||||
)
|
||||
repository_ctx.file("BUILD.bazel")
|
||||
|
||||
|
||||
@@ -15,18 +15,18 @@ VERSIONS = [
|
||||
"2.0.255-SNAPSHOT",
|
||||
]
|
||||
|
||||
DEFAULT_FALLBACK_VERSION = "1.9.0-Beta"
|
||||
DEFAULT_VERSION = "1.9.0"
|
||||
|
||||
def _version_to_tuple(v):
|
||||
v, _, tail = v.partition("-")
|
||||
v = tuple([int(x) for x in v.split(".")])
|
||||
return v + (tail,)
|
||||
# we ignore the tag when comparing versions, for example 1.9.0-Beta <= 1.9.0
|
||||
v, _, ignored_tag = v.partition("-")
|
||||
return tuple([int(x) for x in v.split(".")])
|
||||
|
||||
def version_less(lhs, rhs):
|
||||
return _version_to_tuple(lhs) < _version_to_tuple(rhs)
|
||||
|
||||
def get_language_version(version):
|
||||
major, minor, _, _ = _version_to_tuple(version)
|
||||
major, minor, _ = _version_to_tuple(version)
|
||||
return "%s.%s" % (major, minor)
|
||||
|
||||
def _basename(path):
|
||||
|
||||
Reference in New Issue
Block a user