From a55f734f4733f1ae3da9a436a7c43f659e93e06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 25 Jul 2018 19:02:40 +0200 Subject: [PATCH 1/7] build: Add config header So far we've just passed the defines we need directly to the compiler, but as we'll soon add some more configuration, it makes senses to start adding a config.h. https://gitlab.gnome.org/GNOME/polari/issues/61 --- meson.build | 20 +++++++++++++++++--- src/meson.build | 10 +--------- src/polari.c | 2 ++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index 6089d55c..d969d955 100644 --- a/meson.build +++ b/meson.build @@ -39,10 +39,24 @@ telepathy_glib = dependency('telepathy-glib') girepository = dependency('gobject-introspection-1.0') gjs = dependency('gjs-1.0') +conf = configuration_data() + +conf.set_quoted('PACKAGE_NAME', meson.project_name()) +conf.set_quoted('PACKAGE_VERSION', meson.project_version()) +conf.set_quoted('PREFIX', prefix) +conf.set_quoted('LIBDIR', libdir) +conf.set_quoted('PKGLIBDIR', pkglibdir) + cc = meson.get_compiler('c') -if (cc.has_function('strcasestr')) - add_project_arguments('-DHAVE_STRCASECSTR', language: 'c') -endif +conf.set10('HAVE_STRCASESTR', cc.has_function('strcasestr')) + +config_h = declare_dependency( + sources: configure_file( + configuration: conf, + output: 'config.h' + ), + include_directories: include_directories('.') +) subdir('src') subdir('data') diff --git a/src/meson.build b/src/meson.build index 45e95f28..32df375e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -59,16 +59,8 @@ src_resources = gnome.compile_resources( c_name: 'src_resources' ) -exeargs = [ - '-DPACKAGE_NAME="polari"', - '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()), - '-DPREFIX="@0@"'.format(prefix), - '-DLIBDIR="@0@"'.format(libdir), - '-DPKGLIBDIR="@0@"'.format(pkglibdir) -] polari = executable('polari', ['polari.c', src_resources, data_resources], - dependencies: [gio, girepository, gjs], - c_args: exeargs, + dependencies: [config_h, gio, girepository, gjs], install: true ) diff --git a/src/polari.c b/src/polari.c index 30f43675..eedf0a4b 100644 --- a/src/polari.c +++ b/src/polari.c @@ -1,6 +1,8 @@ #include #include +#include "config.h" + G_DEFINE_AUTOPTR_CLEANUP_FUNC (GjsContext, g_object_unref) const char *src = -- GitLab From b4314799859a23502363e7db996b495ae50936ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 25 Jul 2018 17:55:15 +0200 Subject: [PATCH 2/7] main: Split out ARGV conversion By convention (and the example set by gjs-console), the javascript code has access to a global ARGV variable that holds the actual command line options (that is, ARGV[0] is not the executable from argv[0]). We currently handle that with some pointer arithmetic on argv itself, but as we are about to do some semi-evil command line manipulation, it makes sense to copy the relevant elements from the original argv into a NULL-terminated string array. https://gitlab.gnome.org/GNOME/polari/issues/61 --- src/polari.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/polari.c b/src/polari.c index eedf0a4b..299f9848 100644 --- a/src/polari.c +++ b/src/polari.c @@ -11,6 +11,19 @@ const char *src = " prefix: '" PREFIX "'," " libdir: '" LIBDIR "' });"; +static char ** +get_js_argv (int argc, const char * const *argv) +{ + char **strv; + int js_argc = argc - 1; // gjs doesn't do argv[0] + int i; + + strv = g_new0 (char *, js_argc + 1); + for (i = 0; i < js_argc; i++) + strv[i] = g_strdup (argv[i + 1]); + return strv; +} + int main (int argc, char *argv[]) { @@ -18,6 +31,7 @@ main (int argc, char *argv[]) g_autoptr (GOptionContext) option_context = NULL; g_autoptr (GError) error = NULL; g_autoptr (GjsContext) context = NULL; + g_auto (GStrv) js_argv = NULL; gboolean debugger = FALSE; int status; @@ -43,8 +57,10 @@ main (int argc, char *argv[]) if (debugger) gjs_context_setup_debugger_console (context); + js_argv = get_js_argv (argc, (const char * const *)argv); + if (!gjs_context_define_string_array (context, "ARGV", - argc - 1, (const char **)argv + 1, + -1, (const char **)js_argv, &error)) { g_message ("Failed to define ARGV: %s", error->message); -- GitLab From 90b6c575a561e8ca75f005f5bfca23c00e33eac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 25 Jul 2018 18:05:38 +0200 Subject: [PATCH 3/7] build: Add support for 'snapshot' builds Our CI now generates flatpak bundles on successful builds, which are intended for conveniently testing proposed changes with just a couple of clicks. However for now we still miss that goal, due to two important restrictions: - the bundle uses the same ID/branch as the nightly build, so it can conflict or interfere with the installation - if Polari is already running in the session, the bundle has to be launched manually with --test-instance to work We will be able to address the former by adjusting the CI script to use a dedicated branch, but to address the latter, we need explicit support in the app. Add that in form of a compile time option for producing development snapshots, which injects --test-instance into the command line. https://gitlab.gnome.org/GNOME/polari/issues/61 --- meson.build | 1 + meson_options.txt | 5 +++++ src/polari.c | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 meson_options.txt diff --git a/meson.build b/meson.build index d969d955..98920117 100644 --- a/meson.build +++ b/meson.build @@ -49,6 +49,7 @@ conf.set_quoted('PKGLIBDIR', pkglibdir) cc = meson.get_compiler('c') conf.set10('HAVE_STRCASESTR', cc.has_function('strcasestr')) +conf.set10('SNAPSHOT', get_option('snapshot')) config_h = declare_dependency( sources: configure_file( diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..74573004 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,5 @@ +option('snapshot', + type: 'boolean', + value: false, + description: 'Build development snapshot' +) diff --git a/src/polari.c b/src/polari.c index 299f9848..d3dc4293 100644 --- a/src/polari.c +++ b/src/polari.c @@ -14,13 +14,21 @@ const char *src = static char ** get_js_argv (int argc, const char * const *argv) { + char * injected_args[] = { +#ifdef SNAPSHOT + "--test-instance", +#endif + NULL + }; char **strv; int js_argc = argc - 1; // gjs doesn't do argv[0] int i; - strv = g_new0 (char *, js_argc + 1); + strv = g_new0 (char *, js_argc + G_N_ELEMENTS (injected_args) + 1); for (i = 0; i < js_argc; i++) strv[i] = g_strdup (argv[i + 1]); + for (i = 0; i < G_N_ELEMENTS (injected_args); i++) + strv[js_argc + i] = g_strdup (injected_args[i]); return strv; } -- GitLab From c993e4bfba1de42ce73a51e19933eb207c84d985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 25 Jul 2018 18:05:38 +0200 Subject: [PATCH 4/7] main: Identify snapshot builds in About Development snapshots are different from regularly installed versions, even from nightly builds, as they may be built from code that hasn't even been merged to master yet (and maybe never will). Reflect that by setting an appropriate application name. https://gitlab.gnome.org/GNOME/polari/issues/61 --- src/application.js | 1 - src/polari.c | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/application.js b/src/application.js index dc07080d..65f04ae3 100644 --- a/src/application.js +++ b/src/application.js @@ -29,7 +29,6 @@ var Application = GObject.registerClass({ super._init({ application_id: 'org.gnome.Polari', flags: Gio.ApplicationFlags.HANDLES_OPEN }); - GLib.set_application_name('Polari'); GLib.set_prgname('polari'); this._retryData = new Map(); this._nickTrackData = new Map(); diff --git a/src/polari.c b/src/polari.c index d3dc4293..9804f5e8 100644 --- a/src/polari.c +++ b/src/polari.c @@ -49,6 +49,12 @@ main (int argc, char *argv[]) { NULL } }; +#ifdef SNAPSHOT + g_set_application_name ("Polari Development Snapshot"); +#else + g_set_application_name ("Polari"); +#endif + g_irepository_prepend_search_path (PKGLIBDIR); context = g_object_new (GJS_TYPE_CONTEXT, -- GitLab From 56505cf8ca2403a4992e67eb340d39d154f13ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 30 Jul 2018 00:48:03 +0200 Subject: [PATCH 5/7] build: Include VCS tag in version This is useful information to include in development snapshots, so use the output of `git-describe` as version when building from git. For stable releases there is no change, as they are either build from a tag (where `git describe` simply returns the tag name) or from a tarball (where there's a fallback to meson.project_version()). https://gitlab.gnome.org/GNOME/polari/issues/61 --- meson.build | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 98920117..9f913f46 100644 --- a/meson.build +++ b/meson.build @@ -42,7 +42,7 @@ gjs = dependency('gjs-1.0') conf = configuration_data() conf.set_quoted('PACKAGE_NAME', meson.project_name()) -conf.set_quoted('PACKAGE_VERSION', meson.project_version()) +conf.set_quoted('PACKAGE_VERSION', '@VCS_TAG@') conf.set_quoted('PREFIX', prefix) conf.set_quoted('LIBDIR', libdir) conf.set_quoted('PKGLIBDIR', pkglibdir) @@ -52,8 +52,12 @@ conf.set10('HAVE_STRCASESTR', cc.has_function('strcasestr')) conf.set10('SNAPSHOT', get_option('snapshot')) config_h = declare_dependency( - sources: configure_file( - configuration: conf, + sources: vcs_tag( + command: ['git', 'describe'], + input: configure_file( + configuration: conf, + output: 'config.h.in' + ), output: 'config.h' ), include_directories: include_directories('.') -- GitLab From c4ebeda270d366767bc66fcaf254207fa2768fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 30 Jul 2018 03:15:52 +0200 Subject: [PATCH 6/7] window: Add a visual hint when running a snapshot build As outlined in the DevOps-with-Flatpak initiative[0], it is important that development versions are instantly recognizable as such, similar to the style hint for test instance we added in commit aaec4ee. However the existing hint is only added when a test instance is actually running along-side a regular one, so it is not enough to identify a snapshot build in all cases. For that, add a different visual hint for snapshots and make sure it complements the existing hint if both are applied. [0] https://gitlab.gnome.org/GNOME/Initiatives/wikis/DevOps-with-Flatpak https://gitlab.gnome.org/GNOME/polari/issues/61 --- data/resources/application.css | 12 ++++++++++-- src/mainWindow.js | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/data/resources/application.css b/data/resources/application.css index 6c0f72fb..3af920da 100644 --- a/data/resources/application.css +++ b/data/resources/application.css @@ -209,9 +209,17 @@ treeview.polari-server-room-list { /* Differentiate test instance from "normal" ones */ window.test-instance headerbar:last-child { - background-image: -gtk-icontheme('system-run-symbolic'); - background-blend-mode: color-burn; + background-image: cross-fade(25% -gtk-icontheme('system-run-symbolic')); background-repeat: no-repeat; background-position: 1em center; background-size: 4em; } + +/* Differentiate snapshot builds from regular ones */ +window.snapshot headerbar { background: none; } +window.snapshot .titlebar { + background: linear-gradient(to left, #a5b1bd 0%, #a5b1bd 8%, @theme_bg_color 25%); + box-shadow: inset 0 1px #f1f3f5; + border-color: #909fae; + color: alpha(@theme_fg_color, 0.4); +} diff --git a/src/mainWindow.js b/src/mainWindow.js index f5d87975..b5a80361 100644 --- a/src/mainWindow.js +++ b/src/mainWindow.js @@ -134,6 +134,8 @@ var MainWindow = GObject.registerClass({ if (app.isTestInstance) this.get_style_context().add_class('test-instance'); + if (GLib.get_application_name().toLowerCase().includes('snapshot')) + this.get_style_context().add_class('snapshot'); // command output notifications should not pop up over // the input area, but appear to emerge from it, so -- GitLab From fc39327b26b702237b2738006dfe31f7fc59883b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 25 Jul 2018 19:15:11 +0200 Subject: [PATCH 7/7] ci: Build flatpak bundle as snapshot With everything in place, update the flatpak CI job to use a 'snapshot' build in the produced bundle, and make it available as org.gnome.Polari/snapshot to avoid conflicts with the night- ly flatpak. https://gitlab.gnome.org/GNOME/polari/issues/61 --- .gitlab-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e0768b36..28f9ce98 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,9 +13,10 @@ flatpak: MANIFEST_PATH: "flatpak/org.gnome.Polari.json" RUNTIME_REPO: "https://sdk.gnome.org/gnome-nightly.flatpakrepo" FLATPAK_MODULE: "polari" + BRANCH: "snapshot" # Make sure to keep this in sync with the Flatpak manifest, all arguments # are passed except the config-args because we build it ourselves - MESON_ARGS: "" + MESON_ARGS: "-Dsnapshot=true" DBUS_ID: "org.gnome.Polari" before_script: @@ -26,11 +27,11 @@ flatpak: # are passed except the config-args because we build it ourselves - flatpak build app meson --prefix=/app ${MESON_ARGS} _build - flatpak build app ninja -C _build install - - flatpak-builder --finish-only --repo=repo app ${MANIFEST_PATH} + - flatpak-builder --finish-only --repo=repo --default-branch=${BRANCH} app ${MANIFEST_PATH} # Run automatic tests inside the Flatpak env - flatpak build app ninja -C _build test # Generate a Flatpak bundle - - flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${DBUS_ID} + - flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${DBUS_ID} ${BRANCH} after_script: - tar -czf cache.tar.gz .flatpak-builder/cache -- GitLab