Skip to content

Commit 9a7ced4

Browse files
hugoholgerssonMightyCreak
authored andcommitted
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.
1 parent bb998a8 commit 9a7ced4

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

docs/developers/developers-setup.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ sudo rm -v /usr/local/share/locale/*/LC_MESSAGES/diffuse.mo
128128
Meson allows to change the default installation directories, see
129129
[command-line documentation](https://mesonbuild.com/Commands.html#configure).
130130

131+
## Setup on Mac OS
132+
133+
Building on Mac OS is similar to building on Linux. To recap, these are
134+
the steps needed to build and install Diffuse manually:
135+
136+
```brew install meson python3 py3cairo pygobject3 gtk+3
137+
meson setup build
138+
cd build
139+
meson compile
140+
meson test
141+
meson install
142+
```
143+
144+
After `meson install`, the `diffuse` command can be used to launch Diffuse
145+
as a native Mac app that is installed into `/Applications/Diffuse.app`.
146+
147+
The `diffuse` command is compatible with git. To use Diffuse as git's
148+
`git difftool` run `git config --global diff.tool diffuse`
149+
131150
## Setup on Windows
132151

133152
_Note:_ The Windows port is not maintained and would need some love.
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>mac_launcher.sh</string>
9+
<key>CFBundleIconFile</key>
10+
<string>diffuse.icns</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>io.github.mightycreak.Diffuse</string>
13+
<key>CFBundleName</key>
14+
<string>Diffuse</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>@VERSION@</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>NSAppleScriptEnabled</key>
20+
<string>NO</string>
21+
</dict>
22+
</plist>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#
3+
# This is the command-line entry point on Mac.
4+
#
5+
# We want to use Mac's `open` command for mainly two reasons;
6+
# a) open lets us choose our own icon.
7+
# b) open puts the app on top of the other windows, including the terminal we ran this from.
8+
#
9+
# --new lets us open multiple windows.
10+
# --wait-apps lets Diffuse be a "git difftool", letting Diffuse run before git deletes its tmp files.
11+
#
12+
# We pass "pwd" because Mac's `open` command launches processes at '/'.
13+
# "printf %q" escapes spaces and other characters so the complete dir is passed as one.
14+
open /Applications/Diffuse.app --new --wait-apps --args $(printf %q "$(pwd)") $@
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Mac's `open` command resets working dir. This extra script only
4+
# does `cd` back to the dir from which `diffuse` was launched to
5+
# allow Python to pick up any relative paths given by `git difftool`.
6+
cd $1
7+
@BINDIR@/diffuse_impl ${@:2}

src/diffuse/meson.build

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,42 @@ conf.set('VERSION', meson.project_version())
99
conf.set('PKGDATADIR', pkgdatadir)
1010
conf.set('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
1111
conf.set('SYSCONFIGDIR', join_paths(get_option('prefix'), get_option('sysconfdir')))
12+
conf.set('BINDIR', join_paths(get_option('prefix'), get_option('bindir')))
1213

1314
configure_file(
1415
input: 'diffuse.in',
15-
output: 'diffuse',
16+
output: build_machine.system() == 'darwin' ? 'diffuse_impl' : 'diffuse',
1617
configuration: conf,
1718
install: true,
1819
install_dir: get_option('bindir')
1920
)
2021

22+
if build_machine.system() == 'darwin'
23+
install_subdir('mac-os-app/Diffuse.app', install_dir: '/Applications', strip_directory: false)
24+
25+
configure_file(
26+
input: 'mac-os-app/diffuse-mac.in',
27+
output: 'diffuse',
28+
configuration: conf,
29+
install: true,
30+
install_dir: get_option('bindir')
31+
)
32+
configure_file(
33+
input: 'mac-os-app/mac_launcher.sh.in',
34+
output: 'mac_launcher.sh',
35+
configuration: conf,
36+
install: true,
37+
install_dir: '/Applications/Diffuse.app/Contents/MacOS'
38+
)
39+
configure_file(
40+
input: 'mac-os-app/Info.plist.in',
41+
output: 'Info.plist',
42+
configuration: conf,
43+
install: true,
44+
install_dir: '/Applications/Diffuse.app/Contents'
45+
)
46+
endif
47+
2148
diffuse_sources = [
2249
'__init__.py',
2350
'constants.py',

utils/makemacicon.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# Use this tool if you need to re-create
4+
# Diffuse.app/Contents/Resources/diffuse.icns
5+
# in case the icon changes (unlikely).
6+
7+
sizes=(16 32 64 128 256 512)
8+
for s in "${sizes[@]}"; do
9+
echo $s
10+
rsvg-convert -h $s "$1" > "icon_${s}x$s.png"
11+
done
12+
13+
cp 'icon_32x32.png' '[email protected]'
14+
cp 'icon_64x64.png' '[email protected]'
15+
cp 'icon_256x256.png' '[email protected]'
16+
cp 'icon_512x512.png' '[email protected]'
17+
18+
mkdir icon.iconset
19+
mv icon_*x*.png icon.iconset
20+
iconutil -c icns icon.iconset

0 commit comments

Comments
 (0)