Skip to content

Commit

Permalink
unsound
Browse files Browse the repository at this point in the history
  • Loading branch information
abrisco committed May 11, 2024
1 parent 424f001 commit 7d22644
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
8 changes: 5 additions & 3 deletions dependency_support/org_gnu_bison/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ filegroup(
visibility = ["//visibility:public"],
)

exports_files([
"data",
])
alias(
name = "data",
actual = ":bison_runtime_data",
visibility = ["//visibility:public"],
)

cc_library(
name = "bison_src_headers",
Expand Down
35 changes: 33 additions & 2 deletions dependency_support/verilator/private/verilator_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ def _is_expandable(value):

return False

def _locate_bison_data_root(files):
"""Locate the GNU Bison runtime data directory based on a set of inputs
This function assumes all files are located within the same directory.
Args:
files (list[File]): A list of files to use for locating Bison runtime data.
Returns:
str: The execpath of the data directory.
"""
if not files:
fail("No bison data files provided")

file = files[0]

parent, _, _ = file.path.partition("/data/")
if parent == file.path:
fail("Unable to locate data directory from: {}", file.owner)

return "{}/data".format(parent)

def _verilator_bisonpre_impl(ctx):
data = [ctx.attr.bisonpre] + ctx.attr.srcs + ctx.attr.tools
args = ctx.actions.args()
Expand All @@ -65,15 +87,19 @@ def _verilator_bisonpre_impl(ctx):
ctx.expand_location(a, data) if _is_expandable(a) else a
for a in ctx.attr.args
])

envs = {
"BISON_PKGDATADIR": _locate_bison_data_root(ctx.files.bison_data),
}
envs.update({
# Expand $(location) / $(locations) in the values.
k: ctx.expand_location(v, data) if _is_expandable(v) else v
for k, v in ctx.attr.env.items()
}
})
ctx.actions.run(
outputs = ctx.outputs.outs,
inputs = ctx.files.srcs,
tools = [ctx.file.bisonpre] + ctx.files.tools,
tools = [ctx.file.bisonpre] + ctx.files.tools + ctx.files.bison_data,
executable = ctx.executable._process_wrapper,
arguments = [args],
mnemonic = "VerilatorBisonPre",
Expand All @@ -92,6 +118,11 @@ verilator_bisonpre = rule(
"args": attr.string_list(
doc = "Command line arguments of the `bisonpre`",
),
"bison_data": attr.label(
doc = "Runtime data for GNU Bison.",
allow_files = True,
mandatory = True,
),
"bisonpre": attr.label(
doc = "The path to the `bisonpre` tool.",
allow_single_file = True,
Expand Down
3 changes: 1 addition & 2 deletions dependency_support/verilator/verilator.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ verilator_bisonpre(
name = "verilator_bison",
srcs = [
"src/verilog.y",
"@org_gnu_bison//:data",
],
outs = [
"V3ParseBison.c",
Expand All @@ -202,8 +201,8 @@ verilator_bisonpre(
"$(execpath src/verilog.y)",
],
bisonpre = "src/bisonpre",
bison_data = "@org_gnu_bison//:data",
env = {
"BISON_PKGDATADIR": "$(execpath @org_gnu_bison//:data)",
"M4": "$(execpath @org_gnu_m4//:m4)",
},
tools = [
Expand Down

0 comments on commit 7d22644

Please sign in to comment.