From 0e4dad49cbd911e8ae39f1d0e40e94abe73ec245 Mon Sep 17 00:00:00 2001 From: nekosu Date: Thu, 19 Sep 2024 18:57:00 +0800 Subject: [PATCH 1/4] feat: support startup flags --- refresh.template.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/refresh.template.py b/refresh.template.py index 194f365e..bda46645 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -1170,13 +1170,32 @@ def _convert_compile_commands(aquery_output): 'directory': os.environ["BUILD_WORKSPACE_DIRECTORY"], } +def _split_startup(additional_flags): + new_flags = [] + startup_flags = [] + skip_next = False + + for flag in additional_flags: + if skip_next: + startup_flags.append(flag) + skip_next = False + continue + + if flag == "--startup": + skip_next = True + else: + new_flags.append(flag) + + return new_flags, startup_flags def _get_commands(target: str, flags: str): """Yields compile_commands.json entries for a given target and flags, gracefully tolerating errors.""" # Log clear completion messages log_info(f">>> Analyzing commands used in {target}") - additional_flags = shlex.split(flags) + sys.argv[1:] + argv_flags, argv_startup_flags = _split_startup(sys.argv[1:]) + + additional_flags = shlex.split(flags) + argv_flags # 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.) @@ -1199,8 +1218,9 @@ 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})" - aquery_args = [ - 'bazel', + aquery_args = [ 'bazel' ] + aquery_args += argv_startup_flags + aquery_args += [ 'aquery', # Aquery docs if you need em: https://docs.bazel.build/versions/master/aquery.html # Aquery output proto reference: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/analysis_v2.proto From e253c72c63510dfbec3cd4ba1f59af9190e58339 Mon Sep 17 00:00:00 2001 From: nekosu Date: Sat, 25 Jan 2025 19:49:35 +0800 Subject: [PATCH 2/4] fix: windows TP flag --- refresh.template.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refresh.template.py b/refresh.template.py index bda46645..182126a4 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -681,7 +681,8 @@ def _get_files(compile_action): and not source_file.endswith(_get_files.c_source_extensions) and not any(arg.startswith('-x') or arg.startswith('--language') or arg.lower() in ('-objc', '-objc++', '/tc', '/tp') for arg in compile_action.arguments)): if compile_action.arguments[0].endswith('cl.exe'): # cl.exe and also clang-cl.exe - lang_flag = '/TP' # https://docs.microsoft.com/en-us/cpp/build/reference/tc-tp-tc-tp-specify-source-file-type + pass + # lang_flag = '/TP' # https://docs.microsoft.com/en-us/cpp/build/reference/tc-tp-tc-tp-specify-source-file-type else: lang_flag = _get_files.extensions_to_language_args[os.path.splitext(source_file)[1]] # Insert at front of (non executable) args, because --language is only supposed to take effect on files listed thereafter From abe6981b2adda3aace8e398d7033001620c34f33 Mon Sep 17 00:00:00 2001 From: nekosu Date: Sat, 25 Jan 2025 20:16:42 +0800 Subject: [PATCH 3/4] fix: missing var --- refresh.template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refresh.template.py b/refresh.template.py index 182126a4..6ad5ee76 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -681,7 +681,7 @@ def _get_files(compile_action): and not source_file.endswith(_get_files.c_source_extensions) and not any(arg.startswith('-x') or arg.startswith('--language') or arg.lower() in ('-objc', '-objc++', '/tc', '/tp') for arg in compile_action.arguments)): if compile_action.arguments[0].endswith('cl.exe'): # cl.exe and also clang-cl.exe - pass + lang_flag = '' # lang_flag = '/TP' # https://docs.microsoft.com/en-us/cpp/build/reference/tc-tp-tc-tp-specify-source-file-type else: lang_flag = _get_files.extensions_to_language_args[os.path.splitext(source_file)[1]] From 5a46246be472eb971a3cef6a5e9edea8af785ab2 Mon Sep 17 00:00:00 2001 From: nekosu Date: Sat, 25 Jan 2025 20:20:22 +0800 Subject: [PATCH 4/4] fix: empty param --- refresh.template.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/refresh.template.py b/refresh.template.py index 6ad5ee76..9235a172 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -685,8 +685,9 @@ def _get_files(compile_action): # lang_flag = '/TP' # https://docs.microsoft.com/en-us/cpp/build/reference/tc-tp-tc-tp-specify-source-file-type else: lang_flag = _get_files.extensions_to_language_args[os.path.splitext(source_file)[1]] - # Insert at front of (non executable) args, because --language is only supposed to take effect on files listed thereafter - compile_action.arguments.insert(1, lang_flag) + if lang_flag: + # Insert at front of (non executable) args, because --language is only supposed to take effect on files listed thereafter + compile_action.arguments.insert(1, lang_flag) return {source_file}, header_files _get_files.has_logged_missing_file_error = False