Skip to content

Commit

Permalink
Fix bug #1034: Always rebuild at the second time (#1039)
Browse files Browse the repository at this point in the history
* Fix bug #1034: Always rebuild at the second time
  • Loading branch information
chen3feng authored May 23, 2024
1 parent f8461cf commit 64968d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Set line endings for batch files to CRLF (DOS format)
*.bat text eol=crlf

# Set line endings for shell scripts to LF (UNIX format)
*.sh text eol=lf
/blade eof=lf
/dist_blade eof=lf
23 changes: 20 additions & 3 deletions src/blade/cc_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,6 @@ def _write_inclusion_check_info(self):
'declared_incs': declared_incs,
'declared_genhdrs': declared_genhdrs,
'declared_genincs': declared_genincs,
'hdrs_deps': self._collect_hdrs_deps(direct_hdrs | generated_hdrs),
'private_hdrs_deps': self._collect_private_hdrs_deps(direct_hdrs),
'allowed_undeclared_hdrs': self._collect_allowed_undeclared_hdrs(direct_hdrs),
'severity': config.get_item('cc_config', 'hdr_dep_missing_severity'),
'suppress': verify_suppress.get(self.key, {}),
}
Expand All @@ -695,6 +692,26 @@ def _write_inclusion_check_info(self):
with open(filename, 'wb') as f:
f.write(content)

# Write volatile extra fields to a separate file to avoid unnecessary rebuild.
#
# This information is only available after the first build.
# Therefore, it is empty at the beginning, but is available before the second build.
# If it is written in the same file as the previous information, unnecessary repeated
# builds will be triggered.
# See https://github.com/chen3feng/blade-build/issues/1034
#
# This information is only a subset of the global file `inclusion_declaration.data` and is
# passed to the inclusion_check as an optimization to avoid reading the larger global file.
# So missing this information on the first check is not a problem.
direct_hdrs, generated_hdrs = self._collect_compiler_reported_hdrs(filename + '.details')
extra_target_check_info = {
'hdrs_deps': self._collect_hdrs_deps(direct_hdrs | generated_hdrs),
'private_hdrs_deps': self._collect_private_hdrs_deps(direct_hdrs),
'allowed_undeclared_hdrs': self._collect_allowed_undeclared_hdrs(direct_hdrs),
}
with open(filename + '.extra', 'wb') as f:
f.write(pickle.dumps(extra_target_check_info))

def _incchk_is_valid(self, filename, content, info):
"""Check whether the existing incchk file is still valid."""
with open(filename, 'rb') as f:
Expand Down
5 changes: 5 additions & 0 deletions src/blade/inclusion_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,5 +408,10 @@ def check_file(src, full_src, is_header):

def check(target_check_info_file):
target = pickle.load(open(target_check_info_file, 'rb'))
extra_file = target_check_info_file + '.extra'
if os.path.exists(extra_file):
with open(extra_file, 'rb') as f:
extra_target = pickle.load(f)
target.update(extra_target)
checker = Checker(target)
return checker.check()

0 comments on commit 64968d6

Please sign in to comment.