[gnome-builder/wip/tintou/runtime-triplet: 25/25] runtime: use IdeToolchain to handle the architecture
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/tintou/runtime-triplet: 25/25] runtime: use IdeToolchain to handle the architecture
- Date: Thu, 17 May 2018 13:54:36 +0000 (UTC)
commit 55e4b731cdc25afec89365af74a6caeedcc98eb6
Author: Corentin Noël <corentin noel collabora co uk>
Date: Thu Apr 26 12:39:27 2018 +0200
runtime: use IdeToolchain to handle the architecture
Phabricator: T9071
src/libide/runtimes/ide-runtime.c | 46 ++++++++++++++---
src/libide/runtimes/ide-runtime.h | 5 +-
src/plugins/flatpak/gbp-flatpak-runtime-provider.c | 4 +-
src/plugins/flatpak/gbp-flatpak-runtime.c | 59 ++++++++++++----------
src/plugins/flatpak/gbp-flatpak-runtime.h | 2 +-
src/plugins/sysroot/gbp-sysroot-runtime.c | 10 ++--
src/tests/test-ide-runtime.c | 8 +--
7 files changed, 88 insertions(+), 46 deletions(-)
---
diff --git a/src/libide/runtimes/ide-runtime.c b/src/libide/runtimes/ide-runtime.c
index f60fb20bf..17838a4c8 100644
--- a/src/libide/runtimes/ide-runtime.c
+++ b/src/libide/runtimes/ide-runtime.c
@@ -552,17 +552,50 @@ ide_runtime_get_system_include_dirs (IdeRuntime *self)
return g_strdupv ((gchar **)basic);
}
+/**
+ * ide_runtime_get_triplet:
+ * @self: a #IdeRuntime
+ *
+ * Gets the architecture triplet of the runtime.
+ *
+ * This can be used to ensure we're compiling for the right architecture
+ * given the current device.
+ *
+ * Returns: (transfer full) (not nullable): the architecture triplet the runtime
+ * will build for.
+ *
+ * Since: 3.30
+ */
+IdeTriplet *
+ide_runtime_get_triplet (IdeRuntime *self)
+{
+ IdeTriplet *ret = NULL;
+
+ g_return_val_if_fail (IDE_IS_RUNTIME (self), NULL);
+
+ if (IDE_RUNTIME_GET_CLASS (self)->get_triplet)
+ ret = IDE_RUNTIME_GET_CLASS (self)->get_triplet (self);
+
+ if (ret == NULL)
+ ret = ide_triplet_new_from_system ();
+
+ return ret;
+}
+
/**
* ide_runtime_get_arch:
* @self: a #IdeRuntime
*
- * Get's the architecture of the runtime.
+ * Gets the architecture of the runtime.
*
* This can be used to ensure we're compiling for the right architecture
* given the current device.
*
+ * This is strictly equivalent to calling #ide_triplet_get_arch on the result
+ * of #ide_runtime_get_triplet.
+ *
* Returns: (transfer full) (not nullable): the name of the architecture
- * the runtime will build for.
+ * the runtime will build for.
*
* Since: 3.28
*/
@@ -570,14 +603,13 @@ gchar *
ide_runtime_get_arch (IdeRuntime *self)
{
gchar *ret = NULL;
+ g_autoptr(IdeTriplet) triplet = NULL;
g_return_val_if_fail (IDE_IS_RUNTIME (self), NULL);
- if (IDE_RUNTIME_GET_CLASS (self)->get_arch)
- ret = IDE_RUNTIME_GET_CLASS (self)->get_arch (self);
-
- if (ret == NULL)
- ret = ide_get_system_arch ();
+ triplet = ide_runtime_get_triplet (self);
+ ret = g_strdup (ide_triplet_get_arch (triplet));
return ret;
}
+
diff --git a/src/libide/runtimes/ide-runtime.h b/src/libide/runtimes/ide-runtime.h
index 48961bb0a..82d8745f0 100644
--- a/src/libide/runtimes/ide-runtime.h
+++ b/src/libide/runtimes/ide-runtime.h
@@ -27,6 +27,7 @@
#include "buildsystem/ide-build-target.h"
#include "runner/ide-runner.h"
#include "subprocess/ide-subprocess-launcher.h"
+#include "util/ide-triplet.h"
G_BEGIN_DECLS
@@ -57,7 +58,7 @@ struct _IdeRuntimeClass
GFile *(*translate_file) (IdeRuntime *self,
GFile *file);
gchar **(*get_system_include_dirs) (IdeRuntime *self);
- gchar *(*get_arch) (IdeRuntime *self);
+ IdeTriplet *(*get_triplet) (IdeRuntime *self);
gpointer _reserved[12];
};
@@ -98,5 +99,7 @@ IDE_AVAILABLE_IN_3_28
gchar **ide_runtime_get_system_include_dirs (IdeRuntime *self);
IDE_AVAILABLE_IN_3_28
gchar *ide_runtime_get_arch (IdeRuntime *self);
+IDE_AVAILABLE_IN_3_30
+IdeTriplet *ide_runtime_get_triplet (IdeRuntime *self);
G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index 60ce4f210..649231901 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -103,10 +103,12 @@ static gboolean
is_same_runtime (GbpFlatpakRuntime *runtime,
FlatpakInstalledRef *ref)
{
+ g_autofree gchar *arch = NULL;
+
return (g_strcmp0 (flatpak_ref_get_name (FLATPAK_REF (ref)),
gbp_flatpak_runtime_get_platform (runtime)) == 0) &&
(g_strcmp0 (flatpak_ref_get_arch (FLATPAK_REF (ref)),
- gbp_flatpak_runtime_get_arch (runtime)) == 0) &&
+ arch = ide_runtime_get_arch (IDE_RUNTIME (runtime))) == 0) &&
(g_strcmp0 (flatpak_ref_get_branch (FLATPAK_REF (ref)),
gbp_flatpak_runtime_get_branch (runtime)) == 0);
}
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index b968f5b15..72e89141f 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -35,7 +35,7 @@ struct _GbpFlatpakRuntime
GHashTable *program_paths_cache;
- gchar *arch;
+ IdeTriplet *triplet;
gchar *branch;
gchar *deploy_dir;
gchar *platform;
@@ -48,7 +48,7 @@ G_DEFINE_TYPE (GbpFlatpakRuntime, gbp_flatpak_runtime, IDE_TYPE_RUNTIME)
enum {
PROP_0,
- PROP_ARCH,
+ PROP_TRIPLET,
PROP_BRANCH,
PROP_DEPLOY_DIR,
PROP_PLATFORM,
@@ -102,7 +102,7 @@ gbp_flatpak_runtime_contains_program_in_path (IdeRuntime *runtime,
if (g_hash_table_contains (self->program_paths_cache, program))
return TRUE;
- arch = g_strdup_printf ("--arch=%s", self->arch);
+ arch = g_strdup_printf ("--arch=%s", ide_triplet_get_arch (self->triplet));
/*
* To check if a program is available, we don't want to use the normal
@@ -406,7 +406,8 @@ gbp_flatpak_runtime_get_runtime_dir (GbpFlatpakRuntime *self)
*/
deploy_path = g_file_get_path (self->deploy_dir_files);
path = g_build_filename (deploy_path, "..", "..", "..", "..", "..",
- name, self->arch, self->branch, "active", "files",
+ name, ide_triplet_get_arch (self->triplet),
+ self->branch, "active", "files",
NULL);
if (g_file_test (path, G_FILE_TEST_IS_DIR))
{
@@ -505,25 +506,25 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
return NULL;
}
-const gchar *
-gbp_flatpak_runtime_get_arch (GbpFlatpakRuntime *self)
+IdeTriplet *
+gbp_flatpak_runtime_get_triplet (GbpFlatpakRuntime *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
- return self->arch;
+ return self->triplet;
}
void
-gbp_flatpak_runtime_set_arch (GbpFlatpakRuntime *self,
- const gchar *arch)
+gbp_flatpak_runtime_set_triplet (GbpFlatpakRuntime *self,
+ IdeTriplet *triplet)
{
g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
- if (g_strcmp0 (arch, self->arch) != 0)
+ if (self->triplet != triplet)
{
- g_free (self->arch);
- self->arch = g_strdup (arch);
- g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ARCH]);
+ g_clear_pointer (&self->triplet, ide_triplet_unref);
+ self->triplet = ide_triplet_ref (triplet);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TRIPLET]);
}
}
@@ -615,10 +616,10 @@ gbp_flatpak_runtime_get_system_include_dirs (IdeRuntime *runtime)
return g_strdupv ((gchar **)include_dirs);
}
-static gchar *
-gbp_flatpak_runtime_real_get_arch (IdeRuntime *runtime)
+static IdeTriplet *
+gbp_flatpak_runtime_real_get_triplet (IdeRuntime *runtime)
{
- return g_strdup (GBP_FLATPAK_RUNTIME (runtime)->arch);
+ return ide_triplet_ref (GBP_FLATPAK_RUNTIME (runtime)->triplet);
}
static void
@@ -631,8 +632,8 @@ gbp_flatpak_runtime_get_property (GObject *object,
switch (prop_id)
{
- case PROP_ARCH:
- g_value_set_string (value, gbp_flatpak_runtime_get_arch (self));
+ case PROP_TRIPLET:
+ g_value_set_boxed (value, gbp_flatpak_runtime_get_triplet (self));
break;
case PROP_BRANCH:
@@ -666,8 +667,8 @@ gbp_flatpak_runtime_set_property (GObject *object,
switch (prop_id)
{
- case PROP_ARCH:
- gbp_flatpak_runtime_set_arch (self, g_value_get_string (value));
+ case PROP_TRIPLET:
+ gbp_flatpak_runtime_set_triplet (self, g_value_get_boxed (value));
break;
case PROP_BRANCH:
@@ -696,7 +697,7 @@ gbp_flatpak_runtime_finalize (GObject *object)
{
GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)object;
- g_clear_pointer (&self->arch, g_free);
+ g_clear_pointer (&self->triplet, ide_triplet_unref);
g_clear_pointer (&self->branch, g_free);
g_clear_pointer (&self->runtime_dir, g_free);
g_clear_pointer (&self->deploy_dir, g_free);
@@ -724,13 +725,13 @@ gbp_flatpak_runtime_class_init (GbpFlatpakRuntimeClass *klass)
runtime_class->prepare_configuration = gbp_flatpak_runtime_prepare_configuration;
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_arch = gbp_flatpak_runtime_real_get_arch;
+ runtime_class->get_triplet = gbp_flatpak_runtime_real_get_triplet;
- properties [PROP_ARCH] =
- g_param_spec_string ("arch",
- "Arch",
- "Arch",
- flatpak_get_default_arch (),
+ properties [PROP_TRIPLET] =
+ g_param_spec_boxed ("triplet",
+ "Triplet",
+ "Architecture Triplet",
+ IDE_TYPE_TRIPLET,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
properties [PROP_BRANCH] =
@@ -795,6 +796,7 @@ gbp_flatpak_runtime_new (IdeContext *context,
g_autofree gchar *display_name = NULL;
g_autofree gchar *triplet = NULL;
g_autoptr(FlatpakRef) sdk_ref = NULL;
+ g_autoptr(IdeTriplet) triplet_object = NULL;
const gchar *name;
const gchar *arch;
const gchar *branch;
@@ -807,6 +809,7 @@ gbp_flatpak_runtime_new (IdeContext *context,
arch = flatpak_ref_get_arch (FLATPAK_REF (ref));
branch = flatpak_ref_get_branch (FLATPAK_REF (ref));
deploy_dir = flatpak_installed_ref_get_deploy_dir (ref);
+ triplet_object = ide_triplet_new (arch);
triplet = g_strdup_printf ("%s/%s/%s", name, arch, branch);
id = g_strdup_printf ("flatpak:%s", triplet);
@@ -835,7 +838,7 @@ gbp_flatpak_runtime_new (IdeContext *context,
return g_object_new (GBP_TYPE_FLATPAK_RUNTIME,
"context", context,
"id", id,
- "arch", arch,
+ "triplet", triplet_object,
"branch", branch,
"deploy-dir", deploy_dir,
"display-name", display_name,
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.h b/src/plugins/flatpak/gbp-flatpak-runtime.h
index d295c909d..b68086fca 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.h
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.h
@@ -34,7 +34,7 @@ GbpFlatpakRuntime *gbp_flatpak_runtime_new (IdeContext *con
FlatpakInstalledRef *ref,
GCancellable *cancellable,
GError **error);
-const gchar *gbp_flatpak_runtime_get_arch (GbpFlatpakRuntime *self);
+IdeTriplet *gbp_flatpak_runtime_get_triplet (GbpFlatpakRuntime *self);
const gchar *gbp_flatpak_runtime_get_branch (GbpFlatpakRuntime *self);
const gchar *gbp_flatpak_runtime_get_platform (GbpFlatpakRuntime *self);
const gchar *gbp_flatpak_runtime_get_sdk (GbpFlatpakRuntime *self);
diff --git a/src/plugins/sysroot/gbp-sysroot-runtime.c b/src/plugins/sysroot/gbp-sysroot-runtime.c
index d32e7f4a0..d18c4cae0 100644
--- a/src/plugins/sysroot/gbp-sysroot-runtime.c
+++ b/src/plugins/sysroot/gbp-sysroot-runtime.c
@@ -163,11 +163,12 @@ gbp_sysroot_runtime_get_system_include_dirs (IdeRuntime *runtime)
return g_strdupv ((char**) result_paths);
}
-static gchar *
-gbp_sysroot_runtime_get_arch (IdeRuntime *runtime)
+static IdeTriplet *
+gbp_sysroot_runtime_get_triplet (IdeRuntime *runtime)
{
GbpSysrootRuntime *self = GBP_SYSROOT_RUNTIME(runtime);
GbpSysrootManager *sysroot_manager = NULL;
+ g_autofree gchar *target_arch = NULL;
const gchar *sysroot_id = NULL;
g_assert (GBP_IS_SYSROOT_RUNTIME (self));
@@ -175,7 +176,8 @@ gbp_sysroot_runtime_get_arch (IdeRuntime *runtime)
sysroot_manager = gbp_sysroot_manager_get_default ();
sysroot_id = gbp_sysroot_runtime_get_sysroot_id (self);
- return gbp_sysroot_manager_get_target_arch (sysroot_manager, sysroot_id);
+ target_arch = gbp_sysroot_manager_get_target_arch (sysroot_manager, sysroot_id);
+ return ide_triplet_new (target_arch);
}
static void
@@ -228,7 +230,7 @@ gbp_sysroot_runtime_class_init (GbpSysrootRuntimeClass *klass)
runtime_class->create_launcher = gbp_sysroot_runtime_create_launcher;
runtime_class->get_system_include_dirs = gbp_sysroot_runtime_get_system_include_dirs;
- runtime_class->get_arch = gbp_sysroot_runtime_get_arch;
+ runtime_class->get_triplet = gbp_sysroot_runtime_get_triplet;
}
static void
diff --git a/src/tests/test-ide-runtime.c b/src/tests/test-ide-runtime.c
index aa1e3ff62..7542f5dd0 100644
--- a/src/tests/test-ide-runtime.c
+++ b/src/tests/test-ide-runtime.c
@@ -33,7 +33,7 @@ context_loaded (GObject *object,
g_autoptr(GError) error = NULL;
IdeRuntimeManager *runtime_manager;
IdeRuntime *runtime;
- g_autofree gchar *arch = NULL;
+ g_autoptr(IdeTriplet) triplet = NULL;
context = ide_context_new_finish (result, &error);
g_assert_no_error (error);
@@ -48,9 +48,9 @@ context_loaded (GObject *object,
g_assert_nonnull (runtime);
g_assert (IDE_IS_RUNTIME (runtime));
- arch = ide_runtime_get_arch (runtime);
- g_assert_nonnull (arch);
- g_assert_cmpstr (arch, ==, ide_get_system_arch ());
+ triplet = ide_runtime_get_triplet (runtime);
+ g_assert_nonnull (triplet);
+ g_assert_true (triplet == ide_triplet_new_from_system ());
g_task_return_boolean (task, TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]