--- a/python/mozbuild/mozpack/dmg.py
+++ b/python/mozbuild/mozpack/dmg.py
@@ -1,24 +1,24 @@
# 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 buildconfig
import errno
import mozfile
import os
import platform
import shutil
import subprocess
import mozpack.path as mozpath
from mozbuild.util import ensureParentDir
is_linux = platform.system() == 'Linux'
+cross_tools = {}
def mkdir(dir):
if not os.path.isdir(dir):
try:
os.makedirs(dir)
except OSError as e:
if e.errno != errno.EEXIST:
@@ -41,17 +41,17 @@ def rsync(source, dest):
def set_folder_icon(dir, tmpdir):
'Set HFS attributes of dir to use a custom icon'
if not is_linux:
subprocess.check_call(['SetFile', '-a', 'C', dir])
else:
hfs = os.path.join(tmpdir, 'staged.hfs')
subprocess.check_call([
- buildconfig.substs['HFS_TOOL'], hfs, 'attr', '/', 'C'])
+ cross_tools['HFS_TOOL'], hfs, 'attr', '/', 'C'])
def generate_hfs_file(stagedir, tmpdir, volume_name):
'''
When cross compiling, we zero fill an hfs file, that we will turn into
a DMG. To do so we test the size of the staged dir, and add some slight
padding to that.
'''
@@ -59,30 +59,30 @@ def generate_hfs_file(stagedir, tmpdir,
hfs = os.path.join(tmpdir, 'staged.hfs')
output = subprocess.check_output(['du', '-s', stagedir])
size = (int(output.split()[0]) / 1000) # Get in MB
size = int(size * 1.02) # Bump the used size slightly larger.
# Setup a proper file sized out with zero's
subprocess.check_call(['dd', 'if=/dev/zero', 'of={}'.format(hfs),
'bs=1M', 'count={}'.format(size)])
subprocess.check_call([
- buildconfig.substs['MKFSHFS'], '-v', volume_name,
+ cross_tools['MKFSHFS'], '-v', volume_name,
hfs])
def create_app_symlink(stagedir, tmpdir):
'''
Make a symlink to /Applications. The symlink name is a space
so we don't have to localize it. The Applications folder icon
will be shown in Finder, which should be clear enough for users.
'''
if is_linux:
hfs = os.path.join(tmpdir, 'staged.hfs')
subprocess.check_call([
- buildconfig.substs['HFS_TOOL'], hfs, 'symlink',
+ cross_tools['HFS_TOOL'], hfs, 'symlink',
'/ ', '/Applications'])
else:
os.symlink('/Applications', os.path.join(stagedir, ' '))
def create_dmg_from_staged(stagedir, output_dmg, tmpdir, volume_name):
'Given a prepared directory stagedir, produce a DMG at output_dmg.'
if not is_linux:
@@ -98,39 +98,47 @@ def create_dmg_from_staged(stagedir, out
'-ov', hybrid, '-o', output_dmg])
else:
# The dmg tool doesn't create the destination directories, and silently
# returns success if the parent directory doesn't exist.
ensureParentDir(output_dmg)
hfs = os.path.join(tmpdir, 'staged.hfs')
subprocess.check_call([
- buildconfig.substs['HFS_TOOL'], hfs, 'addall', stagedir])
+ cross_tools['HFS_TOOL'], hfs, 'addall', stagedir])
subprocess.check_call([
- buildconfig.substs['DMG_TOOL'],
+ cross_tools['DMG_TOOL'],
'build',
hfs,
output_dmg
],
# dmg is seriously chatty
stdout=open(os.devnull, 'wb'))
def check_tools(*tools):
'''
Check that each tool named in tools exists in SUBSTS and is executable.
'''
for tool in tools:
- path = buildconfig.substs[tool]
+ # Try to pull tools from the environment first, and only grab them from
+ # buildconfig if necessary. This lets us package dmgs without configure
+ # as a prerequisite.
+ path = os.environ.get(tool)
+ if not path:
+ import buildconfig
+ path = buildconfig.substs[tool]
+
if not path:
raise Exception('Required tool "%s" not found' % tool)
if not os.path.isfile(path):
raise Exception('Required tool "%s" not found at path "%s"' % (tool, path))
if not os.access(path, os.X_OK):
raise Exception('Required tool "%s" at path "%s" is not executable' % (tool, path))
+ cross_tools[tool] = path
def repackage_dmg(source_directory, output_dmg):
import ConfigParser
# 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: