Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 4 | # Copyright 2019-2020 by Garmin Ltd. or its subsidiaries |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 5 | |
| 6 | from oeqa.selftest.case import OESelftestTestCase |
| 7 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 8 | import bb.utils |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 9 | import functools |
| 10 | import multiprocessing |
| 11 | import textwrap |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 12 | import json |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 13 | import unittest |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 14 | import tempfile |
| 15 | import shutil |
| 16 | import stat |
| 17 | import os |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 18 | import datetime |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 19 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 20 | # For sample packages, see: |
| 21 | # https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20201127-0t7wr_oo/ |
| 22 | # https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20201127-4s9ejwyp/ |
| 23 | # https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20201127-haiwdlbr/ |
| 24 | # https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20201127-hwds3mcl/ |
| 25 | # https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20201203-sua0pzvc/ |
| 26 | # (both packages/ and packages-excluded/) |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 27 | |
| 28 | # ruby-ri-docs, meson: |
| 29 | #https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20210215-0_td9la2/packages/diff-html/ |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame^] | 30 | # rust-llvm: |
| 31 | #https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20210825-kaihham6/ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 32 | exclude_packages = [ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 33 | 'glide', |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 34 | 'go-helloworld', |
| 35 | 'go-runtime', |
| 36 | 'go_', |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 37 | 'go-', |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame^] | 38 | 'ruby-ri-docs', |
| 39 | 'rust-llvm-liblto', |
| 40 | 'rust-llvm-staticdev' |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 41 | ] |
| 42 | |
| 43 | def is_excluded(package): |
| 44 | package_name = os.path.basename(package) |
| 45 | for i in exclude_packages: |
| 46 | if package_name.startswith(i): |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 47 | return i |
| 48 | return None |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 49 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 50 | MISSING = 'MISSING' |
| 51 | DIFFERENT = 'DIFFERENT' |
| 52 | SAME = 'SAME' |
| 53 | |
| 54 | @functools.total_ordering |
| 55 | class CompareResult(object): |
| 56 | def __init__(self): |
| 57 | self.reference = None |
| 58 | self.test = None |
| 59 | self.status = 'UNKNOWN' |
| 60 | |
| 61 | def __eq__(self, other): |
| 62 | return (self.status, self.test) == (other.status, other.test) |
| 63 | |
| 64 | def __lt__(self, other): |
| 65 | return (self.status, self.test) < (other.status, other.test) |
| 66 | |
| 67 | class PackageCompareResults(object): |
| 68 | def __init__(self): |
| 69 | self.total = [] |
| 70 | self.missing = [] |
| 71 | self.different = [] |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 72 | self.different_excluded = [] |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 73 | self.same = [] |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 74 | self.active_exclusions = set() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 75 | |
| 76 | def add_result(self, r): |
| 77 | self.total.append(r) |
| 78 | if r.status == MISSING: |
| 79 | self.missing.append(r) |
| 80 | elif r.status == DIFFERENT: |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 81 | exclusion = is_excluded(r.reference) |
| 82 | if exclusion: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 83 | self.different_excluded.append(r) |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 84 | self.active_exclusions.add(exclusion) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 85 | else: |
| 86 | self.different.append(r) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 87 | else: |
| 88 | self.same.append(r) |
| 89 | |
| 90 | def sort(self): |
| 91 | self.total.sort() |
| 92 | self.missing.sort() |
| 93 | self.different.sort() |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 94 | self.different_excluded.sort() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 95 | self.same.sort() |
| 96 | |
| 97 | def __str__(self): |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 98 | return 'same=%i different=%i different_excluded=%i missing=%i total=%i\nunused_exclusions=%s' % (len(self.same), len(self.different), len(self.different_excluded), len(self.missing), len(self.total), self.unused_exclusions()) |
| 99 | |
| 100 | def unused_exclusions(self): |
| 101 | return sorted(set(exclude_packages) - self.active_exclusions) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 102 | |
| 103 | def compare_file(reference, test, diffutils_sysroot): |
| 104 | result = CompareResult() |
| 105 | result.reference = reference |
| 106 | result.test = test |
| 107 | |
| 108 | if not os.path.exists(reference): |
| 109 | result.status = MISSING |
| 110 | return result |
| 111 | |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 112 | r = runCmd(['cmp', '--quiet', reference, test], native_sysroot=diffutils_sysroot, ignore_status=True, sync=False) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 113 | |
| 114 | if r.status: |
| 115 | result.status = DIFFERENT |
| 116 | return result |
| 117 | |
| 118 | result.status = SAME |
| 119 | return result |
| 120 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 121 | def run_diffoscope(a_dir, b_dir, html_dir, **kwargs): |
| 122 | return runCmd(['diffoscope', '--no-default-limits', '--exclude-directory-metadata', 'yes', '--html-dir', html_dir, a_dir, b_dir], |
| 123 | **kwargs) |
| 124 | |
| 125 | class DiffoscopeTests(OESelftestTestCase): |
| 126 | diffoscope_test_files = os.path.join(os.path.dirname(os.path.abspath(__file__)), "diffoscope") |
| 127 | |
| 128 | def test_diffoscope(self): |
| 129 | bitbake("diffoscope-native -c addto_recipe_sysroot") |
| 130 | diffoscope_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "diffoscope-native") |
| 131 | |
| 132 | # Check that diffoscope doesn't return an error when the files compare |
| 133 | # the same (a general check that diffoscope is working) |
| 134 | with tempfile.TemporaryDirectory() as tmpdir: |
| 135 | run_diffoscope('A', 'A', tmpdir, |
| 136 | native_sysroot=diffoscope_sysroot, cwd=self.diffoscope_test_files) |
| 137 | |
| 138 | # Check that diffoscope generates an index.html file when the files are |
| 139 | # different |
| 140 | with tempfile.TemporaryDirectory() as tmpdir: |
| 141 | r = run_diffoscope('A', 'B', tmpdir, |
| 142 | native_sysroot=diffoscope_sysroot, ignore_status=True, cwd=self.diffoscope_test_files) |
| 143 | |
| 144 | self.assertNotEqual(r.status, 0, msg="diffoscope was successful when an error was expected") |
| 145 | self.assertTrue(os.path.exists(os.path.join(tmpdir, 'index.html')), "HTML index not found!") |
| 146 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 147 | class ReproducibleTests(OESelftestTestCase): |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 148 | # Test the reproducibility of whatever is built between sstate_targets and targets |
| 149 | |
| 150 | package_classes = ['deb', 'ipk', 'rpm'] |
| 151 | |
| 152 | # targets are the things we want to test the reproducibility of |
| 153 | targets = ['core-image-minimal', 'core-image-sato', 'core-image-full-cmdline', 'core-image-weston', 'world'] |
| 154 | # sstate targets are things to pull from sstate to potentially cut build/debugging time |
| 155 | sstate_targets = [] |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 156 | save_results = False |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 157 | if 'OEQA_DEBUGGING_SAVED_OUTPUT' in os.environ: |
| 158 | save_results = os.environ['OEQA_DEBUGGING_SAVED_OUTPUT'] |
| 159 | |
| 160 | # This variable controls if one of the test builds is allowed to pull from |
| 161 | # an sstate cache/mirror. The other build is always done clean as a point of |
| 162 | # comparison. |
| 163 | # If you know that your sstate archives are reproducible, enabling this |
| 164 | # will test that and also make the test run faster. If your sstate is not |
| 165 | # reproducible, disable this in your derived test class |
| 166 | build_from_sstate = True |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 167 | |
| 168 | def setUpLocal(self): |
| 169 | super().setUpLocal() |
| 170 | needed_vars = ['TOPDIR', 'TARGET_PREFIX', 'BB_NUMBER_THREADS'] |
| 171 | bb_vars = get_bb_vars(needed_vars) |
| 172 | for v in needed_vars: |
| 173 | setattr(self, v.lower(), bb_vars[v]) |
| 174 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 175 | self.extraresults = {} |
| 176 | self.extraresults.setdefault('reproducible.rawlogs', {})['log'] = '' |
| 177 | self.extraresults.setdefault('reproducible', {}).setdefault('files', {}) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 178 | |
| 179 | def append_to_log(self, msg): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 180 | self.extraresults['reproducible.rawlogs']['log'] += msg |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 181 | |
| 182 | def compare_packages(self, reference_dir, test_dir, diffutils_sysroot): |
| 183 | result = PackageCompareResults() |
| 184 | |
| 185 | old_cwd = os.getcwd() |
| 186 | try: |
| 187 | file_result = {} |
| 188 | os.chdir(test_dir) |
| 189 | with multiprocessing.Pool(processes=int(self.bb_number_threads or 0)) as p: |
| 190 | for root, dirs, files in os.walk('.'): |
| 191 | async_result = [] |
| 192 | for f in files: |
| 193 | reference_path = os.path.join(reference_dir, root, f) |
| 194 | test_path = os.path.join(test_dir, root, f) |
| 195 | async_result.append(p.apply_async(compare_file, (reference_path, test_path, diffutils_sysroot))) |
| 196 | |
| 197 | for a in async_result: |
| 198 | result.add_result(a.get()) |
| 199 | |
| 200 | finally: |
| 201 | os.chdir(old_cwd) |
| 202 | |
| 203 | result.sort() |
| 204 | return result |
| 205 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 206 | def write_package_list(self, package_class, name, packages): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 207 | self.extraresults['reproducible']['files'].setdefault(package_class, {})[name] = [ |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 208 | {'reference': p.reference, 'test': p.test} for p in packages] |
| 209 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 210 | def copy_file(self, source, dest): |
| 211 | bb.utils.mkdirhier(os.path.dirname(dest)) |
| 212 | shutil.copyfile(source, dest) |
| 213 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 214 | def do_test_build(self, name, use_sstate): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 215 | capture_vars = ['DEPLOY_DIR_' + c.upper() for c in self.package_classes] |
| 216 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 217 | tmpdir = os.path.join(self.topdir, name, 'tmp') |
| 218 | if os.path.exists(tmpdir): |
| 219 | bb.utils.remove(tmpdir, recurse=True) |
| 220 | |
| 221 | config = textwrap.dedent('''\ |
| 222 | INHERIT += "reproducible_build" |
| 223 | PACKAGE_CLASSES = "{package_classes}" |
| 224 | INHIBIT_PACKAGE_STRIP = "1" |
| 225 | TMPDIR = "{tmpdir}" |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 226 | LICENSE_FLAGS_WHITELIST = "commercial" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 227 | DISTRO_FEATURES:append = ' systemd pam' |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 228 | USERADDEXTENSION = "useradd-staticids" |
| 229 | USERADD_ERROR_DYNAMIC = "skip" |
| 230 | USERADD_UID_TABLES += "files/static-passwd" |
| 231 | USERADD_GID_TABLES += "files/static-group" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 232 | ''').format(package_classes=' '.join('package_%s' % c for c in self.package_classes), |
| 233 | tmpdir=tmpdir) |
| 234 | |
| 235 | if not use_sstate: |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 236 | if self.sstate_targets: |
| 237 | self.logger.info("Building prebuild for %s (sstate allowed)..." % (name)) |
| 238 | self.write_config(config) |
| 239 | bitbake(' '.join(self.sstate_targets)) |
| 240 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 241 | # This config fragment will disable using shared and the sstate |
| 242 | # mirror, forcing a complete build from scratch |
| 243 | config += textwrap.dedent('''\ |
| 244 | SSTATE_DIR = "${TMPDIR}/sstate" |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 245 | SSTATE_MIRRORS = "" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 246 | ''') |
| 247 | |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 248 | self.logger.info("Building %s (sstate%s allowed)..." % (name, '' if use_sstate else ' NOT')) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 249 | self.write_config(config) |
| 250 | d = get_bb_vars(capture_vars) |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 251 | # targets used to be called images |
| 252 | bitbake(' '.join(getattr(self, 'images', self.targets))) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 253 | return d |
| 254 | |
| 255 | def test_reproducible_builds(self): |
| 256 | def strip_topdir(s): |
| 257 | if s.startswith(self.topdir): |
| 258 | return s[len(self.topdir):] |
| 259 | return s |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 260 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 261 | # Build native utilities |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 262 | self.write_config('') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 263 | bitbake("diffoscope-native diffutils-native jquery-native -c addto_recipe_sysroot") |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 264 | diffutils_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "diffutils-native") |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 265 | diffoscope_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "diffoscope-native") |
| 266 | jquery_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "jquery-native") |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 267 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 268 | if self.save_results: |
| 269 | os.makedirs(self.save_results, exist_ok=True) |
| 270 | datestr = datetime.datetime.now().strftime('%Y%m%d') |
| 271 | save_dir = tempfile.mkdtemp(prefix='oe-reproducible-%s-' % datestr, dir=self.save_results) |
| 272 | os.chmod(save_dir, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) |
| 273 | self.logger.info('Non-reproducible packages will be copied to %s', save_dir) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 274 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 275 | vars_A = self.do_test_build('reproducibleA', self.build_from_sstate) |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 276 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 277 | vars_B = self.do_test_build('reproducibleB', False) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 278 | |
| 279 | # NOTE: The temp directories from the reproducible build are purposely |
| 280 | # kept after the build so it can be diffed for debugging. |
| 281 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 282 | fails = [] |
| 283 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 284 | for c in self.package_classes: |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 285 | with self.subTest(package_class=c): |
| 286 | package_class = 'package_' + c |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 287 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 288 | deploy_A = vars_A['DEPLOY_DIR_' + c.upper()] |
| 289 | deploy_B = vars_B['DEPLOY_DIR_' + c.upper()] |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 290 | |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 291 | self.logger.info('Checking %s packages for differences...' % c) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 292 | result = self.compare_packages(deploy_A, deploy_B, diffutils_sysroot) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 293 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 294 | self.logger.info('Reproducibility summary for %s: %s' % (c, result)) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 295 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 296 | self.append_to_log('\n'.join("%s: %s" % (r.status, r.test) for r in result.total)) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 297 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 298 | self.write_package_list(package_class, 'missing', result.missing) |
| 299 | self.write_package_list(package_class, 'different', result.different) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 300 | self.write_package_list(package_class, 'different_excluded', result.different_excluded) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 301 | self.write_package_list(package_class, 'same', result.same) |
| 302 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 303 | if self.save_results: |
| 304 | for d in result.different: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 305 | self.copy_file(d.reference, '/'.join([save_dir, 'packages', strip_topdir(d.reference)])) |
| 306 | self.copy_file(d.test, '/'.join([save_dir, 'packages', strip_topdir(d.test)])) |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 307 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 308 | for d in result.different_excluded: |
| 309 | self.copy_file(d.reference, '/'.join([save_dir, 'packages-excluded', strip_topdir(d.reference)])) |
| 310 | self.copy_file(d.test, '/'.join([save_dir, 'packages-excluded', strip_topdir(d.test)])) |
| 311 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 312 | if result.missing or result.different: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 313 | fails.append("The following %s packages are missing or different and not in exclusion list: %s" % |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 314 | (c, '\n'.join(r.test for r in (result.missing + result.different)))) |
| 315 | |
| 316 | # Clean up empty directories |
| 317 | if self.save_results: |
| 318 | if not os.listdir(save_dir): |
| 319 | os.rmdir(save_dir) |
| 320 | else: |
| 321 | self.logger.info('Running diffoscope') |
| 322 | package_dir = os.path.join(save_dir, 'packages') |
| 323 | package_html_dir = os.path.join(package_dir, 'diff-html') |
| 324 | |
| 325 | # Copy jquery to improve the diffoscope output usability |
| 326 | self.copy_file(os.path.join(jquery_sysroot, 'usr/share/javascript/jquery/jquery.min.js'), os.path.join(package_html_dir, 'jquery.js')) |
| 327 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 328 | run_diffoscope('reproducibleA', 'reproducibleB', package_html_dir, |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 329 | native_sysroot=diffoscope_sysroot, ignore_status=True, cwd=package_dir) |
| 330 | |
| 331 | if fails: |
| 332 | self.fail('\n'.join(fails)) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 333 | |