python/mozbuild/mozbuild/repackage.py
author Mike Shal <mshal@mozilla.com>
Fri, 10 Mar 2017 18:36:23 -0500
branchSEAMONKEY_2_49_ESR_RELBRANCH
changeset 357564 2829cd1b5e25e13c2aaafd935bfcdf9649b66ad8
permissions -rw-r--r--
Bug 1347576 - Add a 'mach repackage' command, with OSX dmg support; r=chmanchester a=IanN DONTBUILD CLOSED TREE SeaMonkey ESR52 release branch only. This is the initial support of 'mach repackage', which can take an existing tarball and create a DMG on either an OSX host or on a Linux host with cross-OSX tools. Configure is needed in order to find the tools necessary to create the DMG. On a Linux cross-compiled environment with tooltool, this can be as simple as: export MKFSHFS=$topsrcdir/hfsplus-tools/newfs_hfs export DMG_TOOL=$topsrcdir/dmg/dmg export HFS_TOOL=$topsrcdir/dmg/hfsplus ac_add_options --disable-compile-environment MozReview-Commit-ID: 6t2rlXpwUvu

# 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 os
import tempfile
import tarfile
import shutil
import ConfigParser
import mozpack.path as mozpath
from mozpack.dmg import create_dmg

def repackage_dmg(infile, output):

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

    tmpdir = tempfile.mkdtemp()
    try:
        with tarfile.open(infile) as tar:
            tar.extractall(path=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.
        try:
            os.remove(mozpath.join(tmpdir, ' '))
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise

        # Grab the volume name
        volume_name = None
        for root, dirs, files in os.walk(tmpdir):
            if 'application.ini' in files:
                parser = ConfigParser.ConfigParser()
                parser.read(mozpath.join(root, 'application.ini'))
                volume_name = parser.get('App', 'CodeName')
                break

        if volume_name is None:
            raise Exception("Input package does not contain an application.ini file")

        # 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(tmpdir, output, volume_name, [])

    finally:
        shutil.rmtree(tmpdir)