mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 17:48:19 +00:00
Create custom look for DMG using dmgbuild
(nice background image still missing)
This commit is contained in:
parent
b8fb704952
commit
fec20679f1
3
.github/workflows/build.yaml
vendored
3
.github/workflows/build.yaml
vendored
|
@ -80,8 +80,9 @@ jobs:
|
|||
if: contains(matrix.os, 'macOS')
|
||||
run: |
|
||||
brew update || true
|
||||
brew install pkg-config sdl2
|
||||
brew install pkg-config sdl2 python3
|
||||
brew upgrade freetype
|
||||
pip3 install dmgbuild
|
||||
sudo rm -rf /Library/Developer/CommandLineTools
|
||||
|
||||
- name: Build in debug mode
|
||||
|
|
|
@ -437,24 +437,9 @@ else()
|
|||
set(WEBSOCKETS_INCLUDE_DIRS)
|
||||
endif()
|
||||
|
||||
|
||||
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
|
||||
find_program(CMAKE_OTOOL otool)
|
||||
find_program(DMG dmg)
|
||||
find_program(HFSPLUS hfsplus)
|
||||
find_program(NEWFS_HFS newfs_hfs)
|
||||
if(DMG AND HFSPLUS AND NEWFS_HFS)
|
||||
set(DMGTOOLS_FOUND ON)
|
||||
else()
|
||||
set(DMGTOOLS_FOUND OFF)
|
||||
endif()
|
||||
|
||||
find_program(HDIUTIL hdiutil)
|
||||
if(HDIUTIL)
|
||||
set(HDIUTIL_FOUND ON)
|
||||
else()
|
||||
set(HDIUTIL_FOUND OFF)
|
||||
endif()
|
||||
find_program(DMGBUILD dmgbuild)
|
||||
endif()
|
||||
|
||||
message(STATUS "******** DDNet ********")
|
||||
|
@ -493,7 +478,7 @@ endif()
|
|||
show_dependency_status("Glew" GLEW)
|
||||
show_dependency_status("GTest" GTEST)
|
||||
if(TARGET_OS AND TARGET_OS STREQUAL "mac")
|
||||
show_dependency_status("Hdiutil" HDIUTIL)
|
||||
show_dependency_status("Dmgbuild" DMGBUILD)
|
||||
endif()
|
||||
if(UPNP)
|
||||
show_dependency_status("Miniupnpc" MINIUPNPC)
|
||||
|
@ -2562,17 +2547,12 @@ else()
|
|||
endif()
|
||||
|
||||
set(PACKAGE_TARGETS)
|
||||
if(CLIENT AND (DMGTOOLS_FOUND OR HDIUTIL))
|
||||
if(CLIENT AND DMGBUILD)
|
||||
file(MAKE_DIRECTORY bundle/client/)
|
||||
file(MAKE_DIRECTORY bundle/server/)
|
||||
configure_file(other/bundle/client/Info.plist.in bundle/client/Info.plist)
|
||||
configure_file(other/bundle/server/Info.plist.in bundle/server/Info.plist)
|
||||
|
||||
if(HDIUTIL)
|
||||
set(DMG_PARAMS --hdiutil ${HDIUTIL})
|
||||
elseif(DMGTOOLS_FOUND)
|
||||
set(DMG_PARAMS --dmgtools ${DMG} ${HFSPLUS} ${NEWFS_HFS})
|
||||
endif()
|
||||
set(DMG_TMPDIR pack_${CPACK_PACKAGE_FILE_NAME}_dmg)
|
||||
set(DMG_MKDIRS
|
||||
${TARGET_CLIENT}.app
|
||||
|
@ -2628,7 +2608,7 @@ if(CLIENT AND (DMGTOOLS_FOUND OR HDIUTIL))
|
|||
COMMAND ${CMAKE_COMMAND} -E copy ${DMG_TMPDIR}/${TARGET_SERVER}.app/Contents/MacOS/${TARGET_SERVER} ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/MacOS/${TARGET_SERVER}
|
||||
|
||||
# DMG
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/dmg.py create ${DMG_PARAMS} ${CPACK_PACKAGE_FILE_NAME}.dmg ${CPACK_PACKAGE_FILE_NAME} ${DMG_TMPDIR}
|
||||
COMMAND dmgbuild -s ${PROJECT_SOURCE_DIR}/other/dmgsettings.py -D client=${DMG_TMPDIR}/${TARGET_CLIENT}.app -D server=${DMG_TMPDIR}/${TARGET_SERVER}.app "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}" ${CPACK_PACKAGE_FILE_NAME}.dmg
|
||||
|
||||
DEPENDS
|
||||
${TARGET_CLIENT}
|
||||
|
@ -2642,7 +2622,6 @@ if(CLIENT AND (DMGTOOLS_FOUND OR HDIUTIL))
|
|||
other/bundle/server/PkgInfo
|
||||
other/icons/${TARGET_CLIENT}.icns
|
||||
other/icons/${TARGET_SERVER}.icns
|
||||
scripts/dmg.py
|
||||
)
|
||||
add_custom_target(package_dmg DEPENDS ${CPACK_PACKAGE_FILE_NAME}.dmg)
|
||||
list(APPEND PACKAGE_TARGETS package_dmg)
|
||||
|
|
199
other/dmgsettings.py
Normal file
199
other/dmgsettings.py
Normal file
|
@ -0,0 +1,199 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=E0602
|
||||
from __future__ import unicode_literals
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Before Python 3.4, use biplist; afterwards, use plistlib
|
||||
if sys.version_info < (3, 4):
|
||||
import biplist # pylint: disable=E0401
|
||||
def read_plist(path):
|
||||
return biplist.readPlist(path)
|
||||
else:
|
||||
import plistlib # pylint: disable=E0401
|
||||
def read_plist(path):
|
||||
with open(path, 'rb') as f:
|
||||
return plistlib.load(f)
|
||||
|
||||
#
|
||||
# Example settings file for dmgbuild
|
||||
#
|
||||
|
||||
# Use like this: dmgbuild -s settings.py "Test Volume" test.dmg
|
||||
|
||||
# You can actually use this file for your own application (not just TextEdit)
|
||||
# by doing e.g.
|
||||
#
|
||||
# dmgbuild -s settings.py -D app=/path/to/My.app "My Application" MyApp.dmg
|
||||
|
||||
# .. Useful stuff ..............................................................
|
||||
|
||||
application_client = defines.get('client', 'DDNet.app')
|
||||
application_server = defines.get('server', 'DDNet-Server.app')
|
||||
appname_client = os.path.basename(application_client)
|
||||
appname_server = os.path.basename(application_server)
|
||||
|
||||
def icon_from_app(app_path):
|
||||
plist_path = os.path.join(app_path, 'Contents', 'Info.plist')
|
||||
plist = read_plist(plist_path)
|
||||
icon_name = plist['CFBundleIconFile']
|
||||
icon_root,icon_ext = os.path.splitext(icon_name)
|
||||
if not icon_ext:
|
||||
icon_ext = '.icns'
|
||||
icon_name = icon_root + icon_ext
|
||||
return os.path.join(app_path, 'Contents', 'Resources', icon_name)
|
||||
|
||||
# .. Basics ....................................................................
|
||||
|
||||
# Uncomment to override the output filename
|
||||
# filename = 'DDNet.dmg''
|
||||
|
||||
# Uncomment to override the output volume name
|
||||
# volume_name = 'DDNet'
|
||||
|
||||
# Volume format (see hdiutil create -help)
|
||||
format = defines.get('format', 'UDBZ') # pylint: disable=W0622
|
||||
|
||||
# Compression level (if relevant)
|
||||
compression_level = 9
|
||||
|
||||
# Volume size
|
||||
size = defines.get('size', None)
|
||||
|
||||
# Files to include
|
||||
files = [ application_client, application_server ]
|
||||
|
||||
# Symlinks to create
|
||||
symlinks = { 'Applications': '/Applications' }
|
||||
|
||||
# Files to hide
|
||||
# hide = [ 'Secret.data' ]
|
||||
|
||||
# Files to hide the extension of
|
||||
hide_extension = [ appname_client, appname_server ]
|
||||
|
||||
# Volume icon
|
||||
#
|
||||
# You can either define icon, in which case that icon file will be copied to the
|
||||
# image, *or* you can define badge_icon, in which case the icon file you specify
|
||||
# will be used to badge the system's Removable Disk icon. Badge icons require
|
||||
# pyobjc-framework-Quartz.
|
||||
#
|
||||
#icon = '/path/to/icon.icns'
|
||||
badge_icon_client = icon_from_app(application_client)
|
||||
badge_icon_server = icon_from_app(application_server)
|
||||
|
||||
# Where to put the icons
|
||||
icon_locations = {
|
||||
appname_client: (140, 120),
|
||||
appname_server: (240, 120),
|
||||
'Applications': (500, 120)
|
||||
}
|
||||
|
||||
# .. Window configuration ......................................................
|
||||
|
||||
# Background
|
||||
#
|
||||
# This is a STRING containing any of the following:
|
||||
#
|
||||
# #3344ff - web-style RGB color
|
||||
# #34f - web-style RGB color, short form (#34f == #3344ff)
|
||||
# rgb(1,0,0) - RGB color, each value is between 0 and 1
|
||||
# hsl(120,1,.5) - HSL (hue saturation lightness) color
|
||||
# hwb(300,0,0) - HWB (hue whiteness blackness) color
|
||||
# cmyk(0,1,0,0) - CMYK color
|
||||
# goldenrod - X11/SVG named color
|
||||
# builtin-arrow - A simple built-in background with a blue arrow
|
||||
# /foo/bar/baz.png - The path to an image file
|
||||
#
|
||||
# The hue component in hsl() and hwb() may include a unit; it defaults to
|
||||
# degrees ('deg'), but also supports radians ('rad') and gradians ('grad'
|
||||
# or 'gon').
|
||||
#
|
||||
# Other color components may be expressed either in the range 0 to 1, or
|
||||
# as percentages (e.g. 60% is equivalent to 0.6).
|
||||
background = 'builtin-arrow'
|
||||
|
||||
show_status_bar = False
|
||||
show_tab_view = False
|
||||
show_toolbar = False
|
||||
show_pathbar = False
|
||||
show_sidebar = False
|
||||
sidebar_width = 180
|
||||
|
||||
# Window position in ((x, y), (w, h)) format
|
||||
window_rect = ((100, 100), (640, 280))
|
||||
|
||||
# Select the default view; must be one of
|
||||
#
|
||||
# 'icon-view'
|
||||
# 'list-view'
|
||||
# 'column-view'
|
||||
# 'coverflow'
|
||||
#
|
||||
default_view = 'icon-view'
|
||||
|
||||
# General view configuration
|
||||
show_icon_preview = False
|
||||
|
||||
# Set these to True to force inclusion of icon/list view settings (otherwise
|
||||
# we only include settings for the default view)
|
||||
include_icon_view_settings = 'auto'
|
||||
include_list_view_settings = 'auto'
|
||||
|
||||
# .. Icon view configuration ...................................................
|
||||
|
||||
arrange_by = None
|
||||
grid_offset = (0, 0)
|
||||
grid_spacing = 100
|
||||
scroll_position = (0, 0)
|
||||
label_pos = 'bottom' # or 'right'
|
||||
text_size = 16
|
||||
icon_size = 128
|
||||
|
||||
# .. List view configuration ...................................................
|
||||
|
||||
# Column names are as follows:
|
||||
#
|
||||
# name
|
||||
# date-modified
|
||||
# date-created
|
||||
# date-added
|
||||
# date-last-opened
|
||||
# size
|
||||
# kind
|
||||
# label
|
||||
# version
|
||||
# comments
|
||||
#
|
||||
list_icon_size = 16
|
||||
list_text_size = 12
|
||||
list_scroll_position = (0, 0)
|
||||
list_sort_by = 'name'
|
||||
list_use_relative_dates = True
|
||||
list_calculate_all_sizes = (False,)
|
||||
list_columns = ('name', 'date-modified', 'size', 'kind', 'date-added')
|
||||
list_column_widths = {
|
||||
'name': 300,
|
||||
'date-modified': 181,
|
||||
'date-created': 181,
|
||||
'date-added': 181,
|
||||
'date-last-opened': 181,
|
||||
'size': 97,
|
||||
'kind': 115,
|
||||
'label': 100,
|
||||
'version': 75,
|
||||
'comments': 300,
|
||||
}
|
||||
list_column_sort_directions = {
|
||||
'name': 'ascending',
|
||||
'date-modified': 'descending',
|
||||
'date-created': 'descending',
|
||||
'date-added': 'descending',
|
||||
'date-last-opened': 'descending',
|
||||
'size': 'descending',
|
||||
'kind': 'ascending',
|
||||
'label': 'ascending',
|
||||
'version': 'ascending',
|
||||
'comments': 'ascending',
|
||||
}
|
120
scripts/dmg.py
120
scripts/dmg.py
|
@ -1,120 +0,0 @@
|
|||
from collections import namedtuple
|
||||
import argparse
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
ConfigDmgtools = namedtuple('Config', 'dmg hfsplus newfs_hfs verbose')
|
||||
ConfigHdiutil = namedtuple('Config', 'hdiutil verbose')
|
||||
|
||||
def chunks(l, n):
|
||||
"""
|
||||
Yield successive n-sized chunks from l.
|
||||
|
||||
From https://stackoverflow.com/a/312464.
|
||||
"""
|
||||
for i in range(0, len(l), n):
|
||||
yield l[i:i + n]
|
||||
|
||||
class Dmg:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def _check_call(self, process_args, *args, **kwargs):
|
||||
if self.config.verbose >= 1:
|
||||
print("EXECUTING {}".format(" ".join(shlex.quote(x) for x in process_args)))
|
||||
if not (self.config.verbose >= 2 and "stdout" not in kwargs):
|
||||
kwargs["stdout"] = open(os.devnull, 'wb')
|
||||
subprocess.check_call(process_args, *args, **kwargs)
|
||||
|
||||
class Dmgtools(Dmg):
|
||||
def _mkfs_hfs(self, *args):
|
||||
self._check_call((self.config.newfs_hfs,) + args)
|
||||
def _hfs(self, *args):
|
||||
self._check_call((self.config.hfsplus,) + args)
|
||||
def _dmg(self, *args):
|
||||
self._check_call((self.config.dmg,) + args)
|
||||
|
||||
def _create_hfs(self, hfs_fd, hfs, volume_name, size):
|
||||
if self.config.verbose >= 1:
|
||||
print("TRUNCATING {} to {} bytes".format(hfs, size))
|
||||
with os.fdopen(hfs_fd, 'wb') as f:
|
||||
f.truncate(size)
|
||||
self._mkfs_hfs('-v', volume_name, hfs)
|
||||
|
||||
def _symlink(self, hfs, target, link_name):
|
||||
self._hfs(hfs, 'symlink', link_name, target)
|
||||
|
||||
def _add(self, hfs, directory):
|
||||
self._hfs(hfs, 'addall', directory)
|
||||
|
||||
def _finish(self, hfs, dmg):
|
||||
self._dmg('build', hfs, dmg)
|
||||
|
||||
def create(self, dmg, volume_name, directory, symlinks):
|
||||
input_size = sum(os.stat(os.path.join(path, f)).st_size for path, dirs, files in os.walk(directory) for f in files)
|
||||
output_size = max(input_size * 2, 1024**2)
|
||||
hfs_fd, hfs = tempfile.mkstemp(prefix=dmg + '.', suffix='.hfs')
|
||||
self._create_hfs(hfs_fd, hfs, volume_name, output_size)
|
||||
self._add(hfs, directory)
|
||||
for target, link_name in symlinks:
|
||||
self._symlink(hfs, target, link_name)
|
||||
self._finish(hfs, dmg)
|
||||
if self.config.verbose >= 1:
|
||||
print("REMOVING {}".format(hfs))
|
||||
os.remove(hfs)
|
||||
|
||||
class Hdiutil(Dmg):
|
||||
def _hdiutil(self, *args):
|
||||
self._check_call((self.config.hdiutil,) + args)
|
||||
|
||||
def create(self, dmg, volume_name, directory, symlinks):
|
||||
if symlinks:
|
||||
raise NotImplementedError("symlinks are not yet implemented")
|
||||
for i in range(5):
|
||||
try:
|
||||
os.remove(dmg)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
try:
|
||||
self._hdiutil('create', '-volname', volume_name, '-srcdir', directory, dmg)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if i == 4:
|
||||
raise e
|
||||
print("Retrying hdiutil create")
|
||||
time.sleep(5)
|
||||
else:
|
||||
break
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description="Manipulate dmg archives")
|
||||
|
||||
subcommands = p.add_subparsers(help="Subcommand", dest='command', metavar="COMMAND")
|
||||
subcommands.required = True
|
||||
|
||||
create = subcommands.add_parser("create", help="Create a dmg archive from files or directories")
|
||||
create.add_argument('-v', '--verbose', action='count', help="Verbose output")
|
||||
createx = create.add_mutually_exclusive_group(required=True)
|
||||
createx.add_argument('--dmgtools', nargs=3, help="Paths to the dmg and hfsplus executable (https://github.com/mozilla/libdmg-hfsplus) and the newfs_hfs executable (http://pkgs.fedoraproject.org/repo/pkgs/hfsplus-tools/diskdev_cmds-540.1.linux3.tar.gz/0435afc389b919027b69616ad1b05709/diskdev_cmds-540.1.linux3.tar.gz)")
|
||||
createx.add_argument('--hdiutil', help="Path to the hdiutil (only exists for macOS at time of writing)")
|
||||
create.add_argument('output', metavar="OUTPUT", help="Filename of the output dmg archive")
|
||||
create.add_argument('volume_name', metavar="VOLUME_NAME", help="Name of the dmg archive")
|
||||
create.add_argument('directory', metavar="DIR", help="Directory to create the archive from")
|
||||
create.add_argument('--symlink', metavar="SYMLINK", nargs=2, action="append", help="Symlink the first argument under the second name")
|
||||
args = p.parse_args()
|
||||
|
||||
verbose = args.verbose or 0
|
||||
symlinks = args.symlink or []
|
||||
if args.dmgtools:
|
||||
dmg, hfsplus, newfs_hfs = args.dmgtools
|
||||
dmg = Dmgtools(ConfigDmgtools(dmg=dmg, hfsplus=hfsplus, newfs_hfs=newfs_hfs, verbose=verbose))
|
||||
elif args.hdiutil:
|
||||
dmg = Hdiutil(ConfigHdiutil(hdiutil=args.hdiutil, verbose=verbose))
|
||||
else:
|
||||
raise RuntimeError("unreachable")
|
||||
dmg.create(volume_name=args.volume_name, directory=args.directory, dmg=args.output, symlinks=symlinks)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue