Bug 1360525 - Add 'mach repackage mar'; r?chmanchester draft
authorMike Shal <mshal@mozilla.com>
Thu, 04 May 2017 15:09:27 -0400
changeset 593490 5a70d34b310bfe986b0b56ca79583cf1802098a0
parent 593489 eb8f1bc347aca08e2820fa8c64f66e063b68bc2b
child 593491 314b6b3653f7b1bc4daf7b95b3c0e0c74ac9f2b4
push id63715
push userbmo:mshal@mozilla.com
push dateTue, 13 Jun 2017 18:44:17 +0000
reviewerschmanchester
bugs1360525
milestone55.0a1
Bug 1360525 - Add 'mach repackage mar'; r?chmanchester This adds a mach repackage command to create a complete mar file from an input package and mar host executable. The standard make_full_update.sh script actually does the work of creating the complete mar.
python/mozbuild/mozbuild/mach_commands.py
python/mozbuild/mozbuild/repackaging/mar.py
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -1972,8 +1972,20 @@ class Repackage(MachCommandBase):
         help='setup.exe file inside the installer')
     @CommandArgument('--package', type=str, required=False,
         help='Optional package .zip for building a full installer')
     @CommandArgument('--output', '-o', type=str, required=True,
         help='Output filename')
     def repackage_installer(self, tag, setupexe, package, output):
         from mozbuild.repackaging.installer import repackage_installer
         repackage_installer(self.topsrcdir, tag, setupexe, package, output)
+
+    @SubCommand('repackage', 'mar',
+                description='Repackage into complete MAR file')
+    @CommandArgument('--input', '-i', type=str, required=True,
+        help='Input filename')
+    @CommandArgument('--mar', type=str, required=True,
+        help='Mar binary path')
+    @CommandArgument('--output', '-o', type=str, required=True,
+        help='Output filename')
+    def repackage_mar(self, input, mar, output):
+        from mozbuild.repackaging.mar import repackage_mar
+        repackage_mar(self.topsrcdir, input, mar, output)
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/repackaging/mar.py
@@ -0,0 +1,48 @@
+# 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 sys
+import tempfile
+import shutil
+import zipfile
+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):
+        raise Exception("Package file %s is not a valid .zip file." % package)
+
+    ensureParentDir(output)
+    tmpdir = tempfile.mkdtemp()
+    try:
+        z = zipfile.ZipFile(package)
+        z.extractall(tmpdir)
+        filelist = z.namelist()
+        z.close()
+
+        # Make sure the .zip file just contains a directory like 'firefox/' at
+        # the top, and find out what it is called.
+        toplevel_dirs = set([mozpath.split(f)[0] for f in filelist])
+        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/make_full_update.sh')
+
+        env = os.environ.copy()
+        env['MOZ_FULL_PRODUCT_VERSION'] = get_application_ini_value(tmpdir, 'App', 'Version')
+        env['MAR'] = mozpath.normpath(mar)
+
+        cmd = [make_full_update, output, ffxdir]
+        if sys.platform == 'win32':
+            # make_full_update.sh 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)
+
+    finally:
+        shutil.rmtree(tmpdir)