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

chore(linux): improve compatibility with Gentoo Linux 🏠 #12889

Open
wants to merge 2 commits into
base: stable-17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion linux/ibus-keyman/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ conf = configuration_data()
ibus = dependency('ibus-1.0', version: '>= 1.2.0')
gtk = dependency('gtk+-3.0', version: '>= 2.4')
json_glib = dependency('json-glib-1.0', version: '>= 1.0')
systemd = dependency('libsystemd')
icu = dependency('icu-i18n')

systemd = dependency('libsystemd', 'libelogind', required: false)
if systemd.found()
conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD')
else
# Gentoo can use libelogind or basu
systemd = dependency('basu', required: true)
conf.set('DBUS_IMPLEMENTATION', 'BASU')
endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a failure if none of these are available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the dependency function has an implicit required: true parameter. But probably good to add it anyways to make it clearer.


core_dir = meson.current_source_dir() / '../../core'
common_dir = meson.current_source_dir() / '../../common'

Expand Down
5 changes: 5 additions & 0 deletions linux/ibus-keyman/src/KeymanSystemServiceClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "config.h"
#include <cassert>
#if DBUS_IMPLEMENTATION == SYSTEMD
#include <systemd/sd-bus.h>
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to check #elif DBUS_IMPLEMENTATION == BASU?

For all the other .cpp and .h files too...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's necessary since SYSTEMD and BASU are the only two values we set.

#include <basu/sd-bus.h>
#endif
#include "KeymanSystemServiceClient.h"

#define KEYMAN_BUS_NAME "com.keyman.SystemService1"
Expand Down
10 changes: 9 additions & 1 deletion linux/ibus-keyman/tests/KmDbusTestServer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// DBus test server. The server will start and listen on a non-standard DBus.
// It runs until the DBus Exit method gets called.
#include "config.h"
#include <fstream>
#include <gio/gio.h>
#include <iostream>
#if DBUS_IMPLEMENTATION == SYSTEMD
#include <systemd/sd-bus.h>
#else
#include <basu/sd-bus.h>
#endif

#ifndef KEYMAN_TEST_SERVICE_PATH
#warning KEYMAN_TEST_SERVICE_PATH is undefined
Expand Down Expand Up @@ -73,7 +78,10 @@ KmDbusTestServer::~KmDbusTestServer()
{
if (bus) sd_bus_release_name(bus, KEYMAN_TESTSVC_BUS_NAME);
if (slot) sd_bus_slot_unref(slot);
if (bus) sd_bus_close_unref(bus);
if (bus) {
sd_bus_close(bus);
sd_bus_unref(bus);
}

g_test_dbus_down(dbus);
g_object_unref(dbus);
Expand Down
5 changes: 5 additions & 0 deletions linux/ibus-keyman/tests/StopTestServer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Call the Exit method on the km-dbus-test-server. Remember to source
// `/tmp/km-test-server.env` prior to running stop-test-server in order
// to run on our non-standard DBus.
#include "config.h"
#include <iostream>
#if DBUS_IMPLEMENTATION == SYSTEMD
#include <systemd/sd-bus.h>
#else
#include <basu/sd-bus.h>
#endif

using namespace std;

Expand Down
2 changes: 2 additions & 0 deletions linux/ibus-keyman/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dbus_test_server = executable(
'km-dbus-test-server',
'KmDbusTestServer.cpp',
dependencies: dbus_deps,
include_directories: ['..'],
cpp_args: [
'-DKEYMAN_TEST_SERVICE_PATH="' + system_service_dir + '"'
]
Expand All @@ -47,6 +48,7 @@ stop_test_server = executable(
'stop-test-server',
'StopTestServer.cpp',
dependencies: dbus_deps,
include_directories: ['..'],
)

env_file = '/tmp/env.txt'
Expand Down
15 changes: 14 additions & 1 deletion linux/keyman-system-service/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ project('keyman-system-service', 'c', 'cpp',
license: 'GPL-2+',
meson_version: '>=0.61')

conf = configuration_data()

evdev = dependency('libevdev', version: '>= 1.9')
systemd = dependency('libsystemd')

systemd = dependency('libsystemd', 'libelogind', required: false)
if systemd.found()
conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD')
else
# Gentoo can use libelogind or basu
systemd = dependency('basu', required: true)
conf.set('DBUS_IMPLEMENTATION', 'BASU')
endif

configure_file(output : 'config.h',
configuration : conf)

subdir('resources')
subdir('src')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# /usr/share/dbus-1/system-services/com.keyman.SystemService1.service
# This version used with elogind and basu (e.g. on Gentoo)

[D-BUS Service]
Name=com.keyman.SystemService1
Exec=/usr/libexec/systemd-keyman.service
User=root
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# /usr/share/dbus-1/system-services/com.keyman.SystemService1.service
# This version used with systemd (e.g. on Debian)

[D-BUS Service]
Name=com.keyman.SystemService1
Expand Down
9 changes: 8 additions & 1 deletion linux/keyman-system-service/resources/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
install_data('com.keyman.SystemService1.conf', install_dir: get_option('datadir') / 'dbus-1/system.d/')
install_data('com.keyman.SystemService1.service', install_dir: get_option('datadir') / 'dbus-1/system-services/')

if systemd.name() == 'libsystemd'
install_data('com.keyman.SystemService1.service.systemd', install_dir: get_option('datadir') / 'dbus-1/system-services/', rename: ['com.keyman.SystemService1.service'])
else
# libelogind or basu
install_data('com.keyman.SystemService1.service.basu', install_dir: get_option('datadir') / 'dbus-1/system-services/')
endif

install_data('systemd-keyman.service', install_dir: get_option('prefix') / 'lib/systemd/system/')
5 changes: 5 additions & 0 deletions linux/keyman-system-service/src/KeymanSystemService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// based on the sd-bus library, see
// https://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html

#include "config.h"
#include <cstdint>
#include <dirent.h>
#include <errno.h>
Expand All @@ -11,7 +12,11 @@
#include <string.h>
#include <sys/types.h>
#include <syslog.h>
#if DBUS_IMPLEMENTATION == SYSTEMD
#include <systemd/sd-bus.h>
#else
#include <basu/sd-bus.h>
#endif
#include "KeymanSystemService.h"
#include "KeyboardDevice.h"

Expand Down
5 changes: 5 additions & 0 deletions linux/keyman-system-service/src/KeymanSystemService.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef __KEYMANSYSTEMSERVICE_H__
#define __KEYMANSYSTEMSERVICE_H__

#include "config.h"
#include <list>
#if DBUS_IMPLEMENTATION == SYSTEMD
#include <systemd/sd-bus.h>
#else
#include <basu/sd-bus.h>
#endif
#include "KeyboardDevice.h"

using namespace std;
Expand Down
1 change: 1 addition & 0 deletions linux/keyman-system-service/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exe = executable(
'keyman-system-service',
sources: [service_files],
dependencies: deps,
include_directories: ['..'],
install: true,
install_dir: get_option('libexecdir'),
)
Expand Down
2 changes: 1 addition & 1 deletion linux/keyman-system-service/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exe = executable(
c_args: test_c_args,
cpp_args: test_c_args,
dependencies: deps,
include_directories: [ '../src' ]
include_directories: [ '..', '../src' ]
)

# we currently don't have any unit tests for keyman-system-service.
Expand Down