Skip to content

Commit

Permalink
Convert strings to label with the correct repository
Browse files Browse the repository at this point in the history
Remove `absolute_target` and use `Label` in the top-level bzl scope. This makes `Label` correctly evaluate to point to the repository where bzl file resides.

Bzlmod is more stringent about labels and `absolute_target` implementation doesn't work with it - the created labels are de-funct.

This works towards bazelbuild#660
It's one of the minor issues.
  • Loading branch information
comius committed Dec 22, 2022
1 parent b96a41d commit 42d4202
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
35 changes: 19 additions & 16 deletions kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ load(
_KtJsInfo = "KtJsInfo",
_TOOLCHAIN_TYPE = "TOOLCHAIN_TYPE",
)
load(
"//src/main/starlark/core/repositories:tools.bzl",
"absolute_target",
)

"""Kotlin Toolchains
Expand Down Expand Up @@ -264,9 +260,24 @@ _kt_toolchain = rule(
provides = [platform_common.ToolchainInfo],
)

_KT_DEFAULT_TOOLCHAIN = Label("//kotlin/internal:default_toolchain")

def kt_register_toolchains():
"""This macro registers the kotlin toolchain."""
native.register_toolchains(absolute_target("//kotlin/internal:default_toolchain"))
native.register_toolchains(str(_KT_DEFAULT_TOOLCHAIN))

# Evaluating the select in the context of bzl file to get its repository
_DEBUG_SELECT = select({
Label("//kotlin/internal:builder_debug_trace"): ["trace"],
"//conditions:default": [],
}) + select({
Label("//kotlin/internal:builder_debug_timings"): ["timings"],
"//conditions:default": [],
})

# Evaluating the labels in the context of bzl file to get its repository
_EXPERIMENTAL_USE_ABI_JARS = Label("//kotlin/internal:experimental_use_abi_jars")
_NOEXPERIMENTAL_USE_ABI_JARS = Label("//kotlin/internal:noexperimental_use_abi_jars")

def define_kt_toolchain(
name,
Expand All @@ -289,18 +300,10 @@ def define_kt_toolchain(
language_version = language_version,
api_version = api_version,
jvm_target = jvm_target,
debug =
select({
absolute_target("//kotlin/internal:builder_debug_trace"): ["trace"],
"//conditions:default": [],
}) +
select({
absolute_target("//kotlin/internal:builder_debug_timings"): ["timings"],
"//conditions:default": [],
}),
debug = _DEBUG_SELECT,
experimental_use_abi_jars = select({
absolute_target("//kotlin/internal:experimental_use_abi_jars"): True,
absolute_target("//kotlin/internal:noexperimental_use_abi_jars"): False,
_EXPERIMENTAL_USE_ABI_JARS: True,
_NOEXPERIMENTAL_USE_ABI_JARS: False,
"//conditions:default": experimental_use_abi_jars,
}),
experimental_multiplex_workers = experimental_multiplex_workers,
Expand Down
1 change: 0 additions & 1 deletion src/main/starlark/core/repositories/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ release_archive(
srcs = [
"BUILD.com_github_jetbrains_kotlin.bazel",
"compiler.bzl",
"tools.bzl",
"versions.bzl",
] + glob(["capabilities_*.bazel"]),
src_map = {
Expand Down
17 changes: 0 additions & 17 deletions src/main/starlark/core/repositories/tools.bzl

This file was deleted.

0 comments on commit 42d4202

Please sign in to comment.