[gnome-builder] flatpak: track the deploy-dir when creating flatpak runtime instances
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: track the deploy-dir when creating flatpak runtime instances
- Date: Wed, 14 Dec 2016 01:21:03 +0000 (UTC)
commit 0b46d70f8d305a1f59dc255bcbdc9f7b08895000
Author: Christian Hergert <chergert redhat com>
Date: Tue Dec 13 17:20:16 2016 -0800
flatpak: track the deploy-dir when creating flatpak runtime instances
This allows us to know where the base of files are for a given runtime.
Doing so allows us to provide plugins such as clang with access to the
include paths it needs to resolve headers for compilation units.
plugins/flatpak/gbp-flatpak-runtime-provider.c | 69 +++++++++++++--
plugins/flatpak/gbp-flatpak-runtime.c | 107 ++++++++++++++++++++++--
2 files changed, 160 insertions(+), 16 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-runtime-provider.c b/plugins/flatpak/gbp-flatpak-runtime-provider.c
index 93df269..9a01bfe 100644
--- a/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -138,6 +138,7 @@ gbp_flatpak_runtime_provider_load_refs (GbpFlatpakRuntimeProvider *self,
g_autofree gchar *sdk = NULL;
g_autoptr(GKeyFile) key_file = NULL;
const gchar *metadata_data;
+ const gchar *deploy_dir;
gsize metadata_len;
g_autoptr(GError) local_error = NULL;
@@ -165,6 +166,7 @@ gbp_flatpak_runtime_provider_load_refs (GbpFlatpakRuntimeProvider *self,
else
str = g_strdup_printf ("%s <b>%s</b> <sup>%s</sup>", name, branch, arch);
+ deploy_dir = flatpak_installed_ref_get_deploy_dir (FLATPAK_INSTALLED_REF (ref));
metadata = flatpak_installed_ref_load_metadata (FLATPAK_INSTALLED_REF (ref), cancellable,
&local_error);
if (metadata == NULL)
@@ -199,11 +201,12 @@ gbp_flatpak_runtime_provider_load_refs (GbpFlatpakRuntimeProvider *self,
g_ptr_array_add (runtimes,
g_object_new (GBP_TYPE_FLATPAK_RUNTIME,
"branch", branch,
- "sdk", sdk,
- "platform", name,
"context", context,
- "id", id,
+ "deploy-dir", deploy_dir,
"display-name", str,
+ "id", id,
+ "platform", name,
+ "sdk", sdk,
NULL));
}
@@ -353,6 +356,48 @@ gbp_flatpak_runtime_provider_find_flatpak_manifests (GbpFlatpakRuntimeProvider *
return ar;
}
+static gchar *
+find_deploy_dir (GbpFlatpakRuntimeProvider *self,
+ const gchar *name,
+ const gchar *arch,
+ const gchar *branch,
+ GCancellable *cancellable)
+{
+ FlatpakInstallation *installations[2];
+
+ g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ installations[0] = self->user_installation;
+ installations[1] = self->system_installation;
+
+ for (guint i = 0; i < G_N_ELEMENTS (installations); i++)
+ {
+ FlatpakInstallation *installation = installations[i];
+ g_autoptr(FlatpakInstalledRef) ref = NULL;
+
+ ref = flatpak_installation_get_installed_ref (installation,
+ FLATPAK_REF_KIND_RUNTIME,
+ name,
+ arch,
+ branch,
+ cancellable,
+ NULL);
+
+ if (ref != NULL)
+ {
+ const gchar *deploy_dir;
+
+ deploy_dir = flatpak_installed_ref_get_deploy_dir (ref);
+
+ if (deploy_dir != NULL)
+ return g_strdup (deploy_dir);
+ }
+ }
+
+ return NULL;
+}
+
static gboolean
gbp_flatpak_runtime_provider_load_manifests (GbpFlatpakRuntimeProvider *self,
GPtrArray *runtimes,
@@ -401,6 +446,7 @@ gbp_flatpak_runtime_provider_load_manifests (GbpFlatpakRuntimeProvider *self,
g_autofree gchar *id = NULL;
g_autofree gchar *manifest_data = NULL;
g_autofree gchar *path = NULL;
+ g_autofree gchar *deploy_dir = NULL;
gsize manifest_data_len = 0;
path = g_file_get_path (manifest->file);
@@ -424,17 +470,22 @@ gbp_flatpak_runtime_provider_load_manifests (GbpFlatpakRuntimeProvider *self,
if (contains_id (runtimes, id))
continue;
+ deploy_dir = find_deploy_dir (self, manifest->sdk, NULL, manifest->branch, cancellable);
+ if (deploy_dir == NULL)
+ deploy_dir = find_deploy_dir (self, manifest->platform, NULL, manifest->branch, cancellable);
+
g_ptr_array_add (runtimes,
g_object_new (GBP_TYPE_FLATPAK_RUNTIME,
- "branch", manifest->branch,
- "sdk", manifest->sdk,
- "platform", manifest->platform,
- "manifest", manifest->file,
- "primary-module", manifest->primary_module,
"app-id", manifest->app_id,
+ "branch", manifest->branch,
"context", context,
- "id", id,
+ "deploy-dir", deploy_dir,
"display-name", filename,
+ "id", id,
+ "manifest", manifest->file,
+ "platform", manifest->platform,
+ "primary-module", manifest->primary_module,
+ "sdk", manifest->sdk,
NULL));
}
diff --git a/plugins/flatpak/gbp-flatpak-runtime.c b/plugins/flatpak/gbp-flatpak-runtime.c
index 63a9149..762c97c 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/plugins/flatpak/gbp-flatpak-runtime.c
@@ -29,11 +29,13 @@ struct _GbpFlatpakRuntime
{
IdeRuntime parent_instance;
- gchar *sdk;
- gchar *platform;
+ gchar *app_id;
gchar *branch;
+ gchar *deploy_dir;
+ gchar *platform;
gchar *primary_module;
- gchar *app_id;
+ gchar *sdk;
+ GFile *deploy_dir_files;
GFile *manifest;
};
@@ -41,16 +43,17 @@ G_DEFINE_TYPE (GbpFlatpakRuntime, gbp_flatpak_runtime, IDE_TYPE_RUNTIME)
enum {
PROP_0,
+ PROP_APP_ID,
PROP_BRANCH,
+ PROP_DEPLOY_DIR,
+ PROP_MANIFEST,
PROP_PLATFORM,
- PROP_SDK,
PROP_PRIMARY_MODULE,
- PROP_APP_ID,
- PROP_MANIFEST,
+ PROP_SDK,
N_PROPS
};
-static GParamSpec *properties [LAST_PROP];
+static GParamSpec *properties [N_PROPS];
static gchar *
get_build_directory (GbpFlatpakRuntime *self)
@@ -900,6 +903,76 @@ gbp_flatpak_runtime_prepare_configuration (IdeRuntime *runtime,
}
static void
+gbp_flatpak_runtime_set_deploy_dir (GbpFlatpakRuntime *self,
+ const gchar *deploy_dir)
+{
+ g_autoptr(GFile) file = NULL;
+
+ g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+ g_assert (self->deploy_dir == NULL);
+ g_assert (self->deploy_dir_files == NULL);
+
+ if (deploy_dir != NULL)
+ {
+ self->deploy_dir = g_strdup (deploy_dir);
+ file = g_file_new_for_path (deploy_dir);
+ self->deploy_dir_files = g_file_get_child (file, "files");
+ }
+}
+
+static GFile *
+gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
+ GFile *file)
+{
+ GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)runtime;
+ g_autofree gchar *path = NULL;
+ g_autofree gchar *build_dir = NULL;
+ g_autofree gchar *app_files_path = NULL;
+
+ g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+ g_assert (G_IS_FILE (file));
+
+ /*
+ * If we have a manifest and the runtime is not yet installed,
+ * then we can't do a whole lot right now. We have to wait for
+ * the runtime to be installed and a new runtime instance will
+ * be loaded.
+ */
+ if (self->deploy_dir_files == NULL || self->deploy_dir == NULL)
+ return NULL;
+
+ if (!g_file_is_native (file))
+ return NULL;
+
+ if (NULL == (path = g_file_get_path (file)))
+ return NULL;
+
+ if (g_str_equal ("/usr", path))
+ 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 + IDE_LITERAL_LENGTH ("/usr/"));
+
+ build_dir = get_build_directory (self);
+ app_files_path = g_build_filename (build_dir, "files", NULL);
+
+ if (g_str_equal (path, "/app"))
+ return g_file_new_for_path (app_files_path);
+
+ if (g_str_has_prefix (path, "/app/"))
+ {
+ g_autofree gchar *translated = NULL;
+
+ translated = g_build_filename (app_files_path,
+ path + IDE_LITERAL_LENGTH ("/app/"),
+ NULL);
+ return g_file_new_for_path (translated);
+ }
+
+ return NULL;
+}
+
+static void
gbp_flatpak_runtime_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -933,6 +1006,10 @@ gbp_flatpak_runtime_get_property (GObject *object,
g_value_set_object (value, self->manifest);
break;
+ case PROP_DEPLOY_DIR:
+ g_value_set_string (value, self->deploy_dir);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
@@ -972,6 +1049,10 @@ gbp_flatpak_runtime_set_property (GObject *object,
self->manifest = g_value_dup_object (value);
break;
+ case PROP_DEPLOY_DIR:
+ gbp_flatpak_runtime_set_deploy_dir (self, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
@@ -987,6 +1068,8 @@ gbp_flatpak_runtime_finalize (GObject *object)
g_clear_pointer (&self->branch, g_free);
g_clear_pointer (&self->primary_module, g_free);
g_clear_pointer (&self->app_id, g_free);
+ g_clear_pointer (&self->deploy_dir, g_free);
+ g_clear_object (&self->deploy_dir_files);
g_clear_object (&self->manifest);
G_OBJECT_CLASS (gbp_flatpak_runtime_parent_class)->finalize (object);
@@ -1010,6 +1093,7 @@ gbp_flatpak_runtime_class_init (GbpFlatpakRuntimeClass *klass)
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->translate_file = gbp_flatpak_runtime_translate_file;
properties [PROP_BRANCH] =
g_param_spec_string ("branch",
@@ -1020,6 +1104,15 @@ gbp_flatpak_runtime_class_init (GbpFlatpakRuntimeClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+ properties [PROP_DEPLOY_DIR] =
+ g_param_spec_string ("deploy-dir",
+ "Deploy Directory",
+ "The flatpak runtime deploy directory",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
properties [PROP_PLATFORM] =
g_param_spec_string ("platform",
"Platform",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]