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

Replace target attribute with targets #428

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/with_prebuilt_ninja_artefact/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ native_tool_toolchain(
# In the path, we also start with the name of the directory,
# in this case the external repository.
path = "ninja_artefact/ninja",
target = "@ninja_artefact//:all",
targets = ["@ninja_artefact//:all"],
visibility = ["//visibility:public"],
)

Expand Down
6 changes: 3 additions & 3 deletions tools/build_defs/native_tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ make_tool(
native_tool_toolchain(
name = "built_make",
path = "make/bin/make",
target = ":make_tool",
targets = [":make_tool"],
visibility = ["//visibility:public"],
)

Expand All @@ -38,7 +38,7 @@ cmake_tool(
native_tool_toolchain(
name = "built_cmake",
path = "cmake/bin/cmake",
target = ":cmake_tool",
targets = [":cmake_tool"],
visibility = ["//visibility:public"],
)

Expand All @@ -57,7 +57,7 @@ ninja_tool(
native_tool_toolchain(
name = "built_ninja",
path = "ninja/ninja",
target = ":ninja_tool",
targets = [":ninja_tool"],
visibility = ["//visibility:public"],
)

Expand Down
25 changes: 17 additions & 8 deletions tools/build_defs/native_tools/native_tools_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ ToolInfo = provider(
"to the bazel-genfiles, i.e. it should start with the name of the top directory of the built tree " +
"artifact. (Please see the example `//examples:built_cmake_toolchain`)"
),
"target": (
"If the tool is preinstalled, must be None. " +
"targets": (
"If the tool is preinstalled, must be an empty list. " +
"If the tool is built as part of the build, the corresponding build target, which should produce " +
"the tree artifact with the binary to call."
),
},
)

def _native_tool_toolchain(ctx):
if not ctx.attr.path and not ctx.attr.target:
fail("Either path or target (and path) should be defined for the tool.")
if not ctx.attr.path and not ctx.attr.target and not ctx.attr.targets:
fail("Either path or targets (and path) should be defined for the tool.")
targets = ctx.attr.targets
if not targets and ctx.attr.target:
targets = [ctx.attr.target]
return platform_common.ToolchainInfo(data = ToolInfo(
path = ctx.attr.path,
target = ctx.attr.target,
targets = targets,
))

native_tool_toolchain = rule(
Expand All @@ -42,14 +45,20 @@ native_tool_toolchain = rule(
"of the built tree artifact. (Please see the example `//examples:built_cmake_toolchain`)"
),
),
"target": attr.label(
"targets": attr.label_list(
mandatory = False,
allow_empty = True,
default = [],
doc = (
"If the tool is preinstalled, must be None. " +
"If the tool is preinstalled, must be an empty list. " +
"If the tool is built as part of the build, the corresponding build target, " +
"which should produce the tree artifact with the binary to call."
),
),
"target": attr.label(
mandatory = False,
doc = """DEPRECATED: use `targets` instead.""",
),
},
)

Expand All @@ -59,5 +68,5 @@ def access_tool(toolchain_type_, ctx, tool_name):
return tool_toolchain.data
return ToolInfo(
path = tool_name,
target = None,
targets = [],
)
4 changes: 2 additions & 2 deletions tools/build_defs/native_tools/tool_access.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def get_make_data(ctx):

def _access_and_expect_label_copied(toolchain_type_, ctx, tool_name):
tool_data = access_tool(toolchain_type_, ctx, tool_name)
if tool_data.target:
if tool_data.targets:
return struct(
deps = [tool_data.target],
deps = tool_data.targets,
# as the tool will be copied into tools directory
path = "$EXT_BUILD_DEPS/bin/{}".format(tool_data.path),
)
Expand Down