From 8f8976ed5b478badab8ab8d81b78ea365d279bcb Mon Sep 17 00:00:00 2001 From: Snorlax Date: Fri, 23 Dec 2022 23:41:18 +0800 Subject: [PATCH] file based filter --- refresh.template.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/refresh.template.py b/refresh.template.py index f985ba5..78fe020 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -834,7 +834,9 @@ def _get_commands(target: str, flags: str): # Log clear completion messages log_info(f">>> Analyzing commands used in {target}") - additional_flags = shlex.split(flags) + sys.argv[1:] + additional_flags = shlex.split(flags) + [arg for arg in sys.argv[1:] if not arg.startswith('--file=')] + file_flags = [arg for arg in sys.argv[1:] if arg.startswith('--file=')] + assert len(file_flags) < 2, f"Only one or zero --file is supported current args = {sys.argv[1:]}" # Detect anything that looks like a build target in the flags, and issue a warning. # Note that positional arguments after -- are all interpreted as target patterns. (If it's at the end, then no worries.) @@ -857,6 +859,18 @@ def _get_commands(target: str, flags: str): if {exclude_external_sources}: # 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. target_statment = f"filter('^//',{target_statment})" + if (len(file_flags) == 1): + # Strip --file= + file_path = file_flags[0][7:] + # Query escape + file_path = file_path.replace("+", "\+").replace("-", "\-") + # For header file we try to find from hdrs and srcs to get the targets + if file_path.endswith('.h'): + # Since attr function can't query with full path, get the file name to query + head, tail = os.path.split(file_path) + target_statment = f"attr(hdrs, '{tail}', {target_statment}) + attr(srcs, '{tail}', {target_statment})" + else: + target_statment = f"inputs('{file_path}', {target_statment})" aquery_args = [ 'bazel', 'aquery',