builder: handle module-relative paths for json includes

I.e. each include is relative to the location of the "parent"
json directory.
This commit is contained in:
Alexander Larsson
2017-04-19 17:46:28 +02:00
parent 7da0726514
commit d60bfcdf95
4 changed files with 33 additions and 10 deletions

View File

@@ -403,12 +403,12 @@ main (int argc,
}
/* Can't push this as user data to the demarshalling :/ */
builder_manifest_set_demarshal_buid_context (build_context);
builder_manifest_set_demarshal_base_dir (builder_context_get_base_dir (build_context));
manifest = (BuilderManifest *) json_gobject_from_data (BUILDER_TYPE_MANIFEST,
json, -1, &error);
builder_manifest_set_demarshal_buid_context (NULL);
builder_manifest_set_demarshal_base_dir (NULL);
if (manifest == NULL)
{

View File

@@ -36,12 +36,18 @@
#define LOCALES_SEPARATE_DIR "share/runtime/locale"
static BuilderContext *demarshal_build_context = NULL;
static GFile *demarshal_base_dir = NULL;
void
builder_manifest_set_demarshal_buid_context (BuilderContext *build_context)
builder_manifest_set_demarshal_base_dir (GFile *dir)
{
g_set_object (&demarshal_build_context, build_context);
g_set_object (&demarshal_base_dir, dir);
}
GFile *
builder_manifest_get_demarshal_base_dir (void)
{
return g_object_ref (demarshal_base_dir);
}
struct BuilderManifest
@@ -954,15 +960,19 @@ builder_manifest_deserialize_property (JsonSerializable *serializable,
{
const char *module_relpath = json_node_get_string (element_node);
g_autoptr(GFile) module_file =
g_file_resolve_relative_path (builder_context_get_base_dir (demarshal_build_context), module_relpath);
g_file_resolve_relative_path (demarshal_base_dir, module_relpath);
const char *module_path = flatpak_file_get_path_cached (module_file);
g_autofree char *json = NULL;
g_autoptr(GError) error = NULL;
if (g_file_get_contents (module_path, &json, NULL, &error))
{
g_autoptr(GFile) module_file_dir = g_file_get_parent (module_file);
g_autoptr(GFile) saved_demarshal_base_dir = builder_manifest_get_demarshal_base_dir ();
builder_manifest_set_demarshal_base_dir (module_file_dir);
module = json_gobject_from_data (BUILDER_TYPE_MODULE,
json, -1, &error);
builder_manifest_set_demarshal_base_dir (saved_demarshal_base_dir);
if (module)
builder_module_set_json_path (BUILDER_MODULE (module), module_path);
}

View File

@@ -44,7 +44,8 @@ typedef struct BuilderManifest BuilderManifest;
GType builder_manifest_get_type (void);
void builder_manifest_set_demarshal_buid_context (BuilderContext *build_context);
void builder_manifest_set_demarshal_base_dir (GFile *dir);
GFile *builder_manifest_get_demarshal_base_dir (void);
const char * builder_manifest_get_id (BuilderManifest *self);
char * builder_manifest_get_locale_id (BuilderManifest *self);

View File

@@ -34,6 +34,7 @@
#include "builder-utils.h"
#include "builder-module.h"
#include "builder-post-process.h"
#include "builder-manifest.h"
struct BuilderModule
{
@@ -679,12 +680,23 @@ builder_module_deserialize_property (JsonSerializable *serializable,
if (JSON_NODE_HOLDS_VALUE (element_node) &&
json_node_get_value_type (element_node) == G_TYPE_STRING)
{
const char *module_path = json_node_get_string (element_node);
g_autoptr(GFile) saved_demarshal_base_dir = builder_manifest_get_demarshal_base_dir ();
const char *module_relpath = json_node_get_string (element_node);
g_autoptr(GFile) module_file =
g_file_resolve_relative_path (saved_demarshal_base_dir, module_relpath);
const char *module_path = flatpak_file_get_path_cached (module_file);
g_autofree char *json = NULL;
if (g_file_get_contents (module_path, &json, NULL, NULL))
module = json_gobject_from_data (BUILDER_TYPE_MODULE,
json, -1, NULL);
{
g_autoptr(GFile) module_file_dir = g_file_get_parent (module_file);
builder_manifest_set_demarshal_base_dir (module_file_dir);
module = json_gobject_from_data (BUILDER_TYPE_MODULE,
json, -1, NULL);
builder_manifest_set_demarshal_base_dir (saved_demarshal_base_dir);
if (module)
builder_module_set_json_path (BUILDER_MODULE (module), module_path);
}
}
else if (JSON_NODE_HOLDS_OBJECT (element_node))
module = json_gobject_deserialize (BUILDER_TYPE_MODULE, element_node);