Skip to content

Commit

Permalink
openroad.bzl: Hack away prefix
Browse files Browse the repository at this point in the history
Hack to make `$(location <label>)` expansions
work when configuration files are generated for
executables that are run with `bazelisk run`.
Hacks a `File`'s `.path` into a `.short_path`.
  • Loading branch information
hovind authored and oharboe committed Oct 25, 2024
1 parent ff36e26 commit a21a3a6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions openroad.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ def _config_content(arguments, paths):
return ("".join(sorted(["export {}?={}\n".format(*pair) for pair in arguments.items()]) +
["include {}\n".format(path) for path in paths]))

def _hack_away_prefix(arguments, prefix):
return {k: v.removeprefix(prefix + "/") for k, v in arguments.items()}

def _data_arguments(ctx):
return {k: ctx.expand_location(v, ctx.attr.data) for k, v in ctx.attr.arguments.items()}

Expand Down Expand Up @@ -732,7 +735,10 @@ def _yosys_impl(ctx):
ctx.actions.write(
output = config_short,
content = _config_content(
arguments = _data_arguments(ctx) | _required_arguments(ctx) | _orfs_arguments(short = True, *[dep[OrfsInfo] for dep in ctx.attr.deps]) | _verilog_arguments(ctx.files.verilog_files, short = True),
arguments = _hack_away_prefix(
arguments = _data_arguments(ctx) | _required_arguments(ctx) | _orfs_arguments(short = True, *[dep[OrfsInfo] for dep in ctx.attr.deps]) | _verilog_arguments(ctx.files.verilog_files, short = True),
prefix = config_short.root.path,
),
paths = [file.short_path for file in ctx.files.extra_configs],
),
)
Expand Down Expand Up @@ -894,7 +900,10 @@ def _make_impl(ctx, stage, steps, forwarded_names = [], result_names = [], objec
ctx.actions.write(
output = config_short,
content = _config_content(
arguments = extra_arguments | _data_arguments(ctx) | _required_arguments(ctx) | _orfs_arguments(ctx.attr.src[OrfsInfo], short = True),
arguments = _hack_away_prefix(
arguments = extra_arguments | _data_arguments(ctx) | _required_arguments(ctx) | _orfs_arguments(ctx.attr.src[OrfsInfo], short = True),
prefix = config_short.root.path,
),
paths = [file.short_path for file in ctx.files.extra_configs],
),
)
Expand Down

0 comments on commit a21a3a6

Please sign in to comment.