From 64968d636abd10a664aa98e80c4b8bafc6810e31 Mon Sep 17 00:00:00 2001 From: CHEN Feng Date: Thu, 23 May 2024 09:31:33 +0800 Subject: [PATCH] Fix bug #1034: Always rebuild at the second time (#1039) * Fix bug #1034: Always rebuild at the second time --- .gitattributes | 7 +++++++ src/blade/cc_targets.py | 23 ++++++++++++++++++++--- src/blade/inclusion_check.py | 5 +++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..d5061173 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/src/blade/cc_targets.py b/src/blade/cc_targets.py index a3ebc71f..b25c5b5b 100644 --- a/src/blade/cc_targets.py +++ b/src/blade/cc_targets.py @@ -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, {}), } @@ -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: diff --git a/src/blade/inclusion_check.py b/src/blade/inclusion_check.py index 4ba7caa1..fc2ec2fd 100644 --- a/src/blade/inclusion_check.py +++ b/src/blade/inclusion_check.py @@ -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()