Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #1034: Always rebuild at the second time #1039

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -659,7 +659,7 @@
verify_suppress = config.get_item('cc_config', 'hdr_dep_missing_suppress')
declared_hdrs, declared_incs = self._collect_declared_headers()
declared_genhdrs, declared_genincs = _transitive_declared_generated_includes(self)
direct_hdrs, generated_hdrs = self._collect_compiler_reported_hdrs(filename + '.details')

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'direct_hdrs' is unnecessary as it is
redefined
before this value is used.

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'generated_hdrs' is unnecessary as it is
redefined
before this value is used.

target_check_info = {
'type': self.type,
Expand All @@ -676,9 +676,6 @@
'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 @@
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()