Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin: build extractor with bazel #16117

Merged
merged 111 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 98 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
0da4130
Bazel: add LFS rules
redsun82 Apr 3, 2024
341816c
Kotlin: add dependencies as lazy LFS files
redsun82 Apr 3, 2024
c242466
Kotlin: first support for Kotlin extractor build
redsun82 Apr 3, 2024
47ff1c1
Kotlin: working standalone extractor built with bazel
redsun82 Apr 4, 2024
5313288
LFS: do non-matching fetchinclude rather than explicit fetchexclude
redsun82 Apr 4, 2024
55ff710
Kotlin: support embeddable build in bazel
redsun82 Apr 4, 2024
5d6baea
Kotlin: add aliases for default versions
redsun82 Apr 4, 2024
3a0a219
Kotlin: remove obsolete 1.4.32 version
redsun82 Apr 4, 2024
cbdb1eb
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 4, 2024
44f3c02
Kotlin: revert accidental modification of `kotlin_plugin_versions.py`
redsun82 Apr 4, 2024
7aefd22
Kotlin: tweak `BUILD.bazel` file, add documentation
redsun82 Apr 4, 2024
38a7bc0
Bazel: optimize LFS to use symlinks when the file is not an LFS pointer
redsun82 Apr 8, 2024
fd77f1a
Bazel: fix lfs to do checkout rather than smudging
redsun82 Apr 8, 2024
e963b84
Kotlin: fix error in building extractor from internal repo
redsun82 Apr 8, 2024
a970c2d
Kotlin: move empty zip from git to internal bazel repo rule
redsun82 Apr 8, 2024
60febcd
Revert "Bazel: fix lfs to do checkout rather than smudging"
redsun82 Apr 8, 2024
b71ffc6
Bazel: properly fix lfs smudge script
redsun82 Apr 8, 2024
4a4bd16
Java/Kotlin: prepare for internal bazel packaging
redsun82 Apr 9, 2024
11729aa
Kotlin: add licensing links about kotlin dependencies
redsun82 Apr 9, 2024
4b205ff
Apply suggestions from code review
redsun82 Apr 9, 2024
9c73a9a
Bazel: move shared `bazelrc` settings to a `exported.bazelrc` file
redsun82 Apr 9, 2024
662fd5c
Add explanatory comment to `.lfsconfig`
redsun82 Apr 9, 2024
e7c680e
Kotlin: reuse generated dbscheme in embeddable, and tweak comments
redsun82 Apr 9, 2024
3bdab70
Bazel: rename `exported.bazelrc` to `.bazelrc.exported`
redsun82 Apr 10, 2024
aca8d04
Bazel: fix `.bazelrc`
redsun82 Apr 10, 2024
c9565b3
Bazel/Kotlin: fix version comparison logic, add default version printing
redsun82 Apr 10, 2024
5bdd724
Bazel: move patching of `rules_kotlin` to a registry override
redsun82 Apr 9, 2024
a15681a
Bazel: ease update of local registry
redsun82 Apr 10, 2024
35a2ed8
Bazel/Kotlin: patch jdep emission
redsun82 Apr 10, 2024
1a7f25a
Merge pull request #16167 from github/redsun82/kotlin-patched-registry
redsun82 Apr 10, 2024
5df1abc
Bazel/Kotlin: use `"all"` for extension metadata direct dependencies
redsun82 Apr 10, 2024
24ef424
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 10, 2024
fe35902
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 11, 2024
02257ee
Bazel: use triple slash in `--registry`
redsun82 Apr 11, 2024
f0fc811
Bazel/Kotlin: add `2.0.0-RC1`, remove `2.0.0-Beta4`
redsun82 Apr 11, 2024
5415665
Bazel/Kotlin: make `_embeddable_source` more robust
redsun82 Apr 11, 2024
3b75d63
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 11, 2024
c18b556
Kotlin/Bazel: remove `2.0.255-SNAPSHOT` version
redsun82 Apr 11, 2024
7f495b1
Bazel/kotlin: make version detection more robust
redsun82 Apr 11, 2024
59fdbdb
Kotlin/Bazel: move defaults to separate bazel package
redsun82 Apr 11, 2024
3d14654
Bazel/Kotlin: tentatively fix version detection on Windows
redsun82 Apr 11, 2024
fc62ed5
Kotlin/Bazel: port `custom_plugin` test to use bazel
redsun82 Apr 12, 2024
b8c063e
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 12, 2024
4822de3
Kotlin/Bazel: add fail printouts to `_default_version`
redsun82 Apr 12, 2024
a834101
Use `fetchexclude=*` in `.lfsconfig` rather than `fetchinclude`
redsun82 Apr 12, 2024
c64d02d
Undo `.gitattributes` formatting, move `LFS` entry
redsun82 Apr 12, 2024
bc89742
Kotlin: fix space indentation in `OdasaOutput.java`
redsun82 Apr 12, 2024
9c3a615
CI: add non-blocking kotlin extractor build check
redsun82 Apr 12, 2024
2d16192
CI: fix typo in `kotlin-build.yml`
redsun82 Apr 12, 2024
9114131
Bazel: add settings required by internal repo
redsun82 Apr 12, 2024
b8010f2
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 12, 2024
65df2bb
Bazel/Kotlin: add `.exe` to `kotlinc` on windows
redsun82 Apr 12, 2024
0ad8ed3
Kotlin/Bazel: use `kotlinc.bat` instead of `kotlinc.exe` on Windows
redsun82 Apr 12, 2024
24c7ad5
Bazel/Kotlin: use plain `kotlinc` instead of result of `repository_ct…
redsun82 Apr 12, 2024
5c2d9fe
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 12, 2024
a78124b
Bazel/Kotlin: use a wrapper to get the current kotlin version
redsun82 Apr 12, 2024
92a5f3d
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 12, 2024
b36cabb
Anchor `.gitattributes` entries at root where it makes sense
redsun82 Apr 12, 2024
bdc8a7f
Revert "Use `fetchexclude=*` in `.lfsconfig` rather than `fetchinclude`"
redsun82 Apr 15, 2024
9d1901c
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 15, 2024
b07fa70
Kotlin/Bazel: provide wrapper for managing versions of `kotlinc`
redsun82 Apr 15, 2024
e53ef4a
Kotlin/Bazel: fix wrapper on Windows
redsun82 Apr 15, 2024
1b5675e
Kotlin/Bazel: tweak wrapper
redsun82 Apr 15, 2024
6a83bf9
Merge pull request #16208 from github/redsun82/kotlin-wrapper
redsun82 Apr 15, 2024
5bb2cba
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 15, 2024
bd631c5
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 15, 2024
8c705ad
Kotlin/Bazel: fix java release to 8 for java code
redsun82 Apr 15, 2024
735b341
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 16, 2024
aee3c0d
Add license and notice information to patched registry
redsun82 Apr 16, 2024
27ab487
Kotlin: simplify `kotlinc` wrapper
redsun82 Apr 16, 2024
306f0f1
Kotlin: accept `--select default` in kotlinc wrapper to select the de…
redsun82 Apr 16, 2024
a741170
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 16, 2024
c5f6c65
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 16, 2024
3678e51
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 17, 2024
7952f0e
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 22, 2024
f685843
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 22, 2024
aaa29d8
Remove unneeded slash in `kotlinc.bat`
redsun82 Apr 22, 2024
072e2ed
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 23, 2024
5b143ce
Kotlin: make wrapper install quietly unless `--select` is explicit
redsun82 Apr 23, 2024
c014cd8
Bazel: fix kotlin wrapper version dependency
redsun82 Apr 23, 2024
4aa0a8e
Kotlin: make wrapper more robust for windows
redsun82 Apr 24, 2024
a23327c
Merge branch 'main' into HEAD
redsun82 Apr 24, 2024
1e622e1
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 25, 2024
8e1d77b
Bazel: format file
redsun82 Apr 25, 2024
a841a2b
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 26, 2024
d7ecaae
Kotlin: back off from lazy LFS rules
redsun82 Apr 29, 2024
450f651
Bazel: remove generic lazy lfs files
redsun82 Apr 29, 2024
b834173
Merge branch 'main' into redsun82/kotlin
redsun82 Apr 29, 2024
d4e0a56
Kotlin: update wrapper location
redsun82 Apr 29, 2024
52a015f
Bazel: remove further unneeded files
redsun82 Apr 30, 2024
239b6d8
Merge branch 'main' into redsun82/kotlin
redsun82 May 6, 2024
514e24c
Kotlin: bring back lazy LFS dependencies
redsun82 May 6, 2024
e546560
Kotlin: restore `kotlin-compiler-embeddable-1.7.0.jar` to the maven c…
redsun82 May 6, 2024
75709bf
Merge branch 'main' into redsun82/kotlin
redsun82 May 16, 2024
eab940c
Merge branch 'main' into redsun82/kotlin
redsun82 May 22, 2024
821bd1f
Merge branch 'main' into redsun82/kotlin
redsun82 May 27, 2024
d1a2c0f
Merge branch 'main' into redsun82/kotlin
redsun82 Jun 4, 2024
99f70a6
Kotlin: address review comments
redsun82 Jun 4, 2024
fcd326e
CI: reword comment
redsun82 Jun 4, 2024
6a9cb90
Kotlin: rework header comment
redsun82 Jun 4, 2024
2fe0718
Explain `.lfsconfig` choice in the comment
redsun82 Jun 4, 2024
4c91bdc
Kotlin: `tgt` -> `target`
redsun82 Jun 4, 2024
e7cec01
Kotlin: make `current_kotlin_version.py` executable
redsun82 Jun 4, 2024
e693c27
Kotlin: remove unneeded patch
redsun82 Jun 4, 2024
c6039b3
Kotlin: update default `kotlinc` version
redsun82 Jun 4, 2024
be5c82c
Kotlin: add other tools to dev wrapper
redsun82 Jun 4, 2024
8205f86
Kotlin: use `tools/bazel` in integration test
redsun82 Jun 4, 2024
a48d71b
Merge branch 'main' into redsun82/kotlin
redsun82 Jun 4, 2024
10584b3
Kotlin: improve posix dev wrappers
redsun82 Jun 4, 2024
e4653a8
Kotlin: remove `kapt` wrapper, probably unneeded
redsun82 Jun 4, 2024
b7e16ca
Kotlin: fix `custom_plugin` test
redsun82 Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,37 @@
*.dll -text
*.pdb -text

java/ql/test/stubs/**/*.java linguist-generated=true
java/ql/test/experimental/stubs/**/*.java linguist-generated=true
/java/ql/test/stubs/**/*.java linguist-generated=true
/java/ql/test/experimental/stubs/**/*.java linguist-generated=true
/java/kotlin-extractor/deps/*.jar filter=lfs diff=lfs merge=lfs -text

# Force git not to modify line endings for go or html files under the go/ql directory
go/ql/**/*.go -text
go/ql/**/*.html -text
/go/ql/**/*.go -text
/go/ql/**/*.html -text
# Force git not to modify line endings for go dbschemes
go/*.dbscheme -text
/go/*.dbscheme -text
# Preserve unusual line ending from codeql-go merge
go/extractor/opencsv/CSVReader.java -text
/go/extractor/opencsv/CSVReader.java -text

# For some languages, upgrade script testing references really old dbscheme
# files from legacy upgrades that have CRLF line endings. Since upgrade
# resolution relies on object hashes, we must suppress line ending conversion
# for those testing dbscheme files.
*/ql/lib/upgrades/initial/*.dbscheme -text
/*/ql/lib/upgrades/initial/*.dbscheme -text

# Auto-generated modeling for Python
python/ql/lib/semmle/python/frameworks/data/internal/subclass-capture/*.yml linguist-generated=true
/python/ql/lib/semmle/python/frameworks/data/internal/subclass-capture/*.yml linguist-generated=true

# auto-generated bazel lock file
ruby/extractor/cargo-bazel-lock.json linguist-generated=true
ruby/extractor/cargo-bazel-lock.json -merge
/ruby/extractor/cargo-bazel-lock.json linguist-generated=true
/ruby/extractor/cargo-bazel-lock.json -merge

# auto-generated files for the C# build
csharp/paket.lock linguist-generated=true
# needs eol=crlf, as `paket` touches this file and saves it als crlf
csharp/.paket/Paket.Restore.targets linguist-generated=true eol=crlf
csharp/paket.main.bzl linguist-generated=true
csharp/paket.main_extension.bzl linguist-generated=true
/csharp/paket.lock linguist-generated=true
# needs eol=crlf, as `paket` touches this file and saves it as crlf
/csharp/.paket/Paket.Restore.targets linguist-generated=true eol=crlf
/csharp/paket.main.bzl linguist-generated=true
/csharp/paket.main_extension.bzl linguist-generated=true

# ripunzip tool
/misc/bazel/internal/ripunzip/ripunzip-* filter=lfs diff=lfs merge=lfs -text
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/kotlin-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Kotlin Build"

on:
pull_request:
paths:
- "java/kotlin-extractor/**"
- "misc/bazel/**"
- "misc/codegen/**"
- "*.bazel*"
- .github/workflows/kotlin-build.yml
branches:
- main
- rc/*
- codeql-cli-*

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
bazel query //java/kotlin-extractor/...
criemen marked this conversation as resolved.
Show resolved Hide resolved
igfoo marked this conversation as resolved.
Show resolved Hide resolved
# only build the default version as a sanity check that we can build from `codeql`
# the full official build will be checked by QLucie
bazel build //java/kotlin-extractor
46 changes: 46 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "10.0.0")
bazel_dep(name = "rules_kotlin", version = "1.9.4-codeql.1")
bazel_dep(name = "gazelle", version = "0.36.0")
bazel_dep(name = "rules_dotnet", version = "0.15.1")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
Expand Down Expand Up @@ -65,6 +66,51 @@ node.toolchain(
)
use_repo(node, "nodejs", "nodejs_toolchains")

kotlin_extractor_deps = use_extension("//java/kotlin-extractor:deps.bzl", "kotlin_extractor_deps")

# following list can be kept in sync by running `bazel mod tidy` in `codeql`
criemen marked this conversation as resolved.
Show resolved Hide resolved
use_repo(
kotlin_extractor_deps,
"codeql_kotlin_defaults",
"codeql_kotlin_embeddable",
"kotlin-compiler-1.5.0",
criemen marked this conversation as resolved.
Show resolved Hide resolved
"kotlin-compiler-1.5.10",
"kotlin-compiler-1.5.20",
"kotlin-compiler-1.5.30",
"kotlin-compiler-1.6.0",
"kotlin-compiler-1.6.20",
"kotlin-compiler-1.7.0",
"kotlin-compiler-1.7.20",
"kotlin-compiler-1.8.0",
"kotlin-compiler-1.9.0-Beta",
"kotlin-compiler-1.9.20-Beta",
"kotlin-compiler-2.0.0-RC1",
"kotlin-compiler-embeddable-1.5.0",
"kotlin-compiler-embeddable-1.5.10",
"kotlin-compiler-embeddable-1.5.20",
"kotlin-compiler-embeddable-1.5.30",
"kotlin-compiler-embeddable-1.6.0",
"kotlin-compiler-embeddable-1.6.20",
"kotlin-compiler-embeddable-1.7.0",
"kotlin-compiler-embeddable-1.7.20",
"kotlin-compiler-embeddable-1.8.0",
"kotlin-compiler-embeddable-1.9.0-Beta",
"kotlin-compiler-embeddable-1.9.20-Beta",
"kotlin-compiler-embeddable-2.0.0-RC1",
"kotlin-stdlib-1.5.0",
"kotlin-stdlib-1.5.10",
"kotlin-stdlib-1.5.20",
"kotlin-stdlib-1.5.30",
"kotlin-stdlib-1.6.0",
"kotlin-stdlib-1.6.20",
"kotlin-stdlib-1.7.0",
"kotlin-stdlib-1.7.20",
"kotlin-stdlib-1.8.0",
"kotlin-stdlib-1.9.0-Beta",
"kotlin-stdlib-1.9.20-Beta",
"kotlin-stdlib-2.0.0-RC1",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.2")

Expand Down
12 changes: 12 additions & 0 deletions java/downgrades/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")

pkg_files(
name = "downgrades",
srcs = glob(
["**"],
exclude = ["BUILD.bazel"],
),
prefix = "downgrades",
strip_prefix = strip_prefix.from_pkg(),
visibility = ["//visibility:public"],
)
182 changes: 182 additions & 0 deletions java/kotlin-extractor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
"""
# Usage overview
Building the extractor can be done via
```
bazel build @codeql//java/kotlin-extractor:codeql-extractor-kotlin-<variant>-<version>
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this can't be done from <root>, but can be done from <root>/ql or <root>/ql/java/kotlin-extractor. Is that expected?

