def check_all_compressions(extension, default_mime):
     output_file = self.workspace_folder / ("myPackage" + extension)
     for compression, mime in (("-z", "gzip"), ("-j", "x-bzip2"),
                               ("-J", "x-xz"), ("-a", default_mime)):
         self.leaf_exec(("build", "pack"), "--output", output_file,
                        "--input", folder, "--", compression, ".")
         check_mime(output_file, mime)
 def check_all_compressions(extension, mime):
     output_file = self.workspace_folder / ("myPackage" + extension)
     for args, mime in ((None, "x-tar"), (("."), "x-tar"),
                        (("-z", "."), "gzip"), (("-j", "."), "x-bzip2"),
                        (("-J", "."), "x-xz"), (("-a", "."), mime)):
         self.rm.create_package(folder,
                                output_file,
                                tar_extra_args=args)
         check_mime(output_file, mime)
    def test_reproductible_build(self):
        # Build some packages
        pis = "install_1.0"
        folder = TEST_REMOTE_PACKAGE_SOURCE / pis
        manifest = folder / LeafFiles.MANIFEST
        self.assertTrue(manifest.exists())

        def touch_manifest():
            time.sleep(1)
            os.utime(str(manifest), None)

        def build_package(output, args):
            self.leaf_exec(("build", "pack"), "-i", folder, "-o", output,
                           "--no-info", "--", *args)

        for extension, arg, mime in (("tar", "-v", "x-tar"),
                                     ("bz2", "-j", "x-bzip2"), ("xz", "-J",
                                                                "x-xz")):
            output1 = self.workspace_folder / "{pis}.{ext}.{item}".format(
                pis=pis, ext=extension, item=1)
            output2 = self.workspace_folder / "{pis}.{ext}.{item}".format(
                pis=pis, ext=extension, item=2)
            output3 = self.workspace_folder / "{pis}.{ext}.{item}".format(
                pis=pis, ext=extension, item=3)
            output4 = self.workspace_folder / "{pis}.{ext}.{item}".format(
                pis=pis, ext=extension, item=4)

            build_package(output1, (arg, "."))
            touch_manifest()
            build_package(output2, (arg, "."))
            touch_manifest()
            build_package(
                output3,
                ("--mtime=2018-11-01 00:00:00", "--sort=name", "--owner=0",
                 "--group=0", "--numeric-owner", arg, "."))
            touch_manifest()
            build_package(
                output4,
                ("--mtime=2018-11-01 00:00:00", "--sort=name", "--owner=0",
                 "--group=0", "--numeric-owner", arg, "."))

            check_mime(output1, mime)
            check_mime(output2, mime)
            check_mime(output3, mime)
            check_mime(output4, mime)

            self.assertNotEqual(hash_compute(output1), hash_compute(output2))
            self.assertNotEqual(hash_compute(output1), hash_compute(output3))
            self.assertNotEqual(hash_compute(output2), hash_compute(output3))
            self.assertEqual(hash_compute(output3), hash_compute(output4))