Skip to content

Commit

Permalink
file based filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xinzhengzhang committed Dec 23, 2022
1 parent a426081 commit 8f8976e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion refresh.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand All @@ -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',
Expand Down

0 comments on commit 8f8976e

Please sign in to comment.