From 2f8354f13466bcccb031953923b91918e6cacc97 Mon Sep 17 00:00:00 2001 From: Aylur Date: Wed, 22 May 2024 00:14:54 +0200 Subject: update meson format --- flake.lock | 6 ++-- meson.build | 5 ++++ meson_options.txt | 13 +++++++-- src/astal.vala | 6 ++-- src/cli.vala | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ src/client.vala.in | 79 ------------------------------------------------- src/config.vala.in | 6 ++++ src/meson.build | 86 +++++++++++++++++++++++++++++------------------------- 8 files changed, 152 insertions(+), 128 deletions(-) create mode 100644 src/cli.vala delete mode 100644 src/client.vala.in create mode 100644 src/config.vala.in diff --git a/flake.lock b/flake.lock index df4c399..e6e6355 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1715266358, - "narHash": "sha256-doPgfj+7FFe9rfzWo1siAV2mVCasW+Bh8I1cToAXEE4=", + "lastModified": 1716293225, + "narHash": "sha256-pU9ViBVE3XYb70xZx+jK6SEVphvt7xMTbm6yDIF4xPs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f1010e0469db743d14519a1efd37e23f8513d714", + "rev": "3eaeaeb6b1e08a016380c279f8846e0bd8808916", "type": "github" }, "original": { diff --git a/meson.build b/meson.build index 63de369..e5be5e2 100644 --- a/meson.build +++ b/meson.build @@ -14,4 +14,9 @@ project( # math add_project_arguments(['-X', '-lm'], language: 'vala') +assert( + get_option('lib') or get_option('cli'), + 'Either lib or cli option must be set to true.', +) + subdir('src') diff --git a/meson_options.txt b/meson_options.txt index 8eff355..f110242 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,11 @@ -option('typelib', type: 'boolean', value: true, description: 'Needed files for runtime bindings') -option('cli_client', type: 'boolean', value: true, description: 'Minimal cli client for Astal applications') +option( + 'lib', + type: 'boolean', + value: true, +) + +option( + 'cli', + type: 'boolean', + value: true, +) diff --git a/src/astal.vala b/src/astal.vala index e9d1484..fe6558c 100644 --- a/src/astal.vala +++ b/src/astal.vala @@ -97,14 +97,13 @@ public class Application : Gtk.Application { } try { - SocketAddress _; service = new SocketService(); service.add_address( new UnixSocketAddress(socket), SocketType.STREAM, SocketProtocol.DEFAULT, null, - out _); + null); service.incoming.connect((conn) => { _socket_request.begin(conn); @@ -151,8 +150,7 @@ public errordomain WindowError { public async string read_sock(SocketConnection conn) { try { var stream = new DataInputStream(conn.input_stream); - size_t size; - return yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, out size); + return yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, null); } catch (Error err) { critical(err.message); return err.message; diff --git a/src/cli.vala b/src/cli.vala new file mode 100644 index 0000000..82a99a4 --- /dev/null +++ b/src/cli.vala @@ -0,0 +1,79 @@ +private static bool version; +private static bool help; +private static string? instance_name; + +private const GLib.OptionEntry[] options = { + { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null }, + { "help", 'h', OptionFlags.NONE, OptionArg.NONE, ref help, null, null }, + { "instance-name", 'i', OptionFlags.NONE, OptionArg.STRING, ref instance_name, null, null }, + { null }, +}; + +async int main(string[] argv) { + try { + var opts = new OptionContext(); + opts.add_main_entries(options, null); + opts.set_help_enabled(false); + opts.set_ignore_unknown_options(false); + opts.parse(ref argv); + } catch (OptionError err) { + printerr (err.message); + return 1; + } + + if (help) { + print("Client for the socket of an Astal.Application instance\n\n"); + print("Usage:\n"); + print(" %s [flags] message\n\n", argv[0]); + print("Flags:\n"); + print(" -h, --help Print this help and exit\n"); + print(" -v, --version Print version number and exit\n"); + print(" -i, --instance-name Instance name of the Astal instance\n"); + return 0; + } + + if (version) { + print("@VERSION@"); + return 0; + } + + if (instance_name == null) + instance_name = "astal"; + + var request = ""; + for (var i = 1; i < argv.length; ++i) { + request = request.concat(" ", argv[i]); + } + + var client = new SocketClient(); + var rundir = GLib.Environment.get_user_runtime_dir(); + var socket = rundir.concat("/", instance_name, ".sock"); + + try { + var conn = client.connect(new UnixSocketAddress(socket), null); + + try { + yield conn.output_stream.write_async( + request.concat("\x04").data, + Priority.DEFAULT); + } catch (Error err) { + printerr("could not write to app '%s'", instance_name); + } + + var stream = new DataInputStream(conn.input_stream); + size_t size; + + try { + var res = yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, out size); + if (res != null) + print("%s", res); + } catch (Error err) { + printerr(err.message); + } + } catch (Error err) { + printerr("could not connect to app '%s'", instance_name); + return 1; + } + + return 0; +} diff --git a/src/client.vala.in b/src/client.vala.in deleted file mode 100644 index 82a99a4..0000000 --- a/src/client.vala.in +++ /dev/null @@ -1,79 +0,0 @@ -private static bool version; -private static bool help; -private static string? instance_name; - -private const GLib.OptionEntry[] options = { - { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null }, - { "help", 'h', OptionFlags.NONE, OptionArg.NONE, ref help, null, null }, - { "instance-name", 'i', OptionFlags.NONE, OptionArg.STRING, ref instance_name, null, null }, - { null }, -}; - -async int main(string[] argv) { - try { - var opts = new OptionContext(); - opts.add_main_entries(options, null); - opts.set_help_enabled(false); - opts.set_ignore_unknown_options(false); - opts.parse(ref argv); - } catch (OptionError err) { - printerr (err.message); - return 1; - } - - if (help) { - print("Client for the socket of an Astal.Application instance\n\n"); - print("Usage:\n"); - print(" %s [flags] message\n\n", argv[0]); - print("Flags:\n"); - print(" -h, --help Print this help and exit\n"); - print(" -v, --version Print version number and exit\n"); - print(" -i, --instance-name Instance name of the Astal instance\n"); - return 0; - } - - if (version) { - print("@VERSION@"); - return 0; - } - - if (instance_name == null) - instance_name = "astal"; - - var request = ""; - for (var i = 1; i < argv.length; ++i) { - request = request.concat(" ", argv[i]); - } - - var client = new SocketClient(); - var rundir = GLib.Environment.get_user_runtime_dir(); - var socket = rundir.concat("/", instance_name, ".sock"); - - try { - var conn = client.connect(new UnixSocketAddress(socket), null); - - try { - yield conn.output_stream.write_async( - request.concat("\x04").data, - Priority.DEFAULT); - } catch (Error err) { - printerr("could not write to app '%s'", instance_name); - } - - var stream = new DataInputStream(conn.input_stream); - size_t size; - - try { - var res = yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, out size); - if (res != null) - print("%s", res); - } catch (Error err) { - printerr(err.message); - } - } catch (Error err) { - printerr("could not connect to app '%s'", instance_name); - return 1; - } - - return 0; -} diff --git a/src/config.vala.in b/src/config.vala.in new file mode 100644 index 0000000..88bfe9c --- /dev/null +++ b/src/config.vala.in @@ -0,0 +1,6 @@ +namespace Astal { + public const int MAJOR_VERSION = @MAJOR_VERSION@; + public const int MINOR_VERSION = @MINOR_VERSION@; + public const int MICRO_VERSION = @MICRO_VERSION@; + public const string VERSION = "@VERSION@"; +} diff --git a/src/meson.build b/src/meson.build index 2227075..f6b0db0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,8 +1,19 @@ version_split = meson.project_version().split('.') api_version = version_split[0] + '.' + version_split[1] -astal_gir = 'Astal-' + api_version + '.gir' -astal_typelib = 'Astal-' + api_version + '.typelib' -astal_so = 'libastal.so.' + meson.project_version() +gir = 'Astal-' + api_version + '.gir' +typelib = 'Astal-' + api_version + '.typelib' +so = 'libastal.so.' + meson.project_version() + +config = configure_file( + input: 'config.vala.in', + output: 'config.vala', + configuration: { + 'VERSION': meson.project_version(), + 'MAJOR_VERSION': version_split[0], + 'MINOR_VERSION': version_split[1], + 'MICRO_VERSION': version_split[2], + }, +) deps = [ dependency('glib-2.0'), @@ -14,7 +25,8 @@ deps = [ dependency('gtk-layer-shell-0'), ] -sources = files( +sources = [ + config, 'widget/box.vala', 'widget/button.vala', 'widget/centerbox.vala', @@ -27,58 +39,52 @@ sources = files( 'process.vala', 'time.vala', 'variable.vala', -) +] -libastal = library( - meson.project_name(), - sources, - dependencies: deps, - vala_header: meson.project_name() + '.h', - vala_vapi: meson.project_name() + '.vapi', - vala_gir: astal_gir, - version: meson.project_version(), - install: true, - install_dir: [true, true, true, true], -) +if get_option('lib') + lib = library( + meson.project_name(), + sources, + dependencies: deps, + vala_header: meson.project_name() + '.h', + vala_vapi: meson.project_name() + '.vapi', + vala_gir: gir, + version: meson.project_version(), + install: true, + install_dir: [true, true, true, true], + ) -import('pkgconfig').generate( - description: 'libastal', - libraries: libastal, - name: meson.project_name(), - filebase: meson.project_name() + '-' + api_version, - version: meson.project_version(), - subdirs: meson.project_name(), - requires: 'gio-2.0', - install_dir: get_option('libdir') / 'pkgconfig', -) + import('pkgconfig').generate( + description: 'libastal-notifd', + libraries: lib, + name: meson.project_name(), + filebase: meson.project_name() + '-' + api_version, + version: meson.project_version(), + subdirs: meson.project_name(), + requires: deps, + install_dir: get_option('libdir') / 'pkgconfig', + ) -if get_option('typelib') custom_target( - astal_typelib, + typelib, command: [ find_program('g-ir-compiler'), '--output', '@OUTPUT@', '--shared-library', get_option('prefix') / get_option('libdir') / '@PLAINNAME@', - meson.current_build_dir() / astal_gir, + meson.current_build_dir() / gir, ], - input: libastal, - output: astal_typelib, - depends: libastal, + input: lib, + output: typelib, + depends: lib, install: true, install_dir: get_option('libdir') / 'girepository-1.0', ) endif -if get_option('cli_client') +if get_option('cli') executable( meson.project_name(), - configure_file( - input: 'client.vala.in', - output: 'client.vala', - configuration: { - 'VERSION': meson.project_version(), - }, - ), + ['cli.vala', sources], dependencies: deps, install: true, ) -- cgit v1.2.3