Skip to content

Commit

Permalink
Add _warn_if_file_doesnt_exist for reminding missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
xinzhengzhang committed Dec 23, 2022
1 parent c7c7992 commit b042f0d
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions refresh.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ def _print_header_finding_warning_once():
_print_header_finding_warning_once.has_logged = False


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


@functools.lru_cache(maxsize=None)
def _get_bazel_cached_action_keys():
"""Gets the set of actionKeys cached in bazel-out."""
Expand Down Expand Up @@ -556,6 +575,9 @@ def _get_files(compile_action):
# If we've got swift action just return sources
if compile_action.mnemonic == 'SwiftCompile':
source_files = set(filter(lambda arg: arg.endswith(_get_files.swift_source_extension), compile_action.arguments))
for source_file in source_files:
_warn_if_file_doesnt_exist(source_file)

return source_files, set()

# Getting the source file is a little trickier than it might seem.
Expand Down Expand Up @@ -593,19 +615,7 @@ def _get_files(compile_action):
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!"

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

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

0 comments on commit b042f0d

Please sign in to comment.