Skip to content
Merged
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
5 changes: 4 additions & 1 deletion zig/private/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ bzl_library(
name = "bazel_builtin",
srcs = ["bazel_builtin.bzl"],
visibility = ["//zig:__subpackages__"],
deps = ["//zig/private/providers:zig_module_info"],
deps = [
":escape_label",
"//zig/private/providers:zig_module_info",
],
)

bzl_library(
Expand Down
7 changes: 2 additions & 5 deletions zig/private/common/bazel_builtin.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Generate the `bazel_builtin` module."""

load("//zig/private/common:escape_label.bzl", "escape_label")
load(
"//zig/private/providers:zig_module_info.bzl",
"zig_module_info",
Expand All @@ -25,11 +26,7 @@ def bazel_builtin_module(ctx):
package_name = ctx.label.package
target_name = ctx.label.name

name = "bazel_builtin_A{repo}_S_S{package}_C{target}".format(
repo = repo_name.replace("~", "_T"),
package = package_name.replace("/", "_S"),
target = target_name,
)
name = "bazel_builtin_" + escape_label(label = ctx.label)
main = ctx.actions.declare_file(name + ".zig")

substitutions = ctx.actions.template_dict()
Expand Down
15 changes: 6 additions & 9 deletions zig/tests/module_info_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("//zig/private/common:escape_label.bzl", "escape_label")
load(
"//zig/private/providers:zig_module_info.bzl",
"ZigModuleInfo",
"zig_module_specifications",
)

def _bazel_builtin_name(label):
return "bazel_builtin_A{repo}_S_S{package}_C{target}".format(
repo = label.repo_name if hasattr(label, "repo_name") else label.workspace_name,
package = label.package.replace("/", "_S"),
target = label.name,
)
def _bazel_builtin_canonical_name(label):
return "bazel_builtin_" + escape_label(label = label)

def _bazel_builtin_file_name(ctx, label):
return paths.join(
ctx.bin_dir.path,
label.workspace_root,
label.package,
_bazel_builtin_name(label) + ".zig",
_bazel_builtin_canonical_name(label) + ".zig",
)

def _bazel_builtin_mod_flags(ctx, label):
return ["'-M{}={}'".format(
_bazel_builtin_name(label),
_bazel_builtin_canonical_name(label),
_bazel_builtin_file_name(ctx, label),
)]

def _bazel_builtin_dep(label):
return "'bazel_builtin={}'".format(_bazel_builtin_name(label))
return "'bazel_builtin={}'".format(_bazel_builtin_canonical_name(label))

def _write_simple_module_expected_specs_args_impl(ctx):
mod = ctx.attr.mod[ZigModuleInfo]
Expand Down
Loading