diff --git a/java/kotlin-extractor2/BUILD.bazel b/java/kotlin-extractor2/BUILD.bazel deleted file mode 100644 index f95661f8128..00000000000 --- a/java/kotlin-extractor2/BUILD.bazel +++ /dev/null @@ -1,204 +0,0 @@ -""" -# Usage overview -Building the extractor can be done with bazel. If building from the internal repository, it is recommended to use -`tools/bazel` from there. - -A specific kotlin extractor variant can be built with -``` -bazel build @codeql//java/kotlin-extractor:codeql-extractor-kotlin-- -``` -where `` is either `standalone` or `embeddable`, and `` 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 available `kotlinc`, - or `CODEQL_KOTLIN_SINGLE_VERSION` if set. - -If building from the `codeql` repository, `@codeql` can be skipped. - -It is recommended to use the `kotlinc` wrapper in `dev` (which is also available in `tools` from `semmle-code`), which -takes care about providing a sensible default version and keep the version of the default target up to date. - -If the wrapper is not used and `kotlinc` is updated, bazel won't be aware of it and will therefore keep the same default -version. Possible workarounds for that: -* switch to using the `kotlinc` wrapper in `dev` as mentioned above -* `bazel clean` -* `bazel fetch --force @codeql//java/kotlin-extractor` -* `bazel fetch --force @codeql_kotlin_defaults//:all` (only from `codeql`) -""" - -# 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", - 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, target) - for _, target 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" % (source, v, target) - for source, target in _resources - ]), - ), - kt_jvm_library( - name = "%s-%s" % (_extractor_name_prefix, v), - srcs = - ["@codeql//java/kotlin-extractor:generated-dbscheme"] + - glob( - [ - "src/**/*.kt", - "src/**/*.java", - ], - exclude = [ - # a specific version is included back by `get_compatibility_sources` - "src/main/kotlin/utils/versions/**", - # this appears if `generated_dbscheme.py` is run manually, while we want the one built by bazel - "src/main/kotlin/KotlinExtractorDbScheme.kt", - ], - ) + 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"], - ), - genrule( - name = "versions-list", - outs = ["kotlin-versions.list"], - cmd = "\n".join(["cat > $@ << EOF"] + VERSIONS + ["EOF"]), - ), - # these are packed in the extractor pack for running QL tests - filegroup( - name = "version-picker", - srcs = [ - "pick-kotlin-version.py", - ":versions-list", - ], - visibility = ["//visibility:public"], - ), -) if not _for_embeddable else None diff --git a/java/kotlin-extractor2/build.gradle b/java/kotlin-extractor2/build.gradle deleted file mode 100644 index 57229642a92..00000000000 --- a/java/kotlin-extractor2/build.gradle +++ /dev/null @@ -1,71 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" - id 'org.jetbrains.dokka' version '1.4.32' -} - -group 'com.github.codeql' -version '0.0.1' - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib" - compileOnly("org.jetbrains.kotlin:kotlin-compiler") -} - -repositories { - mavenCentral() -} - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions { - jvmTarget = "1.8" - freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" - // enable the below for building with kotlinVersion=1.4.32: - // languageVersion = "1.5" - } -} - -sourceSets { - main { - kotlin { - // change the excludes for building with other versions. - // Currently 1.7.0 is configured: - excludes = [ - // For 1.7.20-Beta, the below two files should be included, and the corresponding v_1_7_20-Beta ones should be excluded from this list. - //"utils/versions/v_1_4_32/allOverriddenIncludingSelf.kt", - //"utils/versions/v_1_4_32/createImplicitParameterDeclarationWithWrappedDescriptor.kt", - "utils/versions/v_1_4_32/Descriptors.kt", - "utils/versions/v_1_4_32/FileEntry.kt", - "utils/versions/v_1_4_32/Functions.kt", - "utils/versions/v_1_4_32/IsUnderscoreParameter.kt", - "utils/versions/v_1_4_32/Psi2Ir.kt", - "utils/versions/v_1_4_32/Types.kt", - "utils/versions/v_1_4_32/withHasQuestionMark.kt", - - "utils/versions/v_1_5_20/Descriptors.kt", - "utils/versions/v_1_6_0/Descriptors.kt", - - "utils/versions/v_1_7_20-Beta/createImplicitParameterDeclarationWithWrappedDescriptor.kt", - "utils/versions/v_1_7_20-Beta/allOverriddenIncludingSelf.kt", - - "utils/versions/v_1_8_0/ExperimentalCompilerApi.kt", - "utils/versions/v_1_8_0/FirIncompatiblePluginAPI.kt", - ] - } - } -} - -jar { - archiveName = "${OUTPUT_JAR_NAME}" -} - -task getHomeDir { - doLast { - println gradle.gradleHomeDir - } -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } -} diff --git a/java/kotlin-extractor2/deps.bzl b/java/kotlin-extractor2/deps.bzl deleted file mode 100644 index 6e55969f251..00000000000 --- a/java/kotlin-extractor2/deps.bzl +++ /dev/null @@ -1,124 +0,0 @@ -load("//java/kotlin-extractor:versions.bzl", "VERSIONS") -load("//misc/bazel:lfs.bzl", "lfs_smudge") - -_kotlin_dep_build = """ -load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_import") - -kt_jvm_import( - name = "{name}", - jar = "{name}.jar", - visibility = ["//visibility:public"], -) -""" - -_empty_zip = "PK\005\006\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - -def _get_dep(repository_ctx, name): - return repository_ctx.path(Label("//java/kotlin-extractor/deps:%s" % name)) - -def _kotlin_dep_impl(repository_ctx): - _, _, name = repository_ctx.name.rpartition("~") - lfs_smudge(repository_ctx, [_get_dep(repository_ctx, name + ".jar")]) - - # for some reason rules_kotlin warns about these jars missing, this is to silence those warnings - repository_ctx.file("empty.zip", _empty_zip) - for jar in ( - "annotations-13.0.jar", - "kotlin-stdlib.jar", - "kotlin-reflect.jar", - "kotlin-script-runtime.jar", - "trove4j.jar", - ): - repository_ctx.symlink("empty.zip", jar) - repository_ctx.file("BUILD.bazel", _kotlin_dep_build.format(name = name)) - -_kotlin_dep = repository_rule( - implementation = _kotlin_dep_impl, -) - -def _walk(dir): - res = [] - next_dirs = [dir] - - # loops must be bounded in starlark - for i in range(100): - current_dirs = next_dirs - next_dirs = [] - for d in current_dirs: - children = d.readdir() - next_dirs.extend([c for c in children if c.is_dir]) - res.extend([c for c in children if not c.is_dir]) - if not next_dirs: - return res - fail("%s directory too deep" % dir) - -def _embeddable_source_impl(repository_ctx): - src_dir = repository_ctx.path(Label("//java/kotlin-extractor:src")) - repository_ctx.watch_tree(src_dir) - for src in _walk(src_dir): - contents = repository_ctx.read(src) - contents = contents.replace( - "import com.intellij", - "import org.jetbrains.kotlin.com.intellij", - ) - repository_ctx.file(str(src).replace(str(src_dir), "src"), contents) - repository_ctx.symlink( - Label("//java/kotlin-extractor:BUILD.bazel"), - "BUILD.bazel", - ) - -_embeddable_source = repository_rule(implementation = _embeddable_source_impl) - -def _get_version(repository_ctx, available = []): - default_version = repository_ctx.getenv("CODEQL_KOTLIN_SINGLE_VERSION") - if default_version: - return default_version - repository_ctx.watch(Label("//java/kotlin-extractor:dev/.kotlinc_version")) - version_picker = repository_ctx.path(Label("//java/kotlin-extractor:pick-kotlin-version.py")) - python = repository_ctx.which("python3") or repository_ctx.which("python") - - # use the kotlinc wrapper as fallback - path = repository_ctx.getenv("PATH") - path_to_add = repository_ctx.path(Label("//java/kotlin-extractor:dev")) - if not path: - path = str(path_to_add) - elif repository_ctx.os.name == "windows": - path = "%s;%s" % (path, path_to_add) - else: - path = "%s:%s" % (path, path_to_add) - res = repository_ctx.execute([python, version_picker] + available, environment = {"PATH": path}) - if res.return_code != 0: - fail(res.stderr) - return res.stdout.strip() - -def _defaults_impl(repository_ctx): - default_version = _get_version(repository_ctx) - default_variant = "standalone" - if repository_ctx.getenv("CODEQL_KOTLIN_SINGLE_VERSION_EMBEDDABLE") in ("true", "1"): - default_variant = "embeddable" - available_version = _get_version(repository_ctx, VERSIONS) - info = struct( - version = default_version, - variant = default_variant, - extractor_version = available_version, - ) - repository_ctx.file( - "defaults.bzl", - "kotlin_extractor_defaults = %s\n" % repr(info), - ) - repository_ctx.file("BUILD.bazel") - -_defaults = repository_rule(implementation = _defaults_impl) - -def _kotlin_deps_impl(module_ctx): - for v in VERSIONS: - for lib in ("compiler", "compiler-embeddable", "stdlib"): - _kotlin_dep(name = "kotlin-%s-%s" % (lib, v)) - _embeddable_source(name = "codeql_kotlin_embeddable") - _defaults(name = "codeql_kotlin_defaults") - return module_ctx.extension_metadata( - root_module_direct_deps = "all", - root_module_direct_dev_deps = [], - ) - -kotlin_extractor_deps = module_extension(implementation = _kotlin_deps_impl) diff --git a/java/kotlin-extractor2/gradle.properties b/java/kotlin-extractor2/gradle.properties deleted file mode 100644 index f9cd575cdd3..00000000000 --- a/java/kotlin-extractor2/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -kotlin.code.style=official -kotlinVersion=1.7.21 - -GROUP=com.github.codeql -VERSION_NAME=0.0.1 -POM_DESCRIPTION=CodeQL Kotlin extractor -OUTPUT_JAR_NAME=codeql-extractor-kotlin.jar - diff --git a/java/kotlin-extractor2/settings.gradle b/java/kotlin-extractor2/settings.gradle deleted file mode 100644 index fa1b7937da6..00000000000 --- a/java/kotlin-extractor2/settings.gradle +++ /dev/null @@ -1,8 +0,0 @@ -pluginManagement { - repositories { - mavenCentral() - gradlePluginPortal() - } -} - -rootProject.name = 'codeql-kotlin-extractor' diff --git a/java/kotlin-extractor2/versions.bzl b/java/kotlin-extractor2/versions.bzl deleted file mode 100644 index e124d6e150a..00000000000 --- a/java/kotlin-extractor2/versions.bzl +++ /dev/null @@ -1,47 +0,0 @@ -# when updating this list, `bazel mod tidy` should be run from `codeql` to update `MODULE.bazel` -VERSIONS = [ - "1.5.0", - "1.5.10", - "1.5.20", - "1.5.30", - "1.6.0", - "1.6.20", - "1.7.0", - "1.7.20", - "1.8.0", - "1.9.0-Beta", - "1.9.20-Beta", - "2.0.0-RC1", - "2.0.20-Beta2", -] - -def _version_to_tuple(v): - # 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) - return "%s.%s" % (major, minor) - -def _basename(path): - if "/" not in path: - return path - return path[path.rindex("/") + 1:] - -def get_compatilibity_sources(version, dir): - prefix = "%s/v_" % dir - available = native.glob(["%s*" % prefix], exclude_directories = 0) - - # we want files with the same base name to replace ones for previous versions, hence the map - srcs = {} - for d in available: - compat_version = d[len(prefix):].replace("_", ".") - if version_less(version, compat_version): - break - files = native.glob(["%s/*.kt" % d]) - srcs |= {_basename(f): f for f in files} - return srcs.values()