diff options
Diffstat (limited to 'zephyr/zmake/zmake/zmake.py')
-rw-r--r-- | zephyr/zmake/zmake/zmake.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py index b7a81a3b9b..f81f157054 100644 --- a/zephyr/zmake/zmake/zmake.py +++ b/zephyr/zmake/zmake/zmake.py @@ -3,6 +3,7 @@ # found in the LICENSE file. """Module encapsulating Zmake wrapper object.""" +import atexit import difflib import functools import logging @@ -11,9 +12,11 @@ import pathlib import re import shutil import subprocess +import tempfile from typing import Dict, Optional, Set, Union import zmake.build_config +import zmake.compare_builds import zmake.generate_readme import zmake.jobserver import zmake.modules @@ -323,6 +326,83 @@ class Zmake: save_temps=save_temps, ) + def compare_builds( + self, + ref1, + ref2, + project_names, + toolchain=None, + all_projects=False, + extra_cflags=None, + keep_temps=False, + ): + """Compare EC builds at two commits.""" + temp_dir = tempfile.mkdtemp(prefix="zcompare-") + if not keep_temps: + atexit.register(shutil.rmtree, temp_dir) + else: + self.logger.info("Temporary dir %s will be retained", temp_dir) + + projects = self._resolve_projects( + project_names, + all_projects=all_projects, + ) + + self.logger.info("Compare zephyr builds") + + cmp_builds = zmake.compare_builds.CompareBuilds(temp_dir, ref1, ref2) + + for checkout in cmp_builds.checkouts: + self.logger.info( + "Checkout %s: full hash %s", checkout.ref, checkout.full_ref + ) + + cmp_builds.do_checkouts(self.zephyr_base, self.module_paths) + + for checkout in cmp_builds.checkouts: + # Now that the sources have been checked out, transform the + # zephyr-base and module-paths to use the temporary directory + # created by BuildInfo. + for module_name in self.module_paths.keys(): + new_path = checkout.modules_dir / module_name + transformed_module = {module_name: new_path} + self.module_paths.update(transformed_module) + + self.zephyr_base = checkout.zephyr_dir + + self.logger.info("Building projects at %s", checkout.ref) + result = self.configure( + project_names, + build_dir=None, + toolchain=toolchain, + clobber=False, + bringup=False, + coverage=False, + allow_warnings=False, + all_projects=all_projects, + extra_cflags=extra_cflags, + build_after_configure=True, + delete_intermediates=False, + static_version=True, + save_temps=False, + ) + + if result: + self.logger.error( + "compare-builds failed to build all projects at %s", + checkout.ref, + ) + return result + + self.failed_projects = cmp_builds.check_binaries(projects) + + if len(self.failed_projects) == 0: + self.logger.info("Zephyr compare builds successful:") + for checkout in cmp_builds.checkouts: + self.logger.info(" %s: %s", checkout.ref, checkout.full_ref) + + return len(self.failed_projects) + def test( # pylint: disable=unused-argument self, project_names, |