author Robert Strong <>
Mon, 31 Jul 2017 10:34:22 -0700
changeset 420672 f632eede0f19b8d81ee2bb0de48c2cc996d5906f
parent 415106 f98b5c33cecccc780ed8743f1ea3125105cbed0a
child 420976 c495c07bdff0c61886dde928f48f9e2060fe2462
child 489082 c832e6e8714145a51619fbcbdd562422c931e59f
permissions -rw-r--r--
Bug 1385780 - Update mar file generation scripts for lzma. r=bhearsum, r=rail, a=app_update_lzma Update scripts to support both lzma and bzip2 Update unused python script to support lzma. This also adds python 3.0 support to the script while still supporting pythin 2.7 Update test scripts to support lzma

# 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

import os
import sys
import tempfile
import shutil
import zipfile
import tarfile
import subprocess
import mozpack.path as mozpath
from application_ini import get_application_ini_value
from mozbuild.util import ensureParentDir

def repackage_mar(topsrcdir, package, mar, output):
    if not zipfile.is_zipfile(package) and not tarfile.is_tarfile(package):
        raise Exception("Package file %s is not a valid .zip or .tar file." % package)

    tmpdir = tempfile.mkdtemp()
        if zipfile.is_zipfile(package):
            z = zipfile.ZipFile(package)
            filelist = z.namelist()
            z =
            filelist = z.getnames()

        toplevel_dirs = set([mozpath.split(f)[0] for f in filelist])
        excluded_stuff = set([' ', '.background', '.DS_Store', '.VolumeIcon.icns'])
        toplevel_dirs = toplevel_dirs - excluded_stuff
        # Make sure the .zip file just contains a directory like 'firefox/' at
        # the top, and find out what it is called.
        if len(toplevel_dirs) != 1:
            raise Exception("Package file is expected to have a single top-level directory"
                            "(eg: 'firefox'), not: %s" % toplevel_dirs)
        ffxdir = mozpath.join(tmpdir, toplevel_dirs.pop())

        make_full_update = mozpath.join(topsrcdir, 'tools/update-packaging/')

        env = os.environ.copy()
        env['MOZ_FULL_PRODUCT_VERSION'] = get_application_ini_value(tmpdir, 'App', 'Version')
        env['MAR'] = mozpath.normpath(mar)
        # The Windows build systems have xz installed but it isn't in the path
        # like it is on Linux and Mac OS X so just use the XZ env var so the mar
        # generation scripts can find it.
        xz_path = mozpath.join(topsrcdir, 'xz/xz.exe')
        if os.path.exists(xz_path):
            env['XZ'] = mozpath.normpath(xz_path)

        cmd = [make_full_update, output, ffxdir]
        if sys.platform == 'win32':
            # is a bash script, and Windows needs to
            # explicitly call out the shell to execute the script from Python.
            cmd.insert(0, env['MOZILLABUILD'] + '/msys/bin/bash.exe')
        subprocess.check_call(cmd, env=env)