Skip to content

Commit b042f0d

Browse files
committed
Add _warn_if_file_doesnt_exist for reminding missing files
1 parent c7c7992 commit b042f0d

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

Diff for: refresh.template.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ def _print_header_finding_warning_once():
9494
_print_header_finding_warning_once.has_logged = False
9595

9696

97+
def _warn_if_file_doesnt_exist(source_file):
98+
if not os.path.isfile(source_file):
99+
if not _warn_if_file_doesnt_exist.has_logged_missing_file_error: # Just log once; subsequent messages wouldn't add anything.
100+
_warn_if_file_doesnt_exist.has_logged_missing_file_error = True
101+
log_warning(f""">>> A source file you compile doesn't (yet) exist: {source_file}
102+
It's probably a generated file, and you haven't yet run a build to generate it.
103+
That's OK; your code doesn't even have to compile for this tool to work.
104+
If you can, though, you might want to run a build of your code.
105+
That way everything is generated, browsable and indexed for autocomplete.
106+
However, if you have *already* built your code, and generated the missing file...
107+
Please make sure you're supplying this tool with the same flags you use to build.
108+
You can either use a refresh_compile_commands rule or the special -- syntax. Please see the README.
109+
[Supplying flags normally won't work. That just causes this tool to be built with those flags.]
110+
Continuing gracefully...""")
111+
return True
112+
return False
113+
_warn_if_file_doesnt_exist.has_logged_missing_file_error = False
114+
115+
97116
@functools.lru_cache(maxsize=None)
98117
def _get_bazel_cached_action_keys():
99118
"""Gets the set of actionKeys cached in bazel-out."""
@@ -556,6 +575,9 @@ def _get_files(compile_action):
556575
# If we've got swift action just return sources
557576
if compile_action.mnemonic == 'SwiftCompile':
558577
source_files = set(filter(lambda arg: arg.endswith(_get_files.swift_source_extension), compile_action.arguments))
578+
for source_file in source_files:
579+
_warn_if_file_doesnt_exist(source_file)
580+
559581
return source_files, set()
560582

561583
# Getting the source file is a little trickier than it might seem.
@@ -593,19 +615,7 @@ def _get_files(compile_action):
593615
assert source_file.endswith(_get_files.c_family_source_extensions), f"Source file candidate, {source_file}, seems to be wrong.\nSelected from {compile_action.arguments}.\nPlease file an issue with this information!"
594616

595617
# Warn gently about missing files
596-
if not os.path.isfile(source_file):
597-
if not _get_files.has_logged_missing_file_error: # Just log once; subsequent messages wouldn't add anything.
598-
_get_files.has_logged_missing_file_error = True
599-
log_warning(f""">>> A source file you compile doesn't (yet) exist: {source_file}
600-
It's probably a generated file, and you haven't yet run a build to generate it.
601-
That's OK; your code doesn't even have to compile for this tool to work.
602-
If you can, though, you might want to run a build of your code.
603-
That way everything is generated, browsable and indexed for autocomplete.
604-
However, if you have *already* built your code, and generated the missing file...
605-
Please make sure you're supplying this tool with the same flags you use to build.
606-
You can either use a refresh_compile_commands rule or the special -- syntax. Please see the README.
607-
[Supplying flags normally won't work. That just causes this tool to be built with those flags.]
608-
Continuing gracefully...""")
618+
if _warn_if_file_doesnt_exist(source_file):
609619
return {source_file}, set()
610620

611621
# Note: We need to apply commands to headers and sources.

0 commit comments

Comments
 (0)