Also, I think that this should mention that you needs tools/bazel to be the bazel on your path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this can't be done from , but can be done from /ql or /ql/java/kotlin-extractor. Is that expected?

I can add a note about building from the internal repo (bazel build @codeql//java/kotlin-extractor:etc is what works from there)

Also, I think that this should mention that you needs tools/bazel to be the bazel on your path.

Actually, any installed bazel or bazelisk will do (bar http fetching problems 😅). On codeql, if it's bazelisk (which is now the recommended bazel executable to have and is what bazel is on github actions) it will pick up the correct bazel version. If it's a fixed bazel version, it will exit any way with a helpful error on a version mismatch.

Furthermore, on semmle-code, any installed bazel will actually auto-pick tools/bazel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helpful error will have the user install bazel, though, and they will have to update their installation when we bump our bazel version. Wouldn't it be better to just tell them to use the tools/bazel they already have?

where `<variant>` is either `standalone` or `embeddable`, and `<version>` is one of the supported versions.
```
bazel build @codeql//java/kotlin-extractor
```
will build a default variant:
* standalone, unless `CODEQL_KOTLIN_SINGLE_VERSION_EMBEDDABLE` is set to true, in which case it will go for embeddable
* the version will be taken as the last supported version less than the version of the currently installed `kotlinc`
* if `CODEQL_KOTLIN_SINGLE_VERSION` is set, that will be used instead
* if `kotlinc` is not installed, `1.9.20-Beta` will be used

If `kotlinc` is updated, bazel won't be aware of it and will therefore keep the same default version. Possible workarounds for that:
criemen marked this conversation as resolved.
Show resolved Hide resolved
* `bazel clean`
* `bazel fetch --force @codeql_kotlin_defaults\\:all`
* `CODEQL_KOTLIN_SINGLE_VERSION= bazel build //java/kotlin-extractor`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work repeatedly? Presumably, the env variable needs to change for bazel to run the configuration again, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this requires CODEQL_KOTLIN_SINGLE_VERSION to appear empty in the environment for bazel to pick up a change. For example setting that in a persistent env won't help at all.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a note about this then, and/or drop this workaround?
Or maybe shell out to a source of randomness to set the variable content :D


If building from the `codeql` repository, `@codeql` can be skipped.
"""

# This file is used in the `@codeql_kotlin_embeddable` external repo, which means we need to
# reference explicitly @codeql
load(
"@codeql//java/kotlin-extractor:versions.bzl",
"VERSIONS",
"get_compatilibity_sources",
"get_language_version",
"version_less",
)
load("@rules_kotlin//kotlin:core.bzl", "kt_javac_options", "kt_kotlinc_options")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

package(default_visibility = ["//java/kotlin-extractor:__subpackages__"])

_for_embeddable = repo_name().endswith("codeql_kotlin_embeddable")

_common_extractor_name_prefix = "codeql-extractor-kotlin"

_extractor_name_prefix = "%s-%s" % (
_common_extractor_name_prefix,
"embeddable" if _for_embeddable else "standalone",
)

py_binary(
name = "generate_dbscheme",
srcs = ["generate_dbscheme.py"],
)

_resources = [
(
r,
r[len("src/main/resources/"):],
)
for r in glob(["src/main/resources/**"])
]

kt_javac_options(
name = "javac-options",
release = "8",
)

[
(
kt_kotlinc_options(
name = "kotlinc-options-%s" % v,
include_stdlibs = "none",
jvm_target = "1.8",
criemen marked this conversation as resolved.
Show resolved Hide resolved
language_version = get_language_version(v),
warn = "error",
x_optin = [
"kotlin.RequiresOptIn",
"org.jetbrains.kotlin.ir.symbols.%s" %
("IrSymbolInternals" if version_less(v, "2.0.0") else "UnsafeDuringIrConstructionAPI"),
],
x_suppress_version_warnings = True,
),
# * extractor.name is different for each version, so we need to put it in different output dirs
# * in order to put it in `resources`, we need to define `resource_strip_prefix` to strip this version
# * `resource_strip_prefix` is unique per jar, so we must also put other resources under the same version prefix
genrule(
name = "resources-%s" % v,
srcs = [src for src, _ in _resources],
outs = [
"%s/com/github/codeql/extractor.name" % v,
] + [
"%s/%s" % (v, tgt)
for _, tgt in _resources
],
cmd = "\n".join([
"echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v),
] + [
"cp $(execpath %s) $(RULEDIR)/%s/%s" % (src, v, tgt)
for src, tgt in _resources
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we call this target instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit doesn't seem to have been addressed, despite a thumbs-up emoji

]),
),
kt_jvm_library(
name = "%s-%s" % (_extractor_name_prefix, v),
srcs =
["@codeql//java/kotlin-extractor:generated-dbscheme"] +
glob(
[
"src/**/*.kt",
"src/**/*.java",
],
exclude = ["src/main/kotlin/utils/versions/**"],
) + get_compatilibity_sources(v, "src/main/kotlin/utils/versions"),
javac_opts = ":javac-options",
kotlinc_opts = ":kotlinc-options-%s" % v,
module_name = "codeql-kotlin-extractor",
# resource_strip_prefix is very nit-picky: the following makes it work from
# `codeql`, `@codeql_kotlin_embeddable` and `semmle-code`
resource_strip_prefix = (
("../%s/" % repo_name() if repo_name() else "") +
("%s/" % package_name() if package_name() else "") +
v
),
resources = [
":resources-%s" % v,
],
visibility = ["//visibility:public"],
deps = [
"@kotlin-compiler%s-%s" % (
"-embeddable" if _for_embeddable else "",
v,
),
"@kotlin-stdlib-%s" % v,
],
),
# if in main repository, alias the embeddable versions from the modified @codeql_kotlin_embeddable repo
alias(
name = "%s-embeddable-%s" % (_common_extractor_name_prefix, v),
actual = "@codeql_kotlin_embeddable//:%s-embeddable-%s" % (_common_extractor_name_prefix, v),
visibility = ["//visibility:public"],
) if not _for_embeddable else None,
)
for v in VERSIONS
]

(
genrule(
name = "generated-dbscheme",
srcs = ["@codeql//java:dbscheme"],
outs = ["KotlinExtractorDbScheme.kt"],
cmd = "$(execpath :generate_dbscheme) $< $@",
tools = [":generate_dbscheme"],
visibility = ["@codeql_kotlin_embeddable//:__pkg__"],
),
[
alias(
name = n,
actual = "//java/kotlin-extractor/defaults:%s" % n,
visibility = ["//visibility:public"],
)
for n in (
"%s-standalone" % _common_extractor_name_prefix,
"%s-embeddable" % _common_extractor_name_prefix,
_common_extractor_name_prefix,
)
],
alias(
name = "kotlin-extractor",
actual = _common_extractor_name_prefix,
visibility = ["//visibility:public"],
),
filegroup(
name = "many",
srcs = ["%s-%s-%s" % (
_common_extractor_name_prefix,
variant,
version,
) for variant in ("standalone", "embeddable") for version in VERSIONS],
visibility = ["//visibility:public"],
),
sh_binary(
name = "print-default-version",
srcs = ["//java/kotlin-extractor/defaults:default-version-printer"],
),
) if not _for_embeddable else None
14 changes: 14 additions & 0 deletions java/kotlin-extractor/current_kotlin_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import subprocess
redsun82 marked this conversation as resolved.
Show resolved Hide resolved
import re
import shutil

kotlinc = shutil.which('kotlinc')
if kotlinc is None:
raise Exception("kotlinc not found")
res = subprocess.run([kotlinc, "-version"], text=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
if res.returncode != 0:
raise Exception(f"kotlinc -version failed: {res.stderr}")
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) .*', res.stderr)
if m is None:
raise Exception(f'Cannot detect version of kotlinc (got {res.stderr})')
print(m[1])
36 changes: 36 additions & 0 deletions java/kotlin-extractor/defaults/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@codeql_kotlin_defaults//:defaults.bzl", "kotlin_extractor_defaults")

package(default_visibility = ["//java/kotlin-extractor:__pkg__"])

_common_extractor_name_prefix = "codeql-extractor-kotlin"

alias(
name = "%s-standalone" % _common_extractor_name_prefix,
actual = "//java/kotlin-extractor:%s-standalone-%s" % (
_common_extractor_name_prefix,
kotlin_extractor_defaults.extractor_version,
),
)

alias(
name = "%s-embeddable" % _common_extractor_name_prefix,
actual = "//java/kotlin-extractor:%s-embeddable-%s" % (
_common_extractor_name_prefix,
kotlin_extractor_defaults.extractor_version,
),
)

alias(
name = _common_extractor_name_prefix,
actual = "//java/kotlin-extractor:%s-%s-%s" % (
_common_extractor_name_prefix,
kotlin_extractor_defaults.variant,
kotlin_extractor_defaults.extractor_version,
),
)

genrule(
name = "default-version-printer",
outs = ["print-default-version.sh"],
cmd = "echo echo %s > $@" % kotlin_extractor_defaults.version,
)
Loading
Loading