summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/repackaging/dmg.py
blob: 883927f214d85a0d8778f3a7cd0e6618fa3c8ded (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import tarfile
from pathlib import Path

import mozfile
from mozpack.dmg import create_dmg

from mozbuild.bootstrap import bootstrap_toolchain
from mozbuild.repackaging.application_ini import get_application_ini_value


def repackage_dmg(infile, output):

    if not tarfile.is_tarfile(infile):
        raise Exception("Input file %s is not a valid tarfile." % infile)

    # Resolve required tools
    dmg_tool = bootstrap_toolchain("dmg/dmg")
    if not dmg_tool:
        raise Exception("DMG tool not found")
    hfs_tool = bootstrap_toolchain("dmg/hfsplus")
    if not hfs_tool:
        raise Exception("HFS tool not found")
    mkfshfs_tool = bootstrap_toolchain("hfsplus/newfs_hfs")
    if not mkfshfs_tool:
        raise Exception("MKFSHFS tool not found")

    with mozfile.TemporaryDirectory() as tmp:
        tmpdir = Path(tmp)
        mozfile.extract_tarball(infile, tmpdir)

        # Remove the /Applications symlink. If we don't, an rsync command in
        # create_dmg() will break, and create_dmg() re-creates the symlink anyway.
        symlink = tmpdir / " "
        if symlink.is_file():
            symlink.unlink()

        volume_name = get_application_ini_value(
            str(tmpdir), "App", "CodeName", fallback="Name"
        )

        # The extra_files argument is empty [] because they are already a part
        # of the original dmg produced by the build, and they remain in the
        # tarball generated by the signing task.
        create_dmg(
            source_directory=tmpdir,
            output_dmg=Path(output),
            volume_name=volume_name,
            extra_files=[],
            dmg_tool=Path(dmg_tool),
            hfs_tool=Path(hfs_tool),
            mkfshfs_tool=Path(mkfshfs_tool),
        )