|
1 | | -load("//java/kotlin-extractor:versions.bzl", "VERSIONS", "version_less") |
| 1 | +load("//java/kotlin-extractor:versions.bzl", "VERSIONS") |
2 | 2 | load("//misc/bazel:lfs.bzl", "lfs_smudge") |
3 | 3 |
|
4 | 4 | _kotlin_dep_build = """ |
@@ -69,42 +69,34 @@ def _embeddable_source_impl(repository_ctx): |
69 | 69 |
|
70 | 70 | _embeddable_source = repository_rule(implementation = _embeddable_source_impl) |
71 | 71 |
|
72 | | -def _get_default_version(repository_ctx): |
| 72 | +def _get_version(repository_ctx, available = []): |
73 | 73 | default_version = repository_ctx.getenv("CODEQL_KOTLIN_SINGLE_VERSION") |
74 | 74 | if default_version: |
75 | 75 | return default_version |
76 | | - kotlin_plugin_versions = repository_ctx.path(Label("//java/kotlin-extractor:current_kotlin_version.py")) |
77 | | - python = repository_ctx.which("python3") or repository_ctx.which("python") |
78 | | - env = {} |
79 | 76 | repository_ctx.watch(Label("//java/kotlin-extractor:dev/.kotlinc_version")) |
80 | | - if not repository_ctx.which("kotlinc"): |
81 | | - # take default from the kotlinc wrapper |
82 | | - path = repository_ctx.getenv("PATH") |
83 | | - path_to_add = repository_ctx.path(Label("//java/kotlin-extractor:dev")) |
84 | | - if not path: |
85 | | - path = str(path_to_add) |
86 | | - elif repository_ctx.os.name == "windows": |
87 | | - path = "%s;%s" % (path, path_to_add) |
88 | | - else: |
89 | | - path = "%s:%s" % (path, path_to_add) |
90 | | - env["PATH"] = path |
91 | | - res = repository_ctx.execute([python, kotlin_plugin_versions], environment = env) |
| 77 | + version_picker = repository_ctx.path(Label("//java/kotlin-extractor:pick-kotlin-version.py")) |
| 78 | + python = repository_ctx.which("python3") or repository_ctx.which("python") |
| 79 | + |
| 80 | + # use the kotlinc wrapper as fallback |
| 81 | + path = repository_ctx.getenv("PATH") |
| 82 | + path_to_add = repository_ctx.path(Label("//java/kotlin-extractor:dev")) |
| 83 | + if not path: |
| 84 | + path = str(path_to_add) |
| 85 | + elif repository_ctx.os.name == "windows": |
| 86 | + path = "%s;%s" % (path, path_to_add) |
| 87 | + else: |
| 88 | + path = "%s:%s" % (path, path_to_add) |
| 89 | + res = repository_ctx.execute([python, version_picker] + available, environment = {"PATH": path}) |
92 | 90 | if res.return_code != 0: |
93 | 91 | fail(res.stderr) |
94 | 92 | return res.stdout.strip() |
95 | 93 |
|
96 | | -def _get_available_version(version): |
97 | | - for available_version in reversed(VERSIONS): |
98 | | - if not version_less(version, available_version): |
99 | | - return available_version |
100 | | - fail("no available version found for version %s among:\n %s" % (version, " ".join(VERSIONS))) |
101 | | - |
102 | 94 | def _defaults_impl(repository_ctx): |
103 | | - default_version = _get_default_version(repository_ctx) |
| 95 | + default_version = _get_version(repository_ctx) |
104 | 96 | default_variant = "standalone" |
105 | 97 | if repository_ctx.getenv("CODEQL_KOTLIN_SINGLE_VERSION_EMBEDDABLE") in ("true", "1"): |
106 | 98 | default_variant = "embeddable" |
107 | | - available_version = _get_available_version(default_version) |
| 99 | + available_version = _get_version(repository_ctx, VERSIONS) |
108 | 100 | info = struct( |
109 | 101 | version = default_version, |
110 | 102 | variant = default_variant, |
|
0 commit comments