Skip to content

Commit

Permalink
Support generated files with sibling repo layout.
Browse files Browse the repository at this point in the history
When using `experimental_sibling_repository_layout`, `file.path` won't contain a segment matching `workspace_root`, as the workspace name is encoded in the `root` path instead. In this change we first remove the root path prefix from each path. This allows patching the toolchain sysroot with rules like `copy_file()`, etc.
  • Loading branch information
yuzhy8701 committed Sep 17, 2024
1 parent f2244a5 commit 13a9cb8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,16 @@ def _symlink_sysroot_tree(ctx, name, target):
# Parse the path to the file relative to the workspace root so a
# symlink matching this path can be created within the sysroot.

file_path = file.path

# Removes file's root path to support derived files when sibling layout is enabled.
if file.root.path and file_path.startswith(file.root.path):
file_path = file_path[len(file.root.path):]

# The code blow attempts to parse any workspace names out of the
# path. For local targets, this code is a noop.
if target.label.workspace_root:
file_path = file.path.split(target.label.workspace_root, 1)[-1]
else:
file_path = file.path
file_path = file_path.split(target.label.workspace_root, 1)[-1]

symlink = ctx.actions.declare_file("{}/{}".format(name, file_path.lstrip("/")))

Expand Down

0 comments on commit 13a9cb8

Please sign in to comment.