Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to a modern build system (meson) #102

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
14 changes: 8 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libmpv-dev libglib2.0-dev libavformat-dev
sudo apt install libmpv-dev libglib2.0-dev libavformat-dev meson ninja-build

- name: Checkout
uses: actions/checkout@v3

- name: Build
run: |
make
mkdir build
meson setup build
ninja -C build

- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: mpris.so
path: mpris.so
path: build/libmpris.so
if-no-files-found: error

- name: Prepare for test
Expand All @@ -34,7 +36,7 @@ jobs:

- name: Run tests
run: |
make test
ninja -C build test

- name: Check git files unmodified
run: |
Expand All @@ -46,8 +48,8 @@ jobs:

- name: Cleanup generated files
run: |
make clean
ninja -C build clean

- name: Check cleanup removed generated files
run: |
! git ls-files --others | grep .
! git ls-files --others | grep . | grep -v build/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
compile_commands.json
.ccls-cache/
build/
mpris.so
*.mpv.ipc.input.json
*.mpv.ipc.output.json
Expand Down
63 changes: 0 additions & 63 deletions Makefile

This file was deleted.

25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ Packages are available for many [distributions](https://repology.org/project/mpv
For 64-bit x86 Linux a pre-built version is [available here](https://github.com/hoyon/mpv-mpris/releases)
and can be copied into one of the mpv scripts directories documented above.

A self-built `mpris.so` file can be installed with `make install` and will
be installed to the appropriate mpv scripts directory for your current user
or to the mpv system wide scripts directory for all users when you install as root.

## Build

Build requirements:
Expand All @@ -45,8 +41,24 @@ Build requirements:
- glib development files
- gio development files
- libavformat development files
- meson build

Building is very simple using meson
```sh
mkdir build
meson setup build
ninja -C build
sudo ninja -C build install
```

If you don't want to install the plugin to the system, this is how you install the plugin to the user scripts directory
```sh
mkdir build
meson setup build -Dinstall_user=true
ninja -C build
ninja -C build install
```

Building should be as simple as running `make` in the source code directory.

## Test

Expand All @@ -62,8 +74,9 @@ Test requirements:
- jq (for mpv IPC JSON generation and parsing)
- socat (for passing JSON to/from mpv IPC sockets)
- awk (for redirecting parts of mpv stderr logs)
- meson build (the backend for actually running the tests)

Testing should be as simple as running `make test` in the source code directory.
Testing should be as simple as running `ninja test` in the build directory, or `ninja -C build test` in the source directory.

The stderr of the tests will be empty unless there are mpv/etc issues.

Expand Down
39 changes: 39 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
project('mpv-mpris', 'c', version: '1.1', default_options: [
'c_std=c99',
'warning_level=3',
])

gio = dependency('gio-2.0')
gio_unix = dependency('gio-unix-2.0')
glib = dependency('glib-2.0')
mpv = dependency('mpv')
ffmpeg = dependency('libavformat')

fs = import('fs')

if get_option('install_user')
lib_install_dir = fs.expanduser(get_option('scripts_dir'))
else
lib_install_dir = join_paths(get_option('prefix'), get_option('libdir'), get_option('plugindir'))
endif

mpris_lib = library(
'mpris',
'mpris.c',
pic: true,
install_dir: lib_install_dir,
install: true,
dependencies: [
gio,
gio_unix,
glib,
mpv,
ffmpeg
]
)

if not get_option('install_user')
install_symlink('mpris.so', pointing_to: join_paths(lib_install_dir, fs.name(mpris_lib.full_path())), install_dir: get_option('sys_scripts_dir'))
endif

subdir('test')
4 changes: 4 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
option('plugindir', type : 'string', value : 'mpv-mpris')
option('sys_scripts_dir', type : 'string', value : '/etc/mpv/scripts')
option('scripts_dir', type : 'string', value : '~/.config/mpv/scripts')
option('install_user', type : 'boolean', value : false)
30 changes: 0 additions & 30 deletions test/Makefile

This file was deleted.

6 changes: 6 additions & 0 deletions test/clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

rm -f \
*.mpv.ipc* \
*.Xauthority \
rm -rf dbus
5 changes: 2 additions & 3 deletions test/env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test="$(basename "$1")"


if [ -z "${MPV_MPRIS_TEST_PLUGIN+set}" ] ; then
export MPV_MPRIS_TEST_PLUGIN=../mpris.so
export MPV_MPRIS_TEST_PLUGIN=$4
fi

if [ -z "$MPV_MPRIS_TEST_PLAY" ] ; then
Expand All @@ -24,7 +24,7 @@ if [ -z "$MPV_MPRIS_TEST_MPV_IPC" ] ; then
fi

if [ -z "$MPV_MPRIS_TEST_LOG" ] ; then
export MPV_MPRIS_TEST_LOG=.
export MPV_MPRIS_TEST_LOG=meson-logs
fi

if [ -z "$MPV_MPRIS_TEST_DBUS" ] ; then
Expand Down Expand Up @@ -107,6 +107,5 @@ TEMPDIR="$MPV_MPRIS_TEST_TMP" \
TMPDIR="$MPV_MPRIS_TEST_TMP" \
TEMP="$MPV_MPRIS_TEST_TMP" \
TMP="$MPV_MPRIS_TEST_TMP" \
dbus-run-session -- \
xvfb-run "$xvfb_auto" --error-file "$MPV_MPRIS_TEST_LOG/$test.xvfb.log" -f "$MPV_MPRIS_TEST_XAUTH/$test.Xauthority" \
"$@"
19 changes: 19 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
metadata_test = find_program('metadata')
pause_test = find_program('pause')
play_test = find_program('play')
play_pause_test = find_program('play-pause')
stop_test = find_program('stop')
quit_test = find_program('quit')
wrapper = find_program('dbus-run-session')
setup = find_program('setup')
env = find_program('env')
clean = find_program('clean')

# All new tests should have a priority of 1, this way the `clean-tests` test runs *after* everything else
test('metadata-test', wrapper, args: ['--', metadata_test.full_path(), setup.full_path(), env.full_path(), mpris_lib.full_path()], timeout: 60, priority: 1)
test('pause-test', wrapper, args: ['--', pause_test.full_path(), setup.full_path(), env.full_path(), mpris_lib.full_path()], timeout: 60, priority: 1)
test('play-test', wrapper, args: ['--', play_test.full_path(), setup.full_path(), env.full_path(), mpris_lib.full_path()], timeout: 60, priority: 1)
test('play-pause-test', wrapper, args: ['--', play_pause_test.full_path(), setup.full_path(), env.full_path(), mpris_lib.full_path()], timeout: 60, priority: 1)
test('stop-test', wrapper, args: ['--', stop_test.full_path(), setup.full_path(), env.full_path(), mpris_lib.full_path()], timeout: 60, priority: 1)
test('quit-test', wrapper, args: ['--', quit_test.full_path(), setup.full_path(), env.full_path(), mpris_lib.full_path()], timeout: 60, priority: 1)
test('clean-tests', clean, is_parallel: false, priority: 0)
2 changes: 1 addition & 1 deletion test/metadata
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. ./setup
. $1

test "$(playerctl metadata xesam:url)" = "file://$file"

Expand Down
2 changes: 1 addition & 1 deletion test/pause
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. ./setup
. $1

status Playing
check pause false
Expand Down
2 changes: 1 addition & 1 deletion test/play
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pause=1

. ./setup
. $1

status Paused
check pause true
Expand Down
2 changes: 1 addition & 1 deletion test/play-pause
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pause=1

. ./setup
. $1

status Paused
check pause true
Expand Down
4 changes: 3 additions & 1 deletion test/setup
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

set -e


Expand All @@ -7,7 +9,7 @@ set -x


test -n "$MPV_MPRIS_TEST_NAME" ||
exec "./env" "$0" "$@"
exec "$2" "$0" "$@"


test="$(basename "$0")"
Expand Down
2 changes: 1 addition & 1 deletion test/stop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pause=1

. ./setup
. $1

status Paused
check pause true
Expand Down
Loading