Skip to content

Commit

Permalink
isolated bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
restingbull committed Dec 8, 2023
1 parent c3928ac commit 230cee3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/main/starlark/core/plugins/test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@rules_testing//lib:test_suite.bzl", "test_suite", "analysis_test")

def _add_plugin_options_test(name):
analysis_test(
name = name,
impl = _foo_test_impl,
attrs = {"myattr": attr.string(default="default")}
)




def _assert_plugin_options_impl(env):
env.expect.that_str(...).equals(...)

def my_test_suite(name):
test_suite(
name = name,
tests = [
_foo_test,
]
)
2 changes: 1 addition & 1 deletion src/main/starlark/core/repositories/bzlmod_bootstrap.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@released_rules_kotlin//src/main/starlark/core/repositories:initialize.bzl", "kotlin_repositories")

def _rules_kotlin_bootstrap_extensions_impl(mctx):
def _rules_kotlin_bootstrap_extensions_impl(_):
kotlin_repositories(
is_bzlmod = True,
compiler_repository_name = "released_com_github_jetbrains_kotlin",
Expand Down
16 changes: 14 additions & 2 deletions src/main/starlark/core/repositories/bzlmod_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load(
"http_archive",
)
load(
"//src/main/starlark/core/repositories:initialize.bzl",
"//src/main/starlark/core/repositories:initialize.release.bzl",
_kotlin_repositories = "kotlin_repositories",
_kotlinc_version = "kotlinc_version",
_ksp_version = "ksp_version",
Expand All @@ -23,7 +23,6 @@ _version_tag = tag_class(
)

def _extra_repositories():
# TODO(bencodes) This really needs to be a development dependency
# This tarball intentionally does not have a SHA256 because the upstream URL can change without notice
# For more context: https://github.com/bazelbuild/bazel-toolchains/blob/0c1f7c3c5f9e63f1e0ee91738b964937eea2d3e0/WORKSPACE#L28-L32
http_archive(
Expand Down Expand Up @@ -51,6 +50,19 @@ def _rules_kotlin_extensions_impl(mctx):
_kotlin_repositories_args["ksp_compiler_release"] = ksp_version
_kotlin_repositories(**_kotlin_repositories_args)

_versions.use_repository(
name = "released_rules_kotlin",
rule = http_archive,
version = _versions.RULES_KOTLIN,
patch_cmds = [
# without repo mapping, force remap the internal dependencies to use the correct version of kotlin
"grep -rl '\"@*{repo}' src kotlin | xargs sed -E -i '' 's/\"(@*)({repo})/\"\\1released_\\2/g'".format(
repo = repo,
)
for repo in ["com_github_jetbrains_kotlin", "com_github_google_ksp"]
],
)

_extra_repositories()

rules_kotlin_extensions = module_extension(
Expand Down
13 changes: 13 additions & 0 deletions src/main/starlark/core/repositories/download.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ def kt_download_local_dev_dependencies():
"proto/private",
],
)

versions.use_repository(
name = "released_rules_kotlin",
rule = http_archive,
version = versions.RULES_KOTLIN,
patch_cmds = [
# without repo mapping, force remap the internal dependencies to use the correct version of kotlin
"grep -rl '\"@*{repo}' src kotlin | xargs sed -E -i '' 's/\"(@*)({repo})/\"\\1released_\\2/g'".format(
repo = repo,
)
for repo in ["com_github_jetbrains_kotlin", "com_github_google_ksp"]
],
)
16 changes: 4 additions & 12 deletions src/main/starlark/core/repositories/initialize.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ load(
load(":setup.bzl", "kt_configure")
load(":versions.bzl", _versions = "versions")

#exports
# exports
versions = _versions
kotlinc_version = _kotlinc_version
ksp_version = _ksp_version

def kotlin_repositories(
is_bzlmod = False,
compiler_release = versions.KOTLIN_CURRENT_COMPILER_RELEASE,
ksp_compiler_release = versions.KSP_CURRENT_COMPILER_PLUGIN_RELEASE):
"""Call this in the WORKSPACE file to setup the Kotlin rules.
Expand All @@ -43,14 +42,7 @@ def kotlin_repositories(
ksp_compiler_release: (internal) version provider from versions.bzl.
"""
_release_kotlin_repositories(is_bzlmod = is_bzlmod, compiler_release = compiler_release, ksp_compiler_release = ksp_compiler_release)

versions.use_repository(
name = "released_rules_kotlin",
rule = http_archive,
version = versions.RULES_KOTLIN,
)

# When Bzlmod is enabled skip over the toolchain setup entirely
if is_bzlmod:
return
kt_configure()

def _http_archive(rctx):
rctx.down
6 changes: 6 additions & 0 deletions src/main/starlark/core/repositories/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
load("@released_rules_kotlin//src/main/starlark/core/repositories:initialize.bzl", release_kotlin_repositories = "kotlin_repositories")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

def kt_configure():
"""Setup dependencies. Must be called AFTER kt_download_local_dev_dependencies() """
release_kotlin_repositories(
is_bzlmod = True,
compiler_repository_name = "released_com_github_jetbrains_kotlin",
ksp_repository_name = "released_com_github_google_ksp",
)

native.register_toolchains("@released_rules_kotlin//kotlin/internal:default_toolchain")

Expand Down

0 comments on commit 230cee3

Please sign in to comment.