Skip to content

Commit 6a6777a

Browse files
committed
normalize file path if the --file is a subpath of the cwd
1 parent 40b9131 commit 6a6777a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

refresh.template.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,11 @@ def _get_commands(target: str, flags: str):
983983

984984
if file_flags:
985985
file_path = file_flags[0]
986+
rel_path = os.path.relpath(file_path, os.getcwd())
987+
if not rel_path.startswith(".."):
988+
log_info(f">>> Detected file path {file_path} is relative path changed to {rel_path}")
989+
file_path = rel_path
990+
986991
target_statement = f"deps('{target}')"
987992
if file_path.endswith(_get_files.source_extensions):
988993
target_statement_candidates.append(f"inputs('{re.escape(file_path)}', {target_statement})")
@@ -997,7 +1002,7 @@ def _get_commands(target: str, flags: str):
9971002
target_statement_candidates.extend([
9981003
header_target_statement,
9991004
f"allpaths({target}, {header_target_statement})", # Ordering is ideal, breadth-first from the deepest dependency, despite the docs. TODO (1) There's a bazel bug that produces extra actions, not on the path but downstream, so we probably want to pass --noinclude_aspects per https://github.com/bazelbuild/bazel/issues/18289 to eliminate them (at the cost of some valid aspects). (2) We might want to benchmark with --infer_universe_scope (if supported) and --universe-scope=target with query allrdeps({header_target_statement}, <maybe some limited depth>) or rdeps, checking speed but also ordering (the docs indicate it is likely to be lost, which is a problem) and for inclusion of the header target. We'd guess it'll have the same aspects bug as allpaths. (3) We probably also also want to *just* run this query, not the whole list, since it captures the former and is therefore unlikely to add much latency, since a given header is probabably either used internally to the target (find on first match) for header-only (must traverse all paths in all targets until you get a match) for all top-level targets, and since we can separate out the last, see below.
1000-
f'deps({target})', # TODO: Let's detect out-of-bazel, absolute paths and run this if and only if we're looking for a system header. We need to think about how we want to handle absolute paths more generally, perhaps normalizing them to relative if possible, like with the windows absolute path issue, above.
1005+
target_statement,
10011006
])
10021007
else:
10031008
if {exclude_external_sources}:

0 commit comments

Comments
 (0)