Bug 1799042 - part 5: Support chroot path when using debian arch "all" r=gabriel
Depends on D171121 Differential Revision: https://phabricator.services.mozilla.com/D171122
This commit is contained in:
@@ -31,6 +31,7 @@ class NoDebPackageFound(Exception):
|
||||
|
||||
|
||||
_DEB_ARCH = {
|
||||
"all": "all",
|
||||
"x86": "i386",
|
||||
"x86_64": "amd64",
|
||||
}
|
||||
@@ -48,13 +49,7 @@ def repackage_deb(infile, output, template_dir, arch, version, build_number):
|
||||
if not tarfile.is_tarfile(infile):
|
||||
raise Exception("Input file %s is not a valid tarfile." % infile)
|
||||
|
||||
deb_arch = _DEB_ARCH[arch]
|
||||
|
||||
if _is_chroot_available(arch):
|
||||
tmpdir = tempfile.mkdtemp(dir=f"/srv/{_DEB_DIST}-{deb_arch}/tmp")
|
||||
else:
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
|
||||
tmpdir = _create_temporary_directory(arch)
|
||||
source_dir = os.path.join(tmpdir, "source")
|
||||
try:
|
||||
mozfile.extract_tarball(infile, source_dir)
|
||||
@@ -237,14 +232,16 @@ def _get_command(arch):
|
||||
"-us", # --unsigned-source
|
||||
"-uc", # --unsigned-changes
|
||||
"-b", # --build=binary
|
||||
f"--host-arch={deb_arch}",
|
||||
]
|
||||
|
||||
if deb_arch != "all":
|
||||
command.append(f"--host-arch={deb_arch}")
|
||||
|
||||
if _is_chroot_available(arch):
|
||||
flattened_command = " ".join(command)
|
||||
command = [
|
||||
"chroot",
|
||||
f"/srv/{_DEB_DIST}-{deb_arch}",
|
||||
_get_chroot_path(arch),
|
||||
"bash",
|
||||
"-c",
|
||||
f"cd /tmp/*/source; {flattened_command}",
|
||||
@@ -253,9 +250,20 @@ def _get_command(arch):
|
||||
return command
|
||||
|
||||
|
||||
def _create_temporary_directory(arch):
|
||||
if _is_chroot_available(arch):
|
||||
return tempfile.mkdtemp(dir=f"{_get_chroot_path(arch)}/tmp")
|
||||
else:
|
||||
return tempfile.mkdtemp()
|
||||
|
||||
|
||||
def _is_chroot_available(arch):
|
||||
deb_arch = _DEB_ARCH[arch]
|
||||
return os.path.isdir(f"/srv/{_DEB_DIST}-{deb_arch}")
|
||||
return os.path.isdir(_get_chroot_path(arch))
|
||||
|
||||
|
||||
def _get_chroot_path(arch):
|
||||
deb_arch = "amd64" if arch == "all" else _DEB_ARCH[arch]
|
||||
return f"/srv/{_DEB_DIST}-{deb_arch}"
|
||||
|
||||
|
||||
_MANIFEST_FILE_NAME = "manifest.json"
|
||||
|
||||
@@ -212,6 +212,18 @@ def test_generate_deb_archive(
|
||||
@pytest.mark.parametrize(
|
||||
"arch, is_chroot_available, expected",
|
||||
(
|
||||
(
|
||||
"all",
|
||||
True,
|
||||
[
|
||||
"chroot",
|
||||
"/srv/jessie-amd64",
|
||||
"bash",
|
||||
"-c",
|
||||
"cd /tmp/*/source; dpkg-buildpackage -us -uc -b",
|
||||
],
|
||||
),
|
||||
("all", False, ["dpkg-buildpackage", "-us", "-uc", "-b"]),
|
||||
(
|
||||
"x86",
|
||||
True,
|
||||
@@ -250,6 +262,8 @@ def test_get_command(monkeypatch, arch, is_chroot_available, expected):
|
||||
@pytest.mark.parametrize(
|
||||
"arch, does_dir_exist, expected_path, expected_result",
|
||||
(
|
||||
("all", False, "/srv/jessie-amd64", False),
|
||||
("all", True, "/srv/jessie-amd64", True),
|
||||
("x86", False, "/srv/jessie-i386", False),
|
||||
("x86_64", False, "/srv/jessie-amd64", False),
|
||||
("x86", True, "/srv/jessie-i386", True),
|
||||
@@ -267,6 +281,18 @@ def test_is_chroot_available(
|
||||
assert deb._is_chroot_available(arch) == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"arch, expected",
|
||||
(
|
||||
("all", "/srv/jessie-amd64"),
|
||||
("x86", "/srv/jessie-i386"),
|
||||
("x86_64", "/srv/jessie-amd64"),
|
||||
),
|
||||
)
|
||||
def test_get_chroot_path(arch, expected):
|
||||
assert deb._get_chroot_path(arch) == expected
|
||||
|
||||
|
||||
_MANIFEST_JSON_DATA = {
|
||||
"langpack_id": "fr",
|
||||
"manifest_version": 2,
|
||||
|
||||
Reference in New Issue
Block a user