[gnome-builder] plugins/flatpak: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/flatpak: port to GTK 4
- Date: Tue, 12 Jul 2022 06:39:16 +0000 (UTC)
commit cbe65ae5e178c5b95e0c26677ea8a1c55f13f6d7
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 22:43:42 2022 -0700
plugins/flatpak: port to GTK 4
- Remove libdazzle usage
- Update dialogs for GTK 4
- Remove build-target-provider (use run-command-provider instead)
- Remove IdeRunner and subprocess launcher
- Implement run context support
- Use workbench addin to override app settings for run command
- Remove unused clone widget
src/plugins/flatpak/flatpak-plugin.c | 10 +-
src/plugins/flatpak/flatpak.gresource.xml | 1 -
src/plugins/flatpak/flatpak.plugin | 4 +-
src/plugins/flatpak/gbp-flatpak-aux.c | 21 +
src/plugins/flatpak/gbp-flatpak-aux.h | 8 +-
.../flatpak/gbp-flatpak-build-system-discovery.c | 4 +-
.../flatpak/gbp-flatpak-build-target-provider.c | 114 ----
src/plugins/flatpak/gbp-flatpak-build-target.c | 164 -----
src/plugins/flatpak/gbp-flatpak-clone-widget.c | 742 ---------------------
src/plugins/flatpak/gbp-flatpak-clone-widget.h | 39 --
src/plugins/flatpak/gbp-flatpak-clone-widget.ui | 44 --
src/plugins/flatpak/gbp-flatpak-config-provider.c | 2 +-
src/plugins/flatpak/gbp-flatpak-download-stage.c | 4 +-
src/plugins/flatpak/gbp-flatpak-install-dialog.c | 4 +-
src/plugins/flatpak/gbp-flatpak-install-dialog.ui | 42 +-
src/plugins/flatpak/gbp-flatpak-manifest.c | 16 +-
src/plugins/flatpak/gbp-flatpak-manifest.h | 1 +
src/plugins/flatpak/gbp-flatpak-pipeline-addin.c | 26 +-
.../flatpak/gbp-flatpak-run-command-provider.c | 147 ++++
...ovider.h => gbp-flatpak-run-command-provider.h} | 8 +-
src/plugins/flatpak/gbp-flatpak-runner.c | 301 ---------
src/plugins/flatpak/gbp-flatpak-runner.h | 36 -
src/plugins/flatpak/gbp-flatpak-runtime.c | 512 ++++++++------
.../flatpak/gbp-flatpak-subprocess-launcher.c | 212 ------
.../flatpak/gbp-flatpak-subprocess-launcher.h | 35 -
src/plugins/flatpak/gbp-flatpak-workbench-addin.c | 167 +++++
...uild-target.h => gbp-flatpak-workbench-addin.h} | 10 +-
src/plugins/flatpak/ipc-flatpak-transfer-impl.c | 2 +-
src/plugins/flatpak/meson.build | 7 +-
29 files changed, 710 insertions(+), 1973 deletions(-)
---
diff --git a/src/plugins/flatpak/flatpak-plugin.c b/src/plugins/flatpak/flatpak-plugin.c
index 094e23552..ae76ebee5 100644
--- a/src/plugins/flatpak/flatpak-plugin.c
+++ b/src/plugins/flatpak/flatpak-plugin.c
@@ -29,12 +29,13 @@
#include "gbp-flatpak-aux.h"
#include "gbp-flatpak-build-system-discovery.h"
-#include "gbp-flatpak-build-target-provider.h"
#include "gbp-flatpak-client.h"
#include "gbp-flatpak-config-provider.h"
#include "gbp-flatpak-dependency-updater.h"
#include "gbp-flatpak-pipeline-addin.h"
+#include "gbp-flatpak-run-command-provider.h"
#include "gbp-flatpak-runtime-provider.h"
+#include "gbp-flatpak-workbench-addin.h"
_IDE_EXTERN void
_gbp_flatpak_register_types (PeasObjectModule *module)
@@ -45,8 +46,8 @@ _gbp_flatpak_register_types (PeasObjectModule *module)
IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
GBP_TYPE_FLATPAK_BUILD_SYSTEM_DISCOVERY);
peas_object_module_register_extension_type (module,
- IDE_TYPE_BUILD_TARGET_PROVIDER,
- GBP_TYPE_FLATPAK_BUILD_TARGET_PROVIDER);
+ IDE_TYPE_RUN_COMMAND_PROVIDER,
+ GBP_TYPE_FLATPAK_RUN_COMMAND_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_CONFIG_PROVIDER,
GBP_TYPE_FLATPAK_CONFIG_PROVIDER);
@@ -59,6 +60,9 @@ _gbp_flatpak_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_PIPELINE_ADDIN,
GBP_TYPE_FLATPAK_PIPELINE_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_WORKBENCH_ADDIN,
+ GBP_TYPE_FLATPAK_WORKBENCH_ADDIN);
gbp_flatpak_aux_init ();
diff --git a/src/plugins/flatpak/flatpak.gresource.xml b/src/plugins/flatpak/flatpak.gresource.xml
index 494fd672a..9b03d6f6e 100644
--- a/src/plugins/flatpak/flatpak.gresource.xml
+++ b/src/plugins/flatpak/flatpak.gresource.xml
@@ -2,7 +2,6 @@
<gresources>
<gresource prefix="/plugins/flatpak">
<file>flatpak.plugin</file>
- <file preprocess="xml-stripblanks">gbp-flatpak-clone-widget.ui</file>
<file preprocess="xml-stripblanks">gbp-flatpak-install-dialog.ui</file>
</gresource>
</gresources>
diff --git a/src/plugins/flatpak/flatpak.plugin b/src/plugins/flatpak/flatpak.plugin
index 2d7e9bc7c..f49185f6f 100644
--- a/src/plugins/flatpak/flatpak.plugin
+++ b/src/plugins/flatpak/flatpak.plugin
@@ -2,10 +2,10 @@
Authors=Christian Hergert <christian hergert me>
Builtin=true
Copyright=Copyright © 2016-2018 Christian Hergert
-Depends=buildui;editor;git;
+Depends=git;
Description=Provides support for building with Flatpak
Embedded=_gbp_flatpak_register_types
-Hidden=true
Module=flatpak
Name=Flatpak
X-At-Startup=true
+X-Category=sdks
diff --git a/src/plugins/flatpak/gbp-flatpak-aux.c b/src/plugins/flatpak/gbp-flatpak-aux.c
index 14f3b04c7..6d74f9f52 100644
--- a/src/plugins/flatpak/gbp-flatpak-aux.c
+++ b/src/plugins/flatpak/gbp-flatpak-aux.c
@@ -182,3 +182,24 @@ gbp_flatpak_aux_apply (IdeSubprocessLauncher *launcher,
return count;
}
+
+void
+gbp_flatpak_aux_append_to_run_context (IdeRunContext *run_context)
+{
+ static const char *arg;
+
+ g_return_if_fail (IDE_IS_RUN_CONTEXT (run_context));
+ g_return_if_fail (initialized);
+
+ if (arg == NULL)
+ arg = g_strdup_printf ("--bind-mount=/run/host/font-dirs.xml=%s",
+ g_file_peek_path (mapped));
+
+ for (guint i = 0; i < maps->len; i++)
+ {
+ const char *element = g_ptr_array_index (maps, i);
+ ide_run_context_append_argv (run_context, element);
+ }
+
+ ide_run_context_append_argv (run_context, arg);
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-aux.h b/src/plugins/flatpak/gbp-flatpak-aux.h
index 6c01a35d4..4a270b827 100644
--- a/src/plugins/flatpak/gbp-flatpak-aux.h
+++ b/src/plugins/flatpak/gbp-flatpak-aux.h
@@ -20,12 +20,14 @@
#pragma once
+#include <libide-foundry.h>
#include <libide-threading.h>
G_BEGIN_DECLS
-void gbp_flatpak_aux_init (void);
-int gbp_flatpak_aux_apply (IdeSubprocessLauncher *launcher,
- int position);
+void gbp_flatpak_aux_init (void);
+int gbp_flatpak_aux_apply (IdeSubprocessLauncher *launcher,
+ int position);
+void gbp_flatpak_aux_append_to_run_context (IdeRunContext *run_context);
G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-build-system-discovery.c
b/src/plugins/flatpak/gbp-flatpak-build-system-discovery.c
index 4308f9aaf..8eb9920d1 100644
--- a/src/plugins/flatpak/gbp-flatpak-build-system-discovery.c
+++ b/src/plugins/flatpak/gbp-flatpak-build-system-discovery.c
@@ -202,9 +202,9 @@ gbp_flatpak_build_system_discovery_discover (IdeBuildSystemDiscovery *discovery
{
gchar *ret;
- if (dzl_str_equal0 (buildsystem, "cmake-ninja"))
+ if (ide_str_equal0 (buildsystem, "cmake-ninja"))
buildsystem = "cmake";
- else if (dzl_str_equal0 (buildsystem, "simple"))
+ else if (ide_str_equal0 (buildsystem, "simple"))
{
JsonNode *sdk_extensions;
JsonArray *sdk_extensions_array;
diff --git a/src/plugins/flatpak/gbp-flatpak-config-provider.c
b/src/plugins/flatpak/gbp-flatpak-config-provider.c
index 1721fe2f6..852ecc031 100644
--- a/src/plugins/flatpak/gbp-flatpak-config-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-config-provider.c
@@ -535,7 +535,7 @@ guess_best_config (GPtrArray *ar)
/* If appid.json is the same as the filename, that is the
* best match (after unstable) we can have. Use it.
*/
- if (dzl_str_equal0 (app_id_json, base))
+ if (ide_str_equal0 (app_id_json, base))
return IDE_CONFIG (config);
}
diff --git a/src/plugins/flatpak/gbp-flatpak-download-stage.c
b/src/plugins/flatpak/gbp-flatpak-download-stage.c
index 4ee3d58d0..0b582cb1e 100644
--- a/src/plugins/flatpak/gbp-flatpak-download-stage.c
+++ b/src/plugins/flatpak/gbp-flatpak-download-stage.c
@@ -121,7 +121,7 @@ gbp_flatpak_download_stage_query (IdePipelineStage *stage,
ide_subprocess_launcher_push_argv (launcher, "--ccache");
ide_subprocess_launcher_push_argv (launcher, "--force-clean");
- if (!dzl_str_empty0 (self->state_dir))
+ if (!ide_str_empty0 (self->state_dir))
{
ide_subprocess_launcher_push_argv (launcher, "--state-dir");
ide_subprocess_launcher_push_argv (launcher, self->state_dir);
@@ -193,8 +193,6 @@ gbp_flatpak_download_stage_class_init (GbpFlatpakDownloadStageClass *klass)
*
* The "state-dir" is the flatpak-builder state directory, to be used
* as a parameter to "flatpak-builder --state-dir".
- *
- * Since: 3.28
*/
properties [PROP_STATE_DIR] =
g_param_spec_string ("state-dir",
diff --git a/src/plugins/flatpak/gbp-flatpak-install-dialog.c
b/src/plugins/flatpak/gbp-flatpak-install-dialog.c
index 8098dc515..bcb322340 100644
--- a/src/plugins/flatpak/gbp-flatpak-install-dialog.c
+++ b/src/plugins/flatpak/gbp-flatpak-install-dialog.c
@@ -73,7 +73,7 @@ gbp_flatpak_install_dialog_response (GtkDialog *dialog,
if (GTK_DIALOG_CLASS (gbp_flatpak_install_dialog_parent_class)->response)
GTK_DIALOG_CLASS (gbp_flatpak_install_dialog_parent_class)->response (dialog, response_id);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_window_destroy (GTK_WINDOW (dialog));
}
static void
@@ -120,7 +120,7 @@ gbp_flatpak_install_dialog_init (GbpFlatpakInstallDialog *self)
gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
- dzl_gtk_widget_add_style_class (button, "suggested-action");
+ gtk_widget_add_css_class (button, "suggested-action");
}
void
diff --git a/src/plugins/flatpak/gbp-flatpak-install-dialog.ui
b/src/plugins/flatpak/gbp-flatpak-install-dialog.ui
index c994b84e1..20f4c45f4 100644
--- a/src/plugins/flatpak/gbp-flatpak-install-dialog.ui
+++ b/src/plugins/flatpak/gbp-flatpak-install-dialog.ui
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.0 -->
<interface>
- <requires lib="gtk+" version="3.24"/>
+ <requires lib="gtk" version="4.0"/>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name name -->
@@ -13,27 +12,13 @@
</columns>
</object>
<template class="GbpFlatpakInstallDialog" parent="GtkDialog">
- <property name="can_focus">False</property>
<property name="modal">True</property>
- <property name="type_hint">normal</property>
- <child internal-child="vbox">
+ <child internal-child="content_area">
<object class="GtkBox">
- <property name="can_focus">False</property>
<property name="orientation">vertical</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox">
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
<child>
<object class="GtkBox" id="content">
<property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<property name="margin_top">12</property>
@@ -44,32 +29,24 @@
<child>
<object class="GtkLabel" id="subtitle">
<property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="label" translatable="yes">Builder needs to install the following software
development kits to build your project.</property>
<property name="wrap">True</property>
<property name="max_width_chars">50</property>
<property name="xalign">0</property>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
<child>
<object class="GtkScrolledWindow">
+ <property name="has-frame">True</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
<property name="margin_top">12</property>
<property name="vexpand">True</property>
- <property name="shadow_type">in</property>
<property name="propagate_natural_width">True</property>
<property name="propagate_natural_height">True</property>
<child>
<object class="GtkTreeView" id="runtimes">
<property name="visible">True</property>
- <property name="can_focus">True</property>
<property name="model">liststore1</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
@@ -113,23 +90,10 @@
</object>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
</object>
</child>
- <child type="titlebar">
- <placeholder/>
- </child>
</template>
</interface>
diff --git a/src/plugins/flatpak/gbp-flatpak-manifest.c b/src/plugins/flatpak/gbp-flatpak-manifest.c
index 8a12b420e..28d5a7212 100644
--- a/src/plugins/flatpak/gbp-flatpak-manifest.c
+++ b/src/plugins/flatpak/gbp-flatpak-manifest.c
@@ -45,6 +45,7 @@ struct _GbpFlatpakManifest
*/
gchar **build_args;
gchar *command;
+ gchar **x_run_args;
gchar **finish_args;
gchar *runtime;
gchar *runtime_version;
@@ -296,7 +297,7 @@ discover_primary_module (GbpFlatpakManifest *self,
!(name = json_object_get_string_member (obj, "name")))
continue;
- if (dzl_str_equal0 (name, dir_name))
+ if (ide_str_equal0 (name, dir_name))
{
self->primary_module = g_strdup (name);
return obj;
@@ -425,6 +426,7 @@ gbp_flatpak_manifest_initable_init (GInitable *initable,
discover_strv_field (root_obj, "build-args", &self->build_args);
discover_strv_field (root_obj, "finish-args", &self->finish_args);
discover_strv_field (root_obj, "sdk-extensions", &self->sdk_extensions);
+ discover_strv_field (root_obj, "x-run-args", &self->x_run_args);
if (discover_strv_as_quoted (root_obj, "x-run-args", &run_args))
ide_config_set_run_opts (IDE_CONFIG (self), run_args);
@@ -932,9 +934,9 @@ apply_changes_to_tree (GbpFlatpakManifest *self)
key = ide_environment_variable_get_key (var);
value = ide_environment_variable_get_value (var);
- if (dzl_str_equal0 (key, "CFLAGS"))
+ if (ide_str_equal0 (key, "CFLAGS"))
json_object_set_string_member (build_options, "cflags", value);
- else if (dzl_str_equal0 (key, "CXXFLAGS"))
+ else if (ide_str_equal0 (key, "CXXFLAGS"))
json_object_set_string_member (build_options, "cxxflags", value);
else
json_object_set_string_member (env_obj, key, value);
@@ -1213,3 +1215,11 @@ gbp_flatpak_manifest_get_branch (GbpFlatpakManifest *self)
return self->runtime_version;
}
+
+const char * const *
+gbp_flatpak_manifest_get_x_run_args (GbpFlatpakManifest *self)
+{
+ g_return_val_if_fail (GBP_IS_FLATPAK_MANIFEST (self), NULL);
+
+ return (const char * const *)self->x_run_args;
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-manifest.h b/src/plugins/flatpak/gbp-flatpak-manifest.h
index 320bb1816..80ea5e4d2 100644
--- a/src/plugins/flatpak/gbp-flatpak-manifest.h
+++ b/src/plugins/flatpak/gbp-flatpak-manifest.h
@@ -37,6 +37,7 @@ GFile *gbp_flatpak_manifest_get_file (GbpFlatpakManifest
const gchar *gbp_flatpak_manifest_get_primary_module (GbpFlatpakManifest *self);
const gchar *gbp_flatpak_manifest_get_command (GbpFlatpakManifest *self);
gchar *gbp_flatpak_manifest_get_path (GbpFlatpakManifest *self);
+const gchar * const *gbp_flatpak_manifest_get_x_run_args (GbpFlatpakManifest *self);
const gchar * const *gbp_flatpak_manifest_get_build_args (GbpFlatpakManifest *self);
const gchar * const *gbp_flatpak_manifest_get_finish_args (GbpFlatpakManifest *self);
const gchar * const *gbp_flatpak_manifest_get_sdk_extensions (GbpFlatpakManifest *self);
diff --git a/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
b/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
index 33834962e..0ce7a74f4 100644
--- a/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
+++ b/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
@@ -22,6 +22,8 @@
#include <glib/gi18n.h>
+#include <libide-gtk.h>
+
#include "gbp-flatpak-manifest.h"
#include "gbp-flatpak-download-stage.h"
#include "gbp-flatpak-pipeline-addin.h"
@@ -196,17 +198,17 @@ reap_staging_dir_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- DzlDirectoryReaper *reaper = (DzlDirectoryReaper *)object;
+ IdeDirectoryReaper *reaper = (IdeDirectoryReaper *)object;
g_autoptr(IdePipelineStage) stage = user_data;
g_autoptr(GError) error = NULL;
IDE_ENTRY;
- g_assert (DZL_IS_DIRECTORY_REAPER (reaper));
+ g_assert (IDE_IS_DIRECTORY_REAPER (reaper));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (IDE_IS_PIPELINE_STAGE (stage));
- if (!dzl_directory_reaper_execute_finish (reaper, result, &error))
+ if (!ide_directory_reaper_execute_finish (reaper, result, &error))
ide_object_warning (stage,
"Failed to reap staging directory: %s",
error->message);
@@ -258,14 +260,14 @@ check_for_build_init_files (IdePipelineStage *stage,
if (!completed && parent_exists)
{
- g_autoptr(DzlDirectoryReaper) reaper = NULL;
+ g_autoptr(IdeDirectoryReaper) reaper = NULL;
g_autoptr(GFile) staging = g_file_new_for_path (staging_dir);
ide_pipeline_stage_pause (stage);
- reaper = dzl_directory_reaper_new ();
- dzl_directory_reaper_add_directory (reaper, staging, 0);
- dzl_directory_reaper_execute_async (reaper,
+ reaper = ide_directory_reaper_new ();
+ ide_directory_reaper_add_directory (reaper, staging, 0);
+ ide_directory_reaper_execute_async (reaper,
cancellable,
reap_staging_dir_cb,
g_object_ref (stage));
@@ -274,17 +276,17 @@ check_for_build_init_files (IdePipelineStage *stage,
static void
reap_staging_dir (IdePipelineStage *stage,
- DzlDirectoryReaper *reaper,
+ IdeDirectoryReaper *reaper,
const gchar *staging_dir)
{
g_autoptr(GFile) dir = NULL;
g_assert (IDE_IS_PIPELINE_STAGE (stage));
- g_assert (DZL_IS_DIRECTORY_REAPER (reaper));
+ g_assert (IDE_IS_DIRECTORY_REAPER (reaper));
g_assert (staging_dir != NULL);
dir = g_file_new_for_path (staging_dir);
- dzl_directory_reaper_add_directory (reaper, dir, 0);
+ ide_directory_reaper_add_directory (reaper, dir, 0);
}
static gboolean
@@ -338,7 +340,7 @@ register_build_init_stage (GbpFlatpakPipelineAddin *self,
* If we got here by using a non-flatpak configuration, then there is a
* chance we don't have a valid app-id.
*/
- if (dzl_str_empty0 (app_id))
+ if (ide_str_empty0 (app_id))
app_id = "com.example.App";
if (platform == NULL && sdk == NULL)
@@ -634,7 +636,7 @@ build_bundle_notify_completed (IdePipelineStage *stage,
if (ide_pipeline_stage_get_completed (stage))
{
g_autoptr(GFile) file = g_file_new_for_path (dest_path);
- dzl_file_manager_show (file, NULL);
+ ide_file_manager_show (file, NULL);
}
}
diff --git a/src/plugins/flatpak/gbp-flatpak-run-command-provider.c
b/src/plugins/flatpak/gbp-flatpak-run-command-provider.c
new file mode 100644
index 000000000..869b8a2fe
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-run-command-provider.c
@@ -0,0 +1,147 @@
+/* gbp-flatpak-run-command-provider.c
+ *
+ * Copyright 2017-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-run-command-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+#include <libide-threading.h>
+
+#include "gbp-flatpak-run-command-provider.h"
+#include "gbp-flatpak-manifest.h"
+
+struct _GbpFlatpakRunCommandProvider
+{
+ IdeObject parent_instance;
+};
+
+static char **
+join_args (const char *argv0,
+ const char * const *x_run_args)
+{
+ GPtrArray *ar = g_ptr_array_new ();
+
+ g_ptr_array_add (ar, g_strdup (argv0));
+ if (x_run_args)
+ {
+ for (guint i = 0; x_run_args[i]; i++)
+ g_ptr_array_add (ar, g_strdup (x_run_args[i]));
+ }
+ g_ptr_array_add (ar, NULL);
+
+ return (char **)(gpointer)g_ptr_array_free (ar, FALSE);
+}
+
+static void
+gbp_flatpak_run_command_provider_list_commands_async (IdeRunCommandProvider *provider,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpFlatpakRunCommandProvider *self = (GbpFlatpakRunCommandProvider *)provider;
+ g_autoptr(GListStore) store = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(IdeRunCommand) command = NULL;
+ g_auto(GStrv) argv = NULL;
+ IdeConfigManager *config_manager;
+ const char * const *x_run_args;
+ const char *argv0;
+ IdeContext *context;
+ IdeConfig *config;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_RUN_COMMAND_PROVIDER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_flatpak_run_command_provider_list_commands_async);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ config_manager = ide_config_manager_from_context (context);
+ config = ide_config_manager_get_current (config_manager);
+
+ if (!GBP_IS_FLATPAK_MANIFEST (config))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Project is not configured with flatpak, cannot list commands");
+ IDE_EXIT;
+ }
+
+ argv0 = gbp_flatpak_manifest_get_command (GBP_FLATPAK_MANIFEST (config));
+ x_run_args = gbp_flatpak_manifest_get_x_run_args (GBP_FLATPAK_MANIFEST (config));
+
+ store = g_list_store_new (IDE_TYPE_RUN_COMMAND);
+ argv = join_args (argv0, x_run_args);
+
+ command = ide_run_command_new ();
+ ide_run_command_set_id (command, "flatpak:");
+ ide_run_command_set_priority (command, -1000);
+ ide_run_command_set_display_name (command, _("Flatpak Application"));
+ ide_run_command_set_argv (command, (const char * const *)argv);
+ g_list_store_append (store, command);
+
+ ide_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
+
+ IDE_EXIT;
+}
+
+static GListModel *
+gbp_flatpak_run_command_provider_list_commands_finish (IdeRunCommandProvider *provider,
+ GAsyncResult *result,
+ GError **error)
+{
+ GListModel *ret;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_RUN_COMMAND_PROVIDER (provider));
+ g_assert (IDE_IS_TASK (result));
+ g_assert (ide_task_is_valid (IDE_TASK (result), provider));
+
+ ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+ IDE_RETURN (ret);
+}
+
+static void
+run_command_provider_iface_init (IdeRunCommandProviderInterface *iface)
+{
+ iface->list_commands_async = gbp_flatpak_run_command_provider_list_commands_async;
+ iface->list_commands_finish = gbp_flatpak_run_command_provider_list_commands_finish;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpFlatpakRunCommandProvider, gbp_flatpak_run_command_provider,
IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_RUN_COMMAND_PROVIDER,
run_command_provider_iface_init))
+
+static void
+gbp_flatpak_run_command_provider_class_init (GbpFlatpakRunCommandProviderClass *klass)
+{
+}
+
+static void
+gbp_flatpak_run_command_provider_init (GbpFlatpakRunCommandProvider *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-build-target-provider.h
b/src/plugins/flatpak/gbp-flatpak-run-command-provider.h
similarity index 71%
rename from src/plugins/flatpak/gbp-flatpak-build-target-provider.h
rename to src/plugins/flatpak/gbp-flatpak-run-command-provider.h
index 285694c04..9ea12ccf9 100644
--- a/src/plugins/flatpak/gbp-flatpak-build-target-provider.h
+++ b/src/plugins/flatpak/gbp-flatpak-run-command-provider.h
@@ -1,6 +1,6 @@
/* gbp-flatpak-build-target-provider.h
*
- * Copyright 2017-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2017-2022 Christian Hergert <chergert redhat com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,12 +20,12 @@
#pragma once
-#include <libide-foundry.h>
+#include <libide-core.h>
G_BEGIN_DECLS
-#define GBP_TYPE_FLATPAK_BUILD_TARGET_PROVIDER (gbp_flatpak_build_target_provider_get_type())
+#define GBP_TYPE_FLATPAK_RUN_COMMAND_PROVIDER (gbp_flatpak_run_command_provider_get_type())
-G_DECLARE_FINAL_TYPE (GbpFlatpakBuildTargetProvider, gbp_flatpak_build_target_provider, GBP,
FLATPAK_BUILD_TARGET_PROVIDER, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpFlatpakRunCommandProvider, gbp_flatpak_run_command_provider, GBP,
FLATPAK_RUN_COMMAND_PROVIDER, IdeObject)
G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index 154a18d54..088d6ed0a 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -20,14 +20,19 @@
#define G_LOG_DOMAIN "gbp-flatpak-runtime"
+#include "config.h"
+
+#include <unistd.h>
+
#include <glib/gi18n.h>
+
#include <json-glib/json-glib.h>
+
#include <libide-vcs.h>
+#include "gbp-flatpak-aux.h"
#include "gbp-flatpak-manifest.h"
-#include "gbp-flatpak-runner.h"
#include "gbp-flatpak-runtime.h"
-#include "gbp-flatpak-subprocess-launcher.h"
#include "gbp-flatpak-util.h"
struct _GbpFlatpakRuntime
@@ -37,11 +42,11 @@ struct _GbpFlatpakRuntime
GHashTable *program_paths_cache;
IdeTriplet *triplet;
- gchar *branch;
- gchar *deploy_dir;
- gchar *platform;
- gchar *sdk;
- gchar *runtime_dir;
+ char *branch;
+ char *deploy_dir;
+ char *platform;
+ char *sdk;
+ char *runtime_dir;
GFile *deploy_dir_files;
};
@@ -59,23 +64,7 @@ enum {
static GParamSpec *properties [N_PROPS];
-static inline gboolean
-strv_empty (gchar **strv)
-{
- return strv == NULL || strv[0] == NULL;
-}
-
-static const gchar *
-get_builddir (GbpFlatpakRuntime *self)
-{
- g_autoptr(IdeContext) context = ide_object_ref_context (IDE_OBJECT (self));
- g_autoptr(IdeBuildManager) build_manager = ide_build_manager_ref_from_context (context);
- g_autoptr(IdePipeline) pipeline = ide_build_manager_ref_pipeline (build_manager);
-
- return ide_pipeline_get_builddir (pipeline);
-}
-
-static gchar *
+static char *
get_staging_directory (GbpFlatpakRuntime *self)
{
g_autoptr(IdeContext) context = ide_object_ref_context (IDE_OBJECT (self));
@@ -87,10 +76,10 @@ get_staging_directory (GbpFlatpakRuntime *self)
static gboolean
gbp_flatpak_runtime_contains_program_in_path (IdeRuntime *runtime,
- const gchar *program,
+ const char *program,
GCancellable *cancellable)
{
- static const gchar *known_path_dirs[] = { "/bin" };
+ static const char *known_path_dirs[] = { "/bin" };
GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)runtime;
gboolean ret = FALSE;
gpointer val = NULL;
@@ -104,7 +93,7 @@ gbp_flatpak_runtime_contains_program_in_path (IdeRuntime *runtime,
for (guint i = 0; i < G_N_ELEMENTS (known_path_dirs); i++)
{
- g_autofree gchar *path = NULL;
+ g_autofree char *path = NULL;
path = g_build_filename (self->deploy_dir,
"files",
@@ -124,188 +113,311 @@ gbp_flatpak_runtime_contains_program_in_path (IdeRuntime *runtime,
self->sdk != NULL &&
!ide_str_equal0 (self->platform, self->sdk))
{
- IdeContext* context = ide_object_get_context (IDE_OBJECT (self));
- if (context)
- {
- g_autoptr(IdeRuntimeManager) manager = ide_object_ensure_child_typed (IDE_OBJECT (context),
IDE_TYPE_RUNTIME_MANAGER);
- g_autofree char *arch = ide_runtime_get_arch (runtime);
- g_autofree char *sdk_id = g_strdup_printf ("flatpak:%s/%s/%s", self->sdk, arch, self->branch);
- IdeRuntime *sdk = ide_runtime_manager_get_runtime (manager, sdk_id);
-
- if (sdk != NULL && sdk != runtime)
- ret = ide_runtime_contains_program_in_path (sdk, program, cancellable);
- }
+ IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
+ IdeRuntimeManager *manager = ide_runtime_manager_from_context (context);
+ g_autofree char *arch = ide_runtime_get_arch (runtime);
+ g_autofree char *sdk_id = g_strdup_printf ("flatpak:%s/%s/%s", self->sdk, arch, self->branch);
+ IdeRuntime *sdk = ide_runtime_manager_get_runtime (manager, sdk_id);
+
+ if (sdk != NULL && sdk != runtime)
+ ret = ide_runtime_contains_program_in_path (sdk, program, cancellable);
}
/* Cache both positive and negative lookups */
g_hash_table_insert (self->program_paths_cache,
- (gchar *)g_intern_string (program),
+ (char *)g_intern_string (program),
GUINT_TO_POINTER (ret));
return ret;
}
-static IdeSubprocessLauncher *
-gbp_flatpak_runtime_create_launcher (IdeRuntime *runtime,
- GError **error)
+static gboolean
+can_pass_through_finish_arg (const char *arg)
{
- IdeSubprocessLauncher *ret;
- GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)runtime;
- g_autoptr(IdeContext) context = NULL;
- const gchar *runtime_id;
-
- g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
-
- context = ide_object_ref_context (IDE_OBJECT (self));
- g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
-
- runtime_id = ide_runtime_get_id (runtime);
- g_return_val_if_fail (g_str_has_prefix (runtime_id, "flatpak:"), NULL);
-
- ret = gbp_flatpak_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
G_SUBPROCESS_FLAGS_STDERR_PIPE);
+ if (arg == NULL)
+ return FALSE;
+
+ return g_str_has_prefix (arg, "--allow") ||
+ g_str_has_prefix (arg, "--share") ||
+ g_str_has_prefix (arg, "--socket") ||
+ g_str_has_prefix (arg, "--filesystem") ||
+ g_str_has_prefix (arg, "--device") ||
+ g_str_has_prefix (arg, "--env") ||
+ g_str_has_prefix (arg, "--system-talk") ||
+ g_str_has_prefix (arg, "--own-name") ||
+ g_str_has_prefix (arg, "--talk-name") ||
+ g_str_has_prefix (arg, "--add-policy");
+}
- if (ret != NULL && !ide_context_has_project (context))
- {
- ide_subprocess_launcher_set_cwd (ret, g_get_home_dir ());
- ide_subprocess_launcher_set_run_on_host (ret, TRUE);
- gbp_flatpak_subprocess_launcher_use_run (GBP_FLATPAK_SUBPROCESS_LAUNCHER (ret),
- runtime_id + strlen ("flatpak:"));
- }
- else if (ret != NULL)
- {
- g_autofree gchar *build_path = NULL;
- g_autofree gchar *ccache_dir = NULL;
- g_auto(GStrv) new_environ = NULL;
- const gchar *builddir = NULL;
- const gchar *project_path = NULL;
- const gchar * const *build_args = NULL;
- const gchar *config_dir = gbp_flatpak_get_config_dir ();
- g_autoptr(IdeConfigManager) config_manager = NULL;
- IdeConfig *configuration;
- IdeVcs *vcs;
+static gboolean
+gbp_flatpak_runtime_handle_run_context_cb (IdeRunContext *run_context,
+ const char * const *argv,
+ const char * const *env,
+ const char *cwd,
+ IdeUnixFDMap *unix_fd_map,
+ gpointer user_data,
+ GError **error)
+{
+ IdePipeline *pipeline = user_data;
+ GbpFlatpakRuntime *self;
+ g_autofree char *project_build_dir_arg = NULL;
+ g_autofree char *project_build_dir = NULL;
+ g_autofree char *staging_dir = NULL;
+ const char *wayland_display;
+ const char *app_id;
+ IdeContext *context;
+ IdeConfig *config;
- config_manager = ide_config_manager_ref_from_context (context);
- configuration = ide_config_manager_ref_current (config_manager);
+ IDE_ENTRY;
- build_path = get_staging_directory (self);
- builddir = get_builddir (self);
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
+ g_assert (IDE_IS_UNIX_FD_MAP (unix_fd_map));
- /* Find the project directory path */
- vcs = ide_vcs_ref_from_context (context);
- project_path = g_file_peek_path (ide_vcs_get_workdir (vcs));
+ self = GBP_FLATPAK_RUNTIME (ide_pipeline_get_runtime (pipeline));
+ context = ide_object_get_context (IDE_OBJECT (self));
- /* Add 'flatpak build' and the specified arguments to the launcher */
- ide_subprocess_launcher_push_argv (ret, "flatpak");
- ide_subprocess_launcher_push_argv (ret, "build");
+ g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+ g_assert (IDE_IS_CONTEXT (context));
- /* Get access to override installations */
- ide_subprocess_launcher_setenv (ret, "FLATPAK_CONFIG_DIR", config_dir, TRUE);
+ /* Pass through the FD mappings */
+ if (!ide_run_context_merge_unix_fd_map (run_context, unix_fd_map, error))
+ return FALSE;
- if (GBP_IS_FLATPAK_MANIFEST (configuration))
- build_args = gbp_flatpak_manifest_get_build_args (GBP_FLATPAK_MANIFEST (configuration));
+ staging_dir = gbp_flatpak_get_staging_dir (pipeline);
+ config = ide_pipeline_get_config (pipeline);
+ app_id = ide_config_get_app_id (config);
- if (build_args != NULL)
- ide_subprocess_launcher_push_args (ret, build_args);
- else
- ide_subprocess_launcher_push_argv (ret, "--share=network");
-
- /* We might need access to ccache configs inside the build environ.
- * Usually, this is set by flatpak-builder, but since we are running
- * the incremental build, we need to take care of that too.
- *
- * See https://bugzilla.gnome.org/show_bug.cgi?id=780153
- */
- ccache_dir = g_build_filename (g_get_user_cache_dir (),
- ide_get_program_name (),
- "flatpak-builder",
- "ccache",
- NULL);
- ide_subprocess_launcher_setenv (ret, "CCACHE_DIR", ccache_dir, FALSE);
+ /* Make sure our worker has access to our Builder-specific Flatpak repository */
+ ide_run_context_setenv (run_context, "FLATPAK_CONFIG_DIR", gbp_flatpak_get_config_dir ());
- if (!ide_str_empty0 (project_path))
+ /* We need access to a few things for "flatpak build" to work and give us
+ * access to the display/etc.
+ */
+ ide_run_context_add_minimal_environment (run_context);
+
+ /* We can pass the CWD directory down just fine */
+ ide_run_context_set_cwd (run_context, cwd);
+
+ /* Now setup our basic arguments for the application */
+ ide_run_context_append_argv (run_context, "flatpak");
+ ide_run_context_append_argv (run_context, "build");
+ ide_run_context_append_argv (run_context, "--with-appdir");
+ ide_run_context_append_argv (run_context, "--allow=devel");
+ ide_run_context_append_argv (run_context, "--die-with-parent");
+
+ /* Make sure we have access to the document portal */
+ ide_run_context_append_formatted (run_context,
+ "--bind-mount=/run/user/%u/doc=/run/user/%u/doc/by-app/%s",
+ getuid (), getuid (), app_id);
+
+ /* Make sure wayland socket is available. */
+ if ((wayland_display = g_getenv ("WAYLAND_DISPLAY")))
+ ide_run_context_append_formatted (run_context,
+ "--bind-mount=/run/user/%u/%s=/run/user/%u/%s",
+ getuid (), wayland_display, getuid (), wayland_display);
+
+ /* Make sure we have access to fonts and such */
+ gbp_flatpak_aux_append_to_run_context (run_context);
+
+ /* Make sure we have access to the build directory */
+ project_build_dir = ide_context_cache_filename (context, NULL, NULL);
+ project_build_dir_arg = g_strdup_printf ("--filesystem=%s", project_build_dir);
+ ide_run_context_append_argv (run_context, project_build_dir_arg);
+
+ /* Convert environment from upper level into --env=FOO=BAR */
+ if (env != NULL)
+ {
+ for (guint i = 0; env[i]; i++)
{
- g_autofree gchar *filesystem_option_src = NULL;
- g_autofree gchar *filesystem_option_build = NULL;
- g_autofree gchar *filesystem_option_cache = NULL;
-
- filesystem_option_src = g_strdup_printf ("--filesystem=%s", project_path);
- filesystem_option_build = g_strdup_printf ("--filesystem=%s", builddir);
- filesystem_option_cache = g_strdup_printf ("--filesystem=%s/gnome-builder", g_get_user_cache_dir
());
- ide_subprocess_launcher_push_argv (ret, "--nofilesystem=host");
- ide_subprocess_launcher_push_argv (ret, filesystem_option_cache);
- ide_subprocess_launcher_push_argv (ret, filesystem_option_src);
- ide_subprocess_launcher_push_argv (ret, filesystem_option_build);
+ g_autofree char *arg = g_strconcat ("--env=", env[i], NULL);
+ ide_run_context_append_argv (run_context, arg);
}
+ }
- new_environ = ide_config_get_environ (IDE_CONFIG (configuration));
+ /* Make sure all of our finish arguments for the manifest are included */
+ if (GBP_IS_FLATPAK_MANIFEST (config))
+ {
+ const char * const *finish_args = gbp_flatpak_manifest_get_finish_args (GBP_FLATPAK_MANIFEST (config));
- if (!strv_empty (new_environ))
+ if (finish_args != NULL)
{
- for (guint i = 0; new_environ[i]; i++)
+ for (guint i = 0; finish_args[i]; i++)
{
- if (g_utf8_strlen (new_environ[i], -1) > 1)
- {
- g_autofree gchar *env_option = NULL;
-
- env_option = g_strdup_printf ("--env=%s", new_environ[i]);
- ide_subprocess_launcher_push_argv (ret, env_option);
- }
+ if (can_pass_through_finish_arg (finish_args[i]))
+ ide_run_context_append_argv (run_context, finish_args[i]);
}
}
+ }
+ else
+ {
+ ide_run_context_append_argv (run_context, "--share=ipc");
+ ide_run_context_append_argv (run_context, "--share=network");
+ ide_run_context_append_argv (run_context, "--socket=x11");
+ ide_run_context_append_argv (run_context, "--socket=wayland");
+ }
- /* We want the configure step to be separate so IdeAutotoolsBuildTask can pass options to it */
- ide_subprocess_launcher_push_argv (ret, "--env=NOCONFIGURE=1");
+ ide_run_context_append_argv (run_context, "--talk-name=org.freedesktop.portal.*");
+ ide_run_context_append_argv (run_context, "--talk-name=org.a11y.Bus");
- ide_subprocess_launcher_push_argv (ret, build_path);
+ /* And last, before our child command, is the staging directory */
+ ide_run_context_append_argv (run_context, staging_dir);
- ide_subprocess_launcher_set_run_on_host (ret, TRUE);
- }
+ /* And now the upper layer's command arguments */
+ ide_run_context_append_args (run_context, argv);
- return ret;
+ IDE_RETURN (TRUE);
}
-static gchar *
-get_manifst_command (GbpFlatpakRuntime *self)
+static void
+gbp_flatpak_runtime_prepare_to_run (IdeRuntime *runtime,
+ IdePipeline *pipeline,
+ IdeRunContext *run_context)
{
- IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
- IdeConfigManager *config_manager = ide_config_manager_from_context (context);
- IdeConfig *config = ide_config_manager_get_current (config_manager);
+ IDE_ENTRY;
- if (GBP_IS_FLATPAK_MANIFEST (config))
- {
- const gchar *command;
+ g_assert (GBP_IS_FLATPAK_RUNTIME (runtime));
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
- command = gbp_flatpak_manifest_get_command (GBP_FLATPAK_MANIFEST (config));
- if (!ide_str_empty0 (command))
- return g_strdup (command);
- }
+ /* We have to run "flatpak build" from the host */
+ ide_run_context_push_host (run_context);
- /* Use the project id as a last resort */
- return ide_context_dup_project_id (context);
+ /* Handle the upper layer to rewrite the command using "flatpak build" */
+ ide_run_context_push (run_context,
+ gbp_flatpak_runtime_handle_run_context_cb,
+ g_object_ref (pipeline),
+ g_object_unref);
+
+ IDE_EXIT;
}
-static IdeRunner *
-gbp_flatpak_runtime_create_runner (IdeRuntime *runtime,
- IdeBuildTarget *build_target)
+static gboolean
+gbp_flatpak_runtime_handle_build_context_cb (IdeRunContext *run_context,
+ const char * const *argv,
+ const char * const *env,
+ const char *cwd,
+ IdeUnixFDMap *unix_fd_map,
+ gpointer user_data,
+ GError **error)
{
- GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)runtime;
- g_autofree gchar *build_path = NULL;
- g_autofree gchar *binary_name = NULL;
+ IdePipeline *pipeline = user_data;
+ GbpFlatpakRuntime *self;
+ g_autofree char *staging_dir = NULL;
+ g_autofree char *ccache_dir = NULL;
+ const char *srcdir;
+ const char *builddir;
IdeContext *context;
- IdeRunner *runner;
+ IdeConfig *config;
- g_assert (GBP_IS_FLATPAK_RUNTIME (self));
- g_assert (!build_target || IDE_IS_BUILD_TARGET (build_target));
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
+ g_assert (IDE_IS_UNIX_FD_MAP (unix_fd_map));
+ self = GBP_FLATPAK_RUNTIME (ide_pipeline_get_runtime (pipeline));
context = ide_object_get_context (IDE_OBJECT (self));
- build_path = get_staging_directory (self);
- binary_name = get_manifst_command (self);
+ g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+ g_assert (IDE_IS_CONTEXT (context));
+
+ /* Pass through the FD mappings */
+ if (!ide_run_context_merge_unix_fd_map (run_context, unix_fd_map, error))
+ return FALSE;
+
+ staging_dir = gbp_flatpak_get_staging_dir (pipeline);
+ srcdir = ide_pipeline_get_srcdir (pipeline);
+ builddir = ide_pipeline_get_builddir (pipeline);
+ config = ide_pipeline_get_config (pipeline);
+
+ /* Make sure our worker has access to our Builder-specific Flatpak repository */
+ ide_run_context_setenv (run_context, "FLATPAK_CONFIG_DIR", gbp_flatpak_get_config_dir ());
+
+ /* We might need access to ccache configs inside the build environ.
+ * Usually, this is set by flatpak-builder, but since we are running
+ * the incremental build, we need to take care of that too.
+ *
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=780153
+ */
+ ccache_dir = g_build_filename (g_get_user_cache_dir (),
+ ide_get_program_name (),
+ "flatpak-builder",
+ "ccache",
+ NULL);
+ ide_run_context_setenv (run_context, "CCACHE_DIR", ccache_dir);
+
+ /* We can pass the CWD directory down just fine */
+ ide_run_context_set_cwd (run_context, cwd);
+
+ /* Now setup our basic arguments for the application */
+ ide_run_context_append_argv (run_context, "flatpak");
+ ide_run_context_append_argv (run_context, "build");
+ ide_run_context_append_argv (run_context, "--with-appdir");
+ ide_run_context_append_argv (run_context, "--allow=devel");
+ ide_run_context_append_argv (run_context, "--die-with-parent");
+
+ /* Make sure we have access to the build directory */
+ ide_run_context_append_formatted (run_context, "--filesystem=%s", srcdir);
+ ide_run_context_append_formatted (run_context, "--filesystem=%s", builddir);
+ ide_run_context_append_formatted (run_context, "--filesystem=%s/gnome-builder", g_get_user_cache_dir ());
+ ide_run_context_append_argv (run_context, "--nofilesystem=host");
+
+ /* Ensure build-args are passed down */
+ if (GBP_IS_FLATPAK_MANIFEST (config))
+ {
+ const char * const *build_args = gbp_flatpak_manifest_get_build_args (GBP_FLATPAK_MANIFEST (config));
+ if (build_args != NULL)
+ ide_run_context_append_args (run_context, build_args);
+ }
+ else
+ {
+ /* Somehow got here w/o a manifest, give network access to be nice so
+ * things like meson subprojects work and git submodules work.
+ */
+ ide_run_context_append_argv (run_context, "--share=network");
+ }
+
+ /* Convert environment from upper level into --env=FOO=BAR */
+ if (env != NULL)
+ {
+ for (guint i = 0; env[i]; i++)
+ {
+ g_autofree char *arg = g_strconcat ("--env=", env[i], NULL);
+ ide_run_context_append_argv (run_context, arg);
+ }
+ }
+
+ /* And last, before our child command, is the staging directory */
+ ide_run_context_append_argv (run_context, staging_dir);
+
+ /* And now the upper layer's command arguments */
+ ide_run_context_append_args (run_context, argv);
+
+ IDE_RETURN (TRUE);
+}
+
+static void
+gbp_flatpak_runtime_prepare_to_build (IdeRuntime *runtime,
+ IdePipeline *pipeline,
+ IdeRunContext *run_context)
+{
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_RUNTIME (runtime));
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+ /* We have to run "flatpak build" from the host */
+ ide_run_context_push_host (run_context);
- if ((runner = IDE_RUNNER (gbp_flatpak_runner_new (context, build_path, build_target, binary_name))))
- ide_object_append (IDE_OBJECT (self), IDE_OBJECT (runner));
+ /* Handle the upper layer to rewrite the command using "flatpak build" */
+ ide_run_context_push (run_context,
+ gbp_flatpak_runtime_handle_build_context_cb,
+ g_object_ref (pipeline),
+ g_object_unref);
- return runner;
+ IDE_EXIT;
}
static void
@@ -321,7 +433,7 @@ gbp_flatpak_runtime_prepare_configuration (IdeRuntime *runtime,
static void
gbp_flatpak_runtime_set_deploy_dir (GbpFlatpakRuntime *self,
- const gchar *deploy_dir)
+ const char *deploy_dir)
{
g_autoptr(GFile) file = NULL;
@@ -337,13 +449,13 @@ gbp_flatpak_runtime_set_deploy_dir (GbpFlatpakRuntime *self,
}
}
-static const gchar *
+static const char *
gbp_flatpak_runtime_get_runtime_dir (GbpFlatpakRuntime *self)
{
if G_UNLIKELY (self->runtime_dir == NULL)
{
- g_autofree gchar *sdk_name = NULL;
- const gchar *ids[2];
+ g_autofree char *sdk_name = NULL;
+ const char *ids[2];
sdk_name = gbp_flatpak_runtime_get_sdk_name (self);
@@ -352,10 +464,10 @@ gbp_flatpak_runtime_get_runtime_dir (GbpFlatpakRuntime *self)
for (guint i = 0; i < G_N_ELEMENTS (ids); i++)
{
- const gchar *id = ids[i];
- g_autofree gchar *name = g_strdup_printf ("%s.Debug", id);
- g_autofree gchar *deploy_path = NULL;
- g_autofree gchar *path = NULL;
+ const char *id = ids[i];
+ g_autofree char *name = g_strdup_printf ("%s.Debug", id);
+ g_autofree char *deploy_path = NULL;
+ g_autofree char *path = NULL;
/*
* The easiest way to reliably stay within the same installation
@@ -382,11 +494,11 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
GFile *file)
{
GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)runtime;
- const gchar *runtime_dir;
- g_autofree gchar *path = NULL;
- g_autofree gchar *build_dir = NULL;
- g_autofree gchar *app_files_path = NULL;
- g_autofree gchar *debug_dir = NULL;
+ const char *runtime_dir;
+ g_autofree char *path = NULL;
+ g_autofree char *build_dir = NULL;
+ g_autofree char *app_files_path = NULL;
+ g_autofree char *debug_dir = NULL;
g_assert (GBP_IS_FLATPAK_RUNTIME (self));
g_assert (G_IS_FILE (file));
@@ -412,11 +524,11 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
{
if (g_str_has_prefix (path, "/run/build-runtime/"))
{
- g_autofree gchar *translated = NULL;
+ g_autofree char *translated = NULL;
translated = g_build_filename (runtime_dir,
"source",
- path + DZL_LITERAL_LENGTH ("/run/build-runtime/"),
+ path + strlen ("/run/build-runtime/"),
NULL);
return g_file_new_for_path (translated);
}
@@ -429,10 +541,10 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
if (g_str_has_prefix (path, "/usr/lib/debug/"))
{
- g_autofree gchar *translated = NULL;
+ g_autofree char *translated = NULL;
translated = g_build_filename (debug_dir,
- path + DZL_LITERAL_LENGTH ("/usr/lib/debug/"),
+ path + strlen ("/usr/lib/debug/"),
NULL);
return g_file_new_for_path (translated);
}
@@ -442,7 +554,7 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
return g_object_ref (self->deploy_dir_files);
if (g_str_has_prefix (path, "/usr/"))
- return g_file_get_child (self->deploy_dir_files, path + DZL_LITERAL_LENGTH ("/usr/"));
+ return g_file_get_child (self->deploy_dir_files, path + strlen ("/usr/"));
build_dir = get_staging_directory (self);
app_files_path = g_build_filename (build_dir, "files", NULL);
@@ -452,10 +564,10 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
if (g_str_has_prefix (path, "/app/"))
{
- g_autofree gchar *translated = NULL;
+ g_autofree char *translated = NULL;
translated = g_build_filename (app_files_path,
- path + DZL_LITERAL_LENGTH ("/app/"),
+ path + strlen ("/app/"),
NULL);
return g_file_new_for_path (translated);
}
@@ -485,7 +597,7 @@ gbp_flatpak_runtime_set_triplet (GbpFlatpakRuntime *self,
}
}
-const gchar *
+const char *
gbp_flatpak_runtime_get_branch (GbpFlatpakRuntime *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
@@ -495,7 +607,7 @@ gbp_flatpak_runtime_get_branch (GbpFlatpakRuntime *self)
static void
gbp_flatpak_runtime_set_branch (GbpFlatpakRuntime *self,
- const gchar *branch)
+ const char *branch)
{
g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
@@ -507,7 +619,7 @@ gbp_flatpak_runtime_set_branch (GbpFlatpakRuntime *self,
}
}
-const gchar *
+const char *
gbp_flatpak_runtime_get_platform (GbpFlatpakRuntime *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
@@ -517,7 +629,7 @@ gbp_flatpak_runtime_get_platform (GbpFlatpakRuntime *self)
static void
gbp_flatpak_runtime_set_platform (GbpFlatpakRuntime *self,
- const gchar *platform)
+ const char *platform)
{
g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
@@ -526,7 +638,7 @@ gbp_flatpak_runtime_set_platform (GbpFlatpakRuntime *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PLATFORM]);
}
-const gchar *
+const char *
gbp_flatpak_runtime_get_sdk (GbpFlatpakRuntime *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
@@ -534,10 +646,10 @@ gbp_flatpak_runtime_get_sdk (GbpFlatpakRuntime *self)
return self->sdk;
}
-gchar *
+char *
gbp_flatpak_runtime_get_sdk_name (GbpFlatpakRuntime *self)
{
- const gchar *slash;
+ const char *slash;
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
@@ -554,7 +666,7 @@ gbp_flatpak_runtime_get_sdk_name (GbpFlatpakRuntime *self)
static void
gbp_flatpak_runtime_set_sdk (GbpFlatpakRuntime *self,
- const gchar *sdk)
+ const char *sdk)
{
g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
@@ -566,11 +678,11 @@ gbp_flatpak_runtime_set_sdk (GbpFlatpakRuntime *self,
}
}
-static gchar **
+static char **
gbp_flatpak_runtime_get_system_include_dirs (IdeRuntime *runtime)
{
- static const gchar *include_dirs[] = { "/app/include", "/usr/include", NULL };
- return g_strdupv ((gchar **)include_dirs);
+ static const char *include_dirs[] = { "/app/include", "/usr/include", NULL };
+ return g_strdupv ((char **)include_dirs);
}
static IdeTriplet *
@@ -683,10 +795,10 @@ gbp_flatpak_runtime_class_init (GbpFlatpakRuntimeClass *klass)
object_class->get_property = gbp_flatpak_runtime_get_property;
object_class->set_property = gbp_flatpak_runtime_set_property;
- runtime_class->create_launcher = gbp_flatpak_runtime_create_launcher;
- runtime_class->create_runner = gbp_flatpak_runtime_create_runner;
runtime_class->contains_program_in_path = gbp_flatpak_runtime_contains_program_in_path;
runtime_class->prepare_configuration = gbp_flatpak_runtime_prepare_configuration;
+ runtime_class->prepare_to_build = gbp_flatpak_runtime_prepare_to_build;
+ runtime_class->prepare_to_run = gbp_flatpak_runtime_prepare_to_run;
runtime_class->translate_file = gbp_flatpak_runtime_translate_file;
runtime_class->get_system_include_dirs = gbp_flatpak_runtime_get_system_include_dirs;
runtime_class->get_triplet = gbp_flatpak_runtime_real_get_triplet;
@@ -746,11 +858,11 @@ gbp_flatpak_runtime_new (const char *name,
const char *metadata,
gboolean is_extension)
{
- g_autofree gchar *id = NULL;
- g_autofree gchar *short_id = NULL;
- g_autofree gchar *display_name = NULL;
- g_autofree gchar *triplet = NULL;
- g_autofree gchar *runtime_name = NULL;
+ g_autofree char *id = NULL;
+ g_autofree char *short_id = NULL;
+ g_autofree char *display_name = NULL;
+ g_autofree char *triplet = NULL;
+ g_autofree char *runtime_name = NULL;
g_autoptr(IdeTriplet) triplet_object = NULL;
g_autoptr(GString) category = NULL;
diff --git a/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
new file mode 100644
index 000000000..ee061062b
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
@@ -0,0 +1,167 @@
+/* gbp-flatpak-workbench-addin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-workbench-addin"
+
+#include "config.h"
+
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-flatpak-manifest.h"
+#include "gbp-flatpak-workbench-addin.h"
+
+struct _GbpFlatpakWorkbenchAddin
+{
+ GObject parent_instance;
+ IdeWorkbench *workbench;
+ IdeRunManager *run_manager;
+ gulong run_signal_handler;
+};
+
+static void
+gbp_flatpak_workbench_addin_run_cb (GbpFlatpakWorkbenchAddin *self,
+ IdeRunContext *run_context,
+ IdeRunManager *run_manager)
+{
+ g_autoptr(GSettingsBackend) backend = NULL;
+ g_autoptr(GSettings) gtk_settings = NULL;
+ g_autofree char *filename = NULL;
+ IdeConfigManager *config_manager;
+ IdeContext *context;
+ const char *app_id;
+ IdeConfig *config;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
+ g_assert (IDE_IS_RUN_MANAGER (run_manager));
+
+ /* This function will overwrite various settings in the application that
+ * are very useful for developing applications from Builder. It modifies
+ * the GLib GKeyFile-based settings file.
+ */
+
+ if (!(context = ide_object_get_context (IDE_OBJECT (run_manager))) ||
+ !(config_manager = ide_config_manager_from_context (context)) ||
+ !(config = ide_config_manager_get_current (config_manager)) ||
+ !GBP_IS_FLATPAK_MANIFEST (config) ||
+ !(app_id = ide_config_get_app_id (config)))
+ IDE_EXIT;
+
+ filename = g_build_filename (g_get_home_dir (), ".var", "app", app_id, "config", "glib-2.0", "settings",
"keyfile", NULL);
+ backend = g_keyfile_settings_backend_new (filename, "/", NULL);
+ gtk_settings = g_settings_new_with_backend ("org.gtk.Settings.Debug", backend);
+
+ g_settings_set_boolean (gtk_settings, "enable-inspector-keybinding", TRUE);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_workbench_addin_project_loaded (IdeWorkbenchAddin *addin,
+ IdeProjectInfo *project_info)
+{
+ GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
+ IdeRunManager *run_manager;
+ IdeContext *context;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (self->workbench));
+ g_assert (IDE_IS_PROJECT_INFO (project_info));
+
+ context = ide_workbench_get_context (self->workbench);
+ run_manager = ide_run_manager_from_context (context);
+
+ g_set_object (&self->run_manager, run_manager);
+
+ self->run_signal_handler =
+ g_signal_connect_object (run_manager,
+ "run",
+ G_CALLBACK (gbp_flatpak_workbench_addin_run_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_workbench_addin_load (IdeWorkbenchAddin *addin,
+ IdeWorkbench *workbench)
+{
+ GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (workbench));
+
+ self->workbench = workbench;
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_workbench_addin_unload (IdeWorkbenchAddin *addin,
+ IdeWorkbench *workbench)
+{
+ GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (workbench));
+
+ if (self->run_manager != NULL)
+ {
+ g_clear_signal_handler (&self->run_signal_handler, self->run_manager);
+ g_clear_object (&self->run_manager);
+ }
+
+ self->workbench = NULL;
+
+ IDE_EXIT;
+}
+
+static void
+workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
+{
+ iface->load = gbp_flatpak_workbench_addin_load;
+ iface->project_loaded = gbp_flatpak_workbench_addin_project_loaded;
+ iface->unload = gbp_flatpak_workbench_addin_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpFlatpakWorkbenchAddin, gbp_flatpak_workbench_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
+
+static void
+gbp_flatpak_workbench_addin_class_init (GbpFlatpakWorkbenchAddinClass *klass)
+{
+}
+
+static void
+gbp_flatpak_workbench_addin_init (GbpFlatpakWorkbenchAddin *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-build-target.h
b/src/plugins/flatpak/gbp-flatpak-workbench-addin.h
similarity index 70%
rename from src/plugins/flatpak/gbp-flatpak-build-target.h
rename to src/plugins/flatpak/gbp-flatpak-workbench-addin.h
index 10c29e59a..f0c802eff 100644
--- a/src/plugins/flatpak/gbp-flatpak-build-target.h
+++ b/src/plugins/flatpak/gbp-flatpak-workbench-addin.h
@@ -1,6 +1,6 @@
-/* gbp-flatpak-build-target.h
+/* gbp-flatpak-workbench-addin.h
*
- * Copyright 2017-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2022 Christian Hergert <chergert redhat com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,12 +20,12 @@
#pragma once
-#include <libide-foundry.h>
+#include <libide-gui.h>
G_BEGIN_DECLS
-#define GBP_TYPE_FLATPAK_BUILD_TARGET (gbp_flatpak_build_target_get_type())
+#define GBP_TYPE_FLATPAK_WORKBENCH_ADDIN (gbp_flatpak_workbench_addin_get_type())
-G_DECLARE_FINAL_TYPE (GbpFlatpakBuildTarget, gbp_flatpak_build_target, GBP, FLATPAK_BUILD_TARGET, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpFlatpakWorkbenchAddin, gbp_flatpak_workbench_addin, GBP, FLATPAK_WORKBENCH_ADDIN,
GObject)
G_END_DECLS
diff --git a/src/plugins/flatpak/ipc-flatpak-transfer-impl.c b/src/plugins/flatpak/ipc-flatpak-transfer-impl.c
index 7cc0d2892..deed8d5ca 100644
--- a/src/plugins/flatpak/ipc-flatpak-transfer-impl.c
+++ b/src/plugins/flatpak/ipc-flatpak-transfer-impl.c
@@ -98,7 +98,7 @@ ipc_flatpak_transfer_impl_handle_confirm (IpcFlatpakTransfer *transfer,
if (gbp_flatpak_install_dialog_is_empty (dialog))
{
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_window_destroy (GTK_WINDOW (dialog));
ipc_flatpak_transfer_complete_confirm (transfer, g_steal_pointer (&invocation));
return TRUE;
}
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index 8424e915d..88705eeec 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -17,23 +17,20 @@ plugins_sources += files([
'flatpak-plugin.c',
'gbp-flatpak-aux.c',
'gbp-flatpak-build-system-discovery.c',
- 'gbp-flatpak-build-target-provider.c',
- 'gbp-flatpak-build-target.c',
'gbp-flatpak-client.c',
- 'gbp-flatpak-clone-widget.c',
'gbp-flatpak-config-provider.c',
'gbp-flatpak-dependency-updater.c',
'gbp-flatpak-download-stage.c',
'gbp-flatpak-install-dialog.c',
'gbp-flatpak-manifest.c',
'gbp-flatpak-pipeline-addin.c',
- 'gbp-flatpak-runner.c',
+ 'gbp-flatpak-run-command-provider.c',
'gbp-flatpak-runtime-provider.c',
'gbp-flatpak-runtime.c',
'gbp-flatpak-sdk-stage.c',
'gbp-flatpak-sources.c',
- 'gbp-flatpak-subprocess-launcher.c',
'gbp-flatpak-util.c',
+ 'gbp-flatpak-workbench-addin.c',
'ipc-flatpak-transfer-impl.c',
])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]