Build logic for installing Diffuse as a native macOS app

Tested on macOS 12.5:

  brew install meson python3 py3cairo pygobject3 gtk+3
  meson setup build
  cd build
  meson compile
  meson test
  meson install

After `meson install`, `diffuse` can be used to launch a
native Mac app that is installed into /Applications/Diffuse.app.

These steps could be put into a Homebrew formula, see
https://docs.brew.sh/Formula-Cookbook, as a way to
distribute Diffuse on macOS.
This commit is contained in:
Hugo Holgersson 2022-08-17 09:42:48 +02:00 committed by Romain Failliot
parent bb998a8785
commit 9a7ced4bc4
7 changed files with 110 additions and 1 deletions

View File

@ -128,6 +128,25 @@ sudo rm -v /usr/local/share/locale/*/LC_MESSAGES/diffuse.mo
Meson allows to change the default installation directories, see Meson allows to change the default installation directories, see
[command-line documentation](https://mesonbuild.com/Commands.html#configure). [command-line documentation](https://mesonbuild.com/Commands.html#configure).
## Setup on Mac OS
Building on Mac OS is similar to building on Linux. To recap, these are
the steps needed to build and install Diffuse manually:
```brew install meson python3 py3cairo pygobject3 gtk+3
meson setup build
cd build
meson compile
meson test
meson install
```
After `meson install`, the `diffuse` command can be used to launch Diffuse
as a native Mac app that is installed into `/Applications/Diffuse.app`.
The `diffuse` command is compatible with git. To use Diffuse as git's
`git difftool` run `git config --global diff.tool diffuse`
## Setup on Windows ## Setup on Windows
_Note:_ The Windows port is not maintained and would need some love. _Note:_ The Windows port is not maintained and would need some love.

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>mac_launcher.sh</string>
<key>CFBundleIconFile</key>
<string>diffuse.icns</string>
<key>CFBundleIdentifier</key>
<string>io.github.mightycreak.Diffuse</string>
<key>CFBundleName</key>
<string>Diffuse</string>
<key>CFBundleShortVersionString</key>
<string>@VERSION@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSAppleScriptEnabled</key>
<string>NO</string>
</dict>
</plist>

View File

@ -0,0 +1,14 @@
#!/bin/bash
#
# This is the command-line entry point on Mac.
#
# We want to use Mac's `open` command for mainly two reasons;
# a) open lets us choose our own icon.
# b) open puts the app on top of the other windows, including the terminal we ran this from.
#
# --new lets us open multiple windows.
# --wait-apps lets Diffuse be a "git difftool", letting Diffuse run before git deletes its tmp files.
#
# We pass "pwd" because Mac's `open` command launches processes at '/'.
# "printf %q" escapes spaces and other characters so the complete dir is passed as one.
open /Applications/Diffuse.app --new --wait-apps --args $(printf %q "$(pwd)") $@

View File

@ -0,0 +1,7 @@
#!/bin/bash
# Mac's `open` command resets working dir. This extra script only
# does `cd` back to the dir from which `diffuse` was launched to
# allow Python to pick up any relative paths given by `git difftool`.
cd $1
@BINDIR@/diffuse_impl ${@:2}

View File

@ -9,15 +9,42 @@ conf.set('VERSION', meson.project_version())
conf.set('PKGDATADIR', pkgdatadir) conf.set('PKGDATADIR', pkgdatadir)
conf.set('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('SYSCONFIGDIR', join_paths(get_option('prefix'), get_option('sysconfdir'))) conf.set('SYSCONFIGDIR', join_paths(get_option('prefix'), get_option('sysconfdir')))
conf.set('BINDIR', join_paths(get_option('prefix'), get_option('bindir')))
configure_file( configure_file(
input: 'diffuse.in', input: 'diffuse.in',
output: 'diffuse', output: build_machine.system() == 'darwin' ? 'diffuse_impl' : 'diffuse',
configuration: conf, configuration: conf,
install: true, install: true,
install_dir: get_option('bindir') install_dir: get_option('bindir')
) )
if build_machine.system() == 'darwin'
install_subdir('mac-os-app/Diffuse.app', install_dir: '/Applications', strip_directory: false)
configure_file(
input: 'mac-os-app/diffuse-mac.in',
output: 'diffuse',
configuration: conf,
install: true,
install_dir: get_option('bindir')
)
configure_file(
input: 'mac-os-app/mac_launcher.sh.in',
output: 'mac_launcher.sh',
configuration: conf,
install: true,
install_dir: '/Applications/Diffuse.app/Contents/MacOS'
)
configure_file(
input: 'mac-os-app/Info.plist.in',
output: 'Info.plist',
configuration: conf,
install: true,
install_dir: '/Applications/Diffuse.app/Contents'
)
endif
diffuse_sources = [ diffuse_sources = [
'__init__.py', '__init__.py',
'constants.py', 'constants.py',

20
utils/makemacicon.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Use this tool if you need to re-create
# Diffuse.app/Contents/Resources/diffuse.icns
# in case the icon changes (unlikely).
sizes=(16 32 64 128 256 512)
for s in "${sizes[@]}"; do
echo $s
rsvg-convert -h $s "$1" > "icon_${s}x$s.png"
done
cp 'icon_32x32.png' 'icon_16x16@2x.png'
cp 'icon_64x64.png' 'icon_32x32@2x.png'
cp 'icon_256x256.png' 'icon_128x128@2x.png'
cp 'icon_512x512.png' 'icon_256x256@2x.png'
mkdir icon.iconset
mv icon_*x*.png icon.iconset
iconutil -c icns icon.iconset