Skip to content

Commit a4a6a90

Browse files
committed
file based filter
1 parent abdd06e commit a4a6a90

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

refresh.template.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,9 @@ def _get_commands(target: str, flags: str):
828828
# Log clear completion messages
829829
log_info(f">>> Analyzing commands used in {target}")
830830

831-
additional_flags = shlex.split(flags) + sys.argv[1:]
831+
additional_flags = shlex.split(flags) + [arg for arg in sys.argv[1:] if not arg.startswith('--file=')]
832+
file_flags = [arg for arg in sys.argv[1:] if arg.startswith('--file=')]
833+
assert len(file_flags) < 2, f"Only one or zero --file is supported current args = {sys.argv[1:]}"
832834

833835
# Detect anything that looks like a build target in the flags, and issue a warning.
834836
# Note that positional arguments after -- are all interpreted as target patterns. (If it's at the end, then no worries.)
@@ -851,6 +853,18 @@ def _get_commands(target: str, flags: str):
851853
if {exclude_external_sources}:
852854
# For efficiency, have bazel filter out external targets (and therefore actions) before they even get turned into actions or serialized and sent to us. Note: this is a different mechanism than is used for excluding just external headers.
853855
target_statment = f"filter('^(//|@//)',{target_statment})"
856+
if (len(file_flags) == 1):
857+
# Strip --file=
858+
file_path = file_flags[0][7:]
859+
# Query escape
860+
file_path = file_path.replace("+", "\+").replace("-", "\-")
861+
# For header file we try to find from hdrs and srcs to get the targets
862+
if file_path.endswith('.h'):
863+
# Since attr function can't query with full path, get the file name to query
864+
head, tail = os.path.split(file_path)
865+
target_statment = f"attr(hdrs, '{tail}', {target_statment}) + attr(srcs, '{tail}', {target_statment})"
866+
else:
867+
target_statment = f"inputs('{file_path}', {target_statment})"
854868
aquery_args = [
855869
'bazel',
856870
'aquery',

0 commit comments

Comments
 (0)