From b789895c1bcb13a400ecbe7018d534f579b0faf1 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 25 Sep 2019 13:17:31 -0700 Subject: [PATCH] macOS: Use dmgbuild to build our .dmg. Scripting the Finder in order to lay out our disk image assumes that we have access to the Finder. This might not be the case on our builder, and it arguably shoudn't be. Switch from using a Bash script + AppleScript to build and lay out our .dmg to using dmgbuild, which creates our .DS_Store directly using Python's ds_store module. Change-Id: I2e4a9dd89bc8297c9cbd9df7aa8d3a44447bde85 Reviewed-on: https://code.wireshark.org/review/34623 Reviewed-by: Gerald Combs --- .editorconfig | 2 +- CMakeLists.txt | 43 +++-- packaging/macosx/arrange_dmg.applescript.in | 43 ----- packaging/macosx/dmgbuild-settings.py.in | 147 +++++++++++++++ packaging/macosx/osx-dmg.sh.in | 196 -------------------- 5 files changed, 171 insertions(+), 260 deletions(-) delete mode 100644 packaging/macosx/arrange_dmg.applescript.in create mode 100644 packaging/macosx/dmgbuild-settings.py.in delete mode 100755 packaging/macosx/osx-dmg.sh.in diff --git a/.editorconfig b/.editorconfig index 3b71a97d15..1bd0e713cd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -25,7 +25,7 @@ indent_style = tab indent_size = 8 # Python -[*.py] +[*.{py,py.in}] indent_style = space indent_size = 4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ee6e53a7c..4ec91abbe7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1275,6 +1275,9 @@ if (QT_FOUND) HINTS "${QT_BIN_PATH}" DOC "Path to the macdeployqt utility." ) + find_program(DMGBUILD_EXECUTABLE dmgbuild + DOC "Path to the dmgbuild utility" + ) # https://doc.qt.io/qt-5.11/supported-platforms-and-configurations.html # CMake < 3.7 doesn't support VERSION_GREATER_EQUAL. if(Qt5Widgets_VERSION VERSION_GREATER "5.11.999") @@ -1554,9 +1557,8 @@ set(CFG_OUT_FILES image/wiretap.rc image/wireshark.exe.manifest packaging/macosx/Info.plist - packaging/macosx/arrange_dmg.applescript + packaging/macosx/dmgbuild-settings.py packaging/macosx/osx-app.sh - packaging/macosx/osx-dmg.sh packaging/source/git-export-release.sh wireshark.pc ) @@ -2877,37 +2879,38 @@ if(ENABLE_APPLICATION_BUNDLE) ) add_dependencies(app_bundle ${PROGLIST} chmodbpf path_helper) - add_custom_target(dmg_package_prep DEPENDS app_bundle) + if( DMGBUILD_EXECUTABLE AND ASCIIDOCTOR_FOUND) + add_custom_target(dmg_package_prep DEPENDS app_bundle) - if( ASCIIDOCTOR_FOUND ) + set(_read_me_first "packaging/macosx/Read me first.html") ADD_CUSTOM_COMMAND( OUTPUT - packaging/macosx/Read_me_first.html + ${_read_me_first} COMMAND ${ASCIIDOCTOR_EXECUTABLE} --backend html - --out-file packaging/macosx/Read_me_first.html + --out-file ${_read_me_first} --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook --attribute min-macos-version=${MIN_MACOS_VERSION} ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Read_me_first.adoc DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Read_me_first.adoc ) - add_custom_target(read_me_first_html DEPENDS packaging/macosx/Read_me_first.html ) + add_custom_target(read_me_first_html DEPENDS ${_read_me_first} ) add_dependencies(dmg_package_prep read_me_first_html) - endif() - ADD_CUSTOM_TARGET( dmg_package - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_SOURCE_DIR}/COPYING - ${CMAKE_BINARY_DIR}/run/COPYING.txt - COMMAND bash -x ${CMAKE_BINARY_DIR}/packaging/macosx/osx-dmg.sh - --source-directory ${CMAKE_SOURCE_DIR}/packaging/macosx - # Unlike nsis_package_prep + nsis_package, we can add a direct - # dependency here. - DEPENDS dmg_package_prep - # We create Wireshark.app in "run". Do our work there. - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run - ) + ADD_CUSTOM_TARGET( dmg_package + COMMAND ${DMGBUILD_EXECUTABLE} + --no-hidpi + -s ${CMAKE_BINARY_DIR}/packaging/macosx/dmgbuild-settings.py + "Wireshark ${VERSION}" + "Wireshark ${VERSION} Intel 64.dmg" + # Unlike nsis_package_prep + nsis_package, we can add a direct + # dependency here. + DEPENDS dmg_package_prep + # We create Wireshark.app in "run". Do our work there. + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run + ) + endif() endif() diff --git a/packaging/macosx/arrange_dmg.applescript.in b/packaging/macosx/arrange_dmg.applescript.in deleted file mode 100644 index 89d745f892..0000000000 --- a/packaging/macosx/arrange_dmg.applescript.in +++ /dev/null @@ -1,43 +0,0 @@ -(* -This AppleScript customizes the appearance of the -disk image in which Wireshark is bundled on macOS - - Author: - Jean-Olivier Irisson - -Modified by: - Gerald Combs - - Copyright 2006 - Licensed under GNU General Public License -*) - - -tell application "Finder" - tell disk "Wireshark @VERSION@" - open - tell container window - set current view to icon view - set toolbar visible to false - set statusbar visible to false - set the bounds to {600, 200, 950, 725} - end tell - set iv_opts to the icon view options of container window - set background picture of iv_opts to POSIX file "/Volumes/Wireshark @VERSION@/.assets/dmg_background.png" - tell iv_opts - set icon size to 72 - set arrangement to not arranged - end tell - set position of application file "Wireshark.app" to {80, 64} - set position of alias file "Applications" to {240, 64} - set position of file "Read me first.html" to {160, 170} - set position of alias file "Install ChmodBPF.pkg" to {80, 276} - set position of alias file "Uninstall ChmodBPF.pkg" to {250, 276} - set position of alias file "Add Wireshark to the system path.pkg" to {80, 382} - set position of alias file "Remove Wireshark from the system path.pkg" to {250, 382} - update without registering applications - end tell - - --give the finder some time to write the .DS_Store file - delay 7 -end tell diff --git a/packaging/macosx/dmgbuild-settings.py.in b/packaging/macosx/dmgbuild-settings.py.in new file mode 100644 index 0000000000..6d7202ce42 --- /dev/null +++ b/packaging/macosx/dmgbuild-settings.py.in @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import biplist +import os.path + +# +# Example settings file for dmgbuild +# +# Adapted from https://raw.githubusercontent.com/al45tair/dmgbuild/master/examples/settings.py + +# 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 .............................................................. + +ws_version = '@VERSION@' +ws_volname = 'Wireshark ' + ws_version +ws_srcdir = '@CMAKE_SOURCE_DIR@' +ws_bindir = '@CMAKE_BINARY_DIR@' +ws_app = 'Wireshark.app' +ws_readme = 'Read me first.html' +ws_install_chmodbpf = 'Install ChmodBPF.pkg' +ws_uninstall_chmodbpf = 'Uninstall ChmodBPF.pkg' +ws_install_path_helper = 'Add Wireshark to the system path.pkg' +ws_uninstall_path_helper = 'Remove Wireshark from the system path.pkg' + +# .. Basics .................................................................... + +# Uncomment to override the output filename +# filename = ws_volname + ' Intel 64.dmg' + +# Uncomment to override the output volume name +# volume_name = 'Wireshark ' + ws_version + +# From the hdiutil man page: +# UDZO - UDIF zlib-compressed image +# UDBZ - UDIF bzip2-compressed image (Mac OS X 10.4+ only) +# ULFO - UDIF lzfse-compressed image (OS X 10.11+ only) +# Volume format (see hdiutil create -help) +format = defines.get('format', 'UDBZ') + +# Compression level (if relevant) +# compression_level = 9 + +# Volume size +size = None + +# Files to include +files = [ + os.path.join(ws_bindir, 'run', ws_app), + os.path.join(ws_bindir, 'packaging', 'macosx', ws_readme), +] + +# Symlinks to create +symlinks = { + 'Applications': '/Applications', + ws_install_chmodbpf: os.path.join(ws_app, 'Contents', 'Resources', 'Extras', ws_install_chmodbpf), + ws_uninstall_chmodbpf: os.path.join(ws_app, 'Contents', 'Resources', 'Extras', ws_uninstall_chmodbpf), + ws_install_path_helper: os.path.join(ws_app, 'Contents', 'Resources', 'Extras', ws_install_path_helper), + ws_uninstall_path_helper: os.path.join(ws_app, 'Contents', 'Resources', 'Extras', ws_uninstall_path_helper), + } + +# 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 +# +#icon = '/path/to/icon.icns' +#badge_icon = icon_from_app(application) + +# Where to put the icons +icon_locations = { + ws_app: ( 80, 64), + 'Applications': (240, 64), + ws_readme: (160, 170), + ws_install_chmodbpf: ( 80, 276), + ws_uninstall_chmodbpf: (250, 276), + ws_install_path_helper: ( 80, 382), + ws_uninstall_path_helper: (250, 382), + } + +# .. 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 = os.path.join(ws_srcdir, 'packaging', 'macosx', 'dmg_background.png') + +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 = ((600, 200), (350, 525)) + +# 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 = 12 +icon_size = 72 diff --git a/packaging/macosx/osx-dmg.sh.in b/packaging/macosx/osx-dmg.sh.in deleted file mode 100755 index 7cb024cb6f..0000000000 --- a/packaging/macosx/osx-dmg.sh.in +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash -# -# USAGE -# osx-dmg [-s] -p /path/to/Wireshark.app -# -# The script creates a read-write disk image, -# copies Wireshark into it, customizes its appearance using a -# previously created .DS_Store file (wireshark.ds_store), -# and then compresses the disk image for distribution. -# -# Copied from Inkscape. -# -# AUTHORS -# Jean-Olivier Irisson -# Michael Wybrow -# -# Copyright (C) 2006-2007 -# Released under GNU GPL, read the file 'COPYING' for more information -# -# -# How to update the disk image layout: -# ------------------------------------ -# -# Modify the 'dmg_background.svg' file and generate a new -# 'dmg_background.png' file. -# -# Update the AppleScript file 'dmg_set_style.scpt'. -# -# Run this script with the '-s' option. It will apply the -# 'dmg_set_style.scpt' AppleScript file, and then prompt the -# user to check the window size and position before writing -# a new 'wireshark.ds_store' file to work around a bug in Finder -# and AppleScript. The updated 'wireshark.ds_store' will need -# to be commited to the repository when this is done. -# - -# Set during configuration -version="@VERSION@" -if [ -z "$version" ] ; then - echo "VERSION not set" - exit 1 -fi - -# Defaults -app_bundle="Wireshark.app" -rw_name="RWwireshark $version.dmg" -volume_name="Wireshark $version" -src_dir="." -tmp_dir="/tmp/dmg-$$" - -# Help message -#---------------------------------------------------------- -help() -{ -echo -e " -Create a custom dmg file to distribute Wireshark - -USAGE - $0 [-s] -p /path/to/Wireshark.app - -OPTIONS - -h,--help - Display this help message. - -b,--app-bundle - Set the path to the Wireshark.app that should be copied - in the dmg. - -S,--source-directory - If this is an out-of-tree build, set this to the path - to the packaging/macosx source directory. - -Icons are positioned and the background image is set in -arrange_dmg.applescript. -" -} - -# Parse command line arguments -while [ "$1" != "" ] -do - case $1 in - -h|--help) - help - exit 0 ;; - -b|--app-bundle) - app_bundle="$2" - shift 1 ;; - -S|--source-directory) - src_dir="$2" - shift 1 ;; - *) - echo "Invalid command line option" - exit 2 ;; - esac - shift 1 -done - -# Safety checks -if [ ! -e "$app_bundle" ]; then - echo "Cannot find application bundle: $app_bundle" - exit 1 -fi - -# Get the architecture -ws_bin="$app_bundle/Contents/MacOS/Wireshark" -case $( file "$ws_bin" ) in - *Mach-O*64-bit*x86_64*) - architecture="Intel 64" - ;; - *Mach-O*i386*) - architecture="Intel 32" - ;; - *) - echo "Cannot determine architecture of $ws_bin; file reports:" - file "$ws_bin" - exit 1 - ;; -esac -pkg_title="$volume_name $architecture" - -echo -e "\\nCREATE WIRESHARK DISK IMAGE\\n" -img_name="$pkg_title.dmg" - -# Create temp directory with desired contents of the release volume. -rm -rf "$tmp_dir" -mkdir "$tmp_dir" || exit 1 - -echo -e "Copying files to temp directory" -# Copy the application bundle -cp -r "$app_bundle" "$tmp_dir"/ || exit 1 -ln -sn "/Applications" "$tmp_dir"/ - -# Copy the readme -cp "../packaging/macosx/Read_me_first.html" "$tmp_dir/Read me first.html" || exit 1 - -# Copy the background image -mkdir "$tmp_dir/.assets" || exit 1 -cp "$src_dir/dmg_background.png" "$tmp_dir/.assets/" || exit 1 - -# Create top-level package symlinks -ln -sn "$app_bundle/Contents/Resources/Extras/"*.pkg "$tmp_dir/" - -# Create a new RW image from the temp directory. -echo -e "Creating a temporary disk image" -rm -f "$rw_name" -/usr/bin/hdiutil create -srcfolder "$tmp_dir" -volname "$volume_name" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$rw_name" || exit 1 - -# We're finished with the temp directory, remove it. -rm -rf "$tmp_dir" - -# Mount the created image. -#MOUNT_DIR="/Volumes/$volume_name" -DEV_NAME=$( /usr/bin/hdiutil attach -readwrite -noverify -noautoopen "$rw_name" | grep -E '^/dev/' | sed 1q | awk '{print $1}' ) - -# Set icon positions and background image -# Work around 'Finder got an error: Can’t get disk "Wireshark 3.1.1". (-1728)' -#sleep 5 -#osascript ../packaging/macosx/arrange_dmg.applescript || exit 1 - -# Have the disk image window open automatically when mounted. -bless -openfolder "/Volumes/$volume_name" - -# `hdiutil detach` sometimes fails with "Resource busy", possibly due to Spotlight. -# Give it a chance to finish up here and pass `-force` to hdiutil below. -sleep 5 - -# Unmount the disk image. -hdiutil detach "$DEV_NAME" - -# Create the offical release image by compressing the RW one. -echo -e "Compressing the final disk image" - -# TODO make this a command line option -if [ -e "$img_name" ]; then - echo "$img_name already exists." - rm -i "$img_name" -fi - -# From the hdiutil man page: -# UDZO - UDIF zlib-compressed image -# ULFO - UDIF lzfse-compressed image (OS X 10.11+ only) -# UDBZ - UDIF bzip2-compressed image (Mac OS X 10.4+ only) - -/usr/bin/hdiutil convert "$rw_name" -format UDBZ -o "$img_name" || exit 1 -rm -f "$rw_name" - -# TN2206, "Signing Disk Images" -if [ -n "$CODE_SIGN_IDENTITY" ] ; then - echo -e "Signing $img_name" - codesign \ - --sign "Developer ID Application: $CODE_SIGN_IDENTITY" \ - --timestamp \ - --verbose \ - "$img_name" - spctl --assess --type open --context context:primary-signature --verbose=2 "$img_name" || exit 1 -fi - -exit 0