зеркало из https://github.com/mozilla/gecko-dev.git
bug 1190522 - Rewrite pkg-dmg as a Python script. r=gps
--HG-- extra : commitid : 8CKCtjFc6wl extra : rebase_source : bc51508f3708a7a7af8fe48bdbcb0d787bf77362 extra : source : bca1ad6cc3781af4b8c8667ccb3c29e5bcb50ea9
This commit is contained in:
Родитель
e9e5f1bb92
Коммит
de9027084a
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,37 @@
|
|||
# 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/.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from mozbuild.base import MozbuildObject
|
||||
from mozpack import dmg
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def make_dmg(source_directory, output_dmg):
|
||||
build = MozbuildObject.from_environment()
|
||||
extra_files = [
|
||||
(os.path.join(build.distdir, 'branding', 'dsstore'), '.DS_Store'),
|
||||
(os.path.join(build.distdir, 'branding', 'background.png'),
|
||||
'.background/background.png'),
|
||||
(os.path.join(build.distdir, 'branding', 'disk.icns'),
|
||||
'.VolumeIcon.icns'),
|
||||
]
|
||||
volume_name = build.substs['MOZ_APP_DISPLAYNAME']
|
||||
dmg.create_dmg(source_directory, output_dmg, volume_name, extra_files)
|
||||
|
||||
|
||||
def main(args):
|
||||
if len(args) != 2:
|
||||
print('Usage: make_dmg.py <source directory> <output dmg>',
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
make_dmg(args[0], args[1])
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
|
@ -0,0 +1,78 @@
|
|||
# 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 errno
|
||||
import mozfile
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def mkdir(dir):
|
||||
if not os.path.isdir(dir):
|
||||
try:
|
||||
os.makedirs(dir)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
def chmod(dir):
|
||||
'Set permissions of DMG contents correctly'
|
||||
subprocess.check_call(['chmod', '-R', 'a+rX,a-st,u+w,go-w', dir])
|
||||
|
||||
|
||||
def rsync(source, dest):
|
||||
'rsync the contents of directory source into directory dest'
|
||||
# Ensure a trailing slash so rsync copies the *contents* of source.
|
||||
if not source.endswith('/'):
|
||||
source += '/'
|
||||
subprocess.check_call(['rsync', '-a', '--copy-unsafe-links',
|
||||
source, dest])
|
||||
|
||||
|
||||
def set_folder_icon(dir):
|
||||
'Set HFS attributes of dir to use a custom icon'
|
||||
subprocess.check_call(['SetFile', '-a', 'C', dir])
|
||||
|
||||
|
||||
def create_dmg_from_staged(stagedir, output_dmg, tmpdir, volume_name):
|
||||
'Given a prepared directory stagedir, produce a DMG at output_dmg.'
|
||||
hybrid = os.path.join(tmpdir, 'hybrid.dmg')
|
||||
subprocess.check_call(['hdiutil', 'makehybrid', '-hfs',
|
||||
'-hfs-volume-name', volume_name,
|
||||
'-hfs-openfolder', stagedir,
|
||||
'-ov', stagedir,
|
||||
'-o', hybrid])
|
||||
subprocess.check_call(['hdiutil', 'convert', '-format', 'UDBZ',
|
||||
'-imagekey', 'bzip2-level=9',
|
||||
'-ov', hybrid, '-o', output_dmg])
|
||||
|
||||
|
||||
def create_dmg(source_directory, output_dmg, volume_name, extra_files):
|
||||
'''
|
||||
Create a DMG disk image at the path output_dmg from source_directory.
|
||||
|
||||
Use volume_name as the disk image volume name, and
|
||||
use extra_files as a list of tuples of (filename, relative path) to copy
|
||||
into the disk image.
|
||||
'''
|
||||
with mozfile.TemporaryDirectory() as tmpdir:
|
||||
stagedir = os.path.join(tmpdir, 'stage')
|
||||
os.mkdir(stagedir)
|
||||
# Copy the app bundle over using rsync
|
||||
rsync(source_directory, stagedir)
|
||||
# Copy extra files
|
||||
for source, target in extra_files:
|
||||
full_target = os.path.join(stagedir, target)
|
||||
mkdir(os.path.dirname(full_target))
|
||||
shutil.copyfile(source, full_target)
|
||||
# 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.
|
||||
os.symlink('/Applications', os.path.join(stagedir, ' '))
|
||||
# Set the folder attributes to use a custom icon
|
||||
set_folder_icon(stagedir)
|
||||
chmod(stagedir)
|
||||
create_dmg_from_staged(stagedir, output_dmg, tmpdir, volume_name)
|
|
@ -503,29 +503,10 @@ endif
|
|||
|
||||
ifeq ($(MOZ_PKG_FORMAT),DMG)
|
||||
PKG_SUFFIX = .dmg
|
||||
PKG_DMG_FLAGS =
|
||||
ifneq (,$(MOZ_PKG_MAC_DSSTORE))
|
||||
PKG_DMG_FLAGS += --copy '$(MOZ_PKG_MAC_DSSTORE):/.DS_Store'
|
||||
endif
|
||||
ifneq (,$(MOZ_PKG_MAC_BACKGROUND))
|
||||
PKG_DMG_FLAGS += --mkdir /.background --copy '$(MOZ_PKG_MAC_BACKGROUND):/.background'
|
||||
endif
|
||||
ifneq (,$(MOZ_PKG_MAC_ICON))
|
||||
PKG_DMG_FLAGS += --icon '$(MOZ_PKG_MAC_ICON)'
|
||||
endif
|
||||
ifneq (,$(MOZ_PKG_MAC_RSRC))
|
||||
PKG_DMG_FLAGS += --resource '$(MOZ_PKG_MAC_RSRC)'
|
||||
endif
|
||||
ifneq (,$(MOZ_PKG_MAC_EXTRA))
|
||||
PKG_DMG_FLAGS += $(MOZ_PKG_MAC_EXTRA)
|
||||
endif
|
||||
|
||||
_ABS_MOZSRCDIR = $(shell cd $(MOZILLA_DIR) && pwd)
|
||||
ifndef PKG_DMG_SOURCE
|
||||
PKG_DMG_SOURCE = $(STAGEPATH)$(MOZ_PKG_DIR)
|
||||
endif
|
||||
INNER_MAKE_PACKAGE = $(_ABS_MOZSRCDIR)/build/package/mac_osx/pkg-dmg \
|
||||
--source '$(PKG_DMG_SOURCE)' --target '$(PACKAGE)' \
|
||||
--volname '$(MOZ_APP_DISPLAYNAME)' $(PKG_DMG_FLAGS)
|
||||
INNER_MAKE_PACKAGE = $(call py_action,make_dmg,'$(PKG_DMG_SOURCE)' '$(PACKAGE)')
|
||||
INNER_UNMAKE_PACKAGE = \
|
||||
set -ex; \
|
||||
rm -rf $(_ABS_DIST)/unpack.tmp; \
|
||||
|
|
Загрузка…
Ссылка в новой задаче