From aedc76369d89be287db0384c2eb6368d2b10e5a1 Mon Sep 17 00:00:00 2001 From: Christopher Peterson Sauer Date: Wed, 2 Nov 2022 19:53:13 -0700 Subject: [PATCH] Fix flag<>targets warning https://github.com/hedronvision/bazel-compile-commands-extractor/issues/82 --- refresh.template.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/refresh.template.py b/refresh.template.py index e8ff1b4..975cb57 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -799,8 +799,11 @@ def _get_commands(target: str, flags: str): additional_flags = shlex.split(flags) + sys.argv[1:] - # Detect any positional args--build targets--in the flags, and issue a warning. - if not all(f.startswith('-') for f in additional_flags) or '--' in additional_flags[:-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.) + # And that we have to look for targets. checking for a - prefix is not enough. Consider the case of `-c opt` leading to a false positive + if ('--' in additional_flags[:-1] + or any(re.match(r'-?(@|:|//)', f) for f in additional_flags)): log_warning(""">>> The flags you passed seem to contain targets. Try adding them as targets in your refresh_compile_commands rather than flags. [Specifying targets at runtime isn't supported yet, and in a moment, Bazel will likely fail to parse without our help. If you need to be able to specify targets at runtime, and can't easily just add them to your refresh_compile_commands, please open an issue or file a PR. You may also want to refer to https://github.com/hedronvision/bazel-compile-commands-extractor/issues/62.]""")