Skip to content

Commit b446046

Browse files
mattemalexeagle
authored andcommitted
handle in expand_path_into_runfiles
1 parent 6b2b019 commit b446046

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎internal/common/expand_into_runfiles.bzl‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,40 @@ def expand_location_into_runfiles(ctx, path):
3232
return expand_path_into_runfiles(ctx, path)
3333

3434
def expand_path_into_runfiles(ctx, path):
35-
"""Expand a path into runfiles.
35+
"""Expand paths into runfiles.
3636
37-
Given a file path that might contain a $(location) label expansion,
38-
provide the path to the file in runfiles.
37+
Given a file path that might contain a $(location) or $(locations) label expansion,
38+
provide the paths to the file in runfiles.
3939
4040
See https://docs.bazel.build/versions/master/skylark/lib/ctx.html#expand_location
4141
4242
Args:
4343
ctx: context
44-
path: the path to expand
44+
path: the paths to expand
4545
4646
Returns:
47-
The expanded path
47+
The expanded paths
4848
"""
4949
targets = ctx.attr.data if hasattr(ctx.attr, "data") else []
5050
expanded = ctx.expand_location(path, targets)
51+
52+
expansion = [resolve_expanded_path(ctx, exp) for exp in expanded.strip().split(" ")]
53+
54+
return " ".join(expansion)
55+
56+
def resolve_expanded_path(ctx, expanded):
57+
"""Resolves an expanded path
58+
59+
Given a file path that has been expaned with $(location), resolve the path to include the workspace name,
60+
handling when that path is within bin_dir or gen_fir
61+
62+
Args:
63+
ctx: context
64+
expanded: the expanded path to resolve
65+
66+
Returns:
67+
The resolved path
68+
"""
5169
if expanded.startswith("../"):
5270
return expanded[len("../"):]
5371
if expanded.startswith(ctx.bin_dir.path):

0 commit comments

Comments
 (0)