[gnome-builder] flatpak: add API to get default arch from service
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: add API to get default arch from service
- Date: Mon, 3 May 2021 18:33:33 +0000 (UTC)
commit a47b9f4b1e82e669c113dd6be783c472ea814a02
Author: Christian Hergert <chergert redhat com>
Date: Mon May 3 11:27:23 2021 -0700
flatpak: add API to get default arch from service
.../flatpak/daemon/ipc-flatpak-service-impl.c | 2 ++
.../daemon/org.gnome.Builder.Flatpak.Service.xml | 4 +++
src/plugins/flatpak/daemon/test-flatpak.c | 15 ++++++++++
src/plugins/flatpak/gbp-flatpak-util.c | 32 ++++++++++++++++++++++
src/plugins/flatpak/gbp-flatpak-util.h | 15 +++++-----
5 files changed, 61 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
index 21c7461e1..122d779a7 100644
--- a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
+++ b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
@@ -912,6 +912,8 @@ ipc_flatpak_service_impl_constructed (GObject *object)
G_OBJECT_CLASS (ipc_flatpak_service_impl_parent_class)->constructed (object);
+ ipc_flatpak_service_set_default_arch (IPC_FLATPAK_SERVICE (self), flatpak_get_default_arch ());
+
user_file = g_file_new_build_filename (g_get_home_dir (), ".local", "share", "flatpak", NULL);
if ((user = flatpak_installation_new_for_path (user_file, TRUE, NULL, NULL)))
add_installation (self, user, NULL);
diff --git a/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Service.xml
b/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Service.xml
index 4f866678c..6ef120fdf 100644
--- a/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Service.xml
+++ b/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Service.xml
@@ -21,6 +21,10 @@
SPDX-License-Identifier: GPL-3.0-or-later
-->
<interface name="org.gnome.Builder.Flatpak.Service">
+ <!--
+ The default architecture of the system, such as "x86_64".
+ -->
+ <property name="DefaultArch" type="s" access="read"/>
<signal name="RuntimeAdded">
<!--
Param is (name, arch, branch, sdk_name, sdk_branch, metadata, is_sdk_extension)
diff --git a/src/plugins/flatpak/daemon/test-flatpak.c b/src/plugins/flatpak/daemon/test-flatpak.c
index 5cfc89c7d..b3e3b160a 100644
--- a/src/plugins/flatpak/daemon/test-flatpak.c
+++ b/src/plugins/flatpak/daemon/test-flatpak.c
@@ -166,6 +166,21 @@ main (gint argc,
g_assert_no_error (error);
g_assert_true (IPC_IS_FLATPAK_SERVICE (service));
+ {
+ const char *default_arch;
+ g_message ("Checking DefaultArch property");
+ default_arch = ipc_flatpak_service_get_default_arch (service);
+#if defined(__x86_64__)
+ g_assert_cmpstr (default_arch, ==, "x86_64");
+#elif defined(__i386__)
+ g_assert_cmpstr (default_arch, ==, "i386");
+#elif defined(__aarch64__)
+ g_assert_cmpstr (default_arch, ==, "aarch64");
+#else
+# warning "Please add your compiler to the test for default arch property!"
+#endif
+ }
+
g_signal_connect (service,
"runtime-added",
G_CALLBACK (on_runtime_added_cb),
diff --git a/src/plugins/flatpak/gbp-flatpak-util.c b/src/plugins/flatpak/gbp-flatpak-util.c
index 4b60733d5..8479ecc94 100644
--- a/src/plugins/flatpak/gbp-flatpak-util.c
+++ b/src/plugins/flatpak/gbp-flatpak-util.c
@@ -25,6 +25,7 @@
#include <libide-foundry.h>
#include <libide-vcs.h>
+#include "gbp-flatpak-client.h"
#include "gbp-flatpak-util.h"
gchar *
@@ -128,3 +129,34 @@ gbp_flatpak_split_id (const gchar *str,
return TRUE;
}
+
+static const char *
+_gbp_flatpak_get_default_arch (IdeObject *object)
+{
+ if (object != NULL)
+ {
+ g_autoptr(IdeContext) context = ide_object_ref_context (object);
+
+ if (context != NULL)
+ {
+ g_autoptr(GbpFlatpakClient) client = gbp_flatpak_client_ensure (context);
+ IpcFlatpakService *service = gbp_flatpak_client_get_service (client, NULL, NULL);
+
+ if (service != NULL)
+ return ipc_flatpak_service_get_default_arch (service);
+ }
+ }
+
+ return ide_get_system_arch ();
+}
+
+const char *
+gbp_flatpak_get_default_arch (IdeObject *object)
+{
+ static char *default_arch;
+
+ if (default_arch == NULL)
+ default_arch = g_strdup (_gbp_flatpak_get_default_arch (object));
+
+ return default_arch;
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-util.h b/src/plugins/flatpak/gbp-flatpak-util.h
index c56b13676..63da8443d 100644
--- a/src/plugins/flatpak/gbp-flatpak-util.h
+++ b/src/plugins/flatpak/gbp-flatpak-util.h
@@ -24,12 +24,13 @@
G_BEGIN_DECLS
-gboolean gbp_flatpak_is_ignored (const gchar *name);
-gchar *gbp_flatpak_get_repo_dir (IdeContext *context);
-gchar *gbp_flatpak_get_staging_dir (IdePipeline *pipeline);
-gboolean gbp_flatpak_split_id (const gchar *str,
- gchar **id,
- gchar **arch,
- gchar **branch);
+const char *gbp_flatpak_get_default_arch (IdeObject *object);
+gboolean gbp_flatpak_is_ignored (const gchar *name);
+gchar *gbp_flatpak_get_repo_dir (IdeContext *context);
+gchar *gbp_flatpak_get_staging_dir (IdePipeline *pipeline);
+gboolean gbp_flatpak_split_id (const gchar *str,
+ gchar **id,
+ gchar **arch,
+ gchar **branch);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]