forked from Mirrors/flatpak-builder
Merge pull request #101 from matthiasclasen/recursive-modules
Support recursive modulestingping/wmclass
commit
375565e567
|
@ -70,6 +70,7 @@ struct BuilderManifest
|
|||
char *command;
|
||||
BuilderOptions *build_options;
|
||||
GList *modules;
|
||||
GList *expanded_modules;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
|
@ -134,6 +135,7 @@ builder_manifest_finalize (GObject *object)
|
|||
g_free (self->command);
|
||||
g_clear_object (&self->build_options);
|
||||
g_list_free_full (self->modules, g_object_unref);
|
||||
g_list_free (self->expanded_modules);
|
||||
g_strfreev (self->cleanup);
|
||||
g_strfreev (self->cleanup_commands);
|
||||
g_strfreev (self->cleanup_platform);
|
||||
|
@ -148,6 +150,29 @@ builder_manifest_finalize (GObject *object)
|
|||
G_OBJECT_CLASS (builder_manifest_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
expand_modules (GList *modules, GList **expanded, GError **error)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = modules; l; l = l->next)
|
||||
{
|
||||
BuilderModule *m = l->data;
|
||||
GList *submodules = NULL;
|
||||
|
||||
if (builder_module_get_disabled (m))
|
||||
continue;
|
||||
|
||||
if (!expand_modules (builder_module_get_modules (m), &submodules, error))
|
||||
return FALSE;
|
||||
|
||||
*expanded = g_list_concat (*expanded, submodules);
|
||||
*expanded = g_list_append (*expanded, m);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
builder_manifest_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
|
@ -742,13 +767,21 @@ builder_manifest_deserialize_property (JsonSerializable *serializable,
|
|||
{
|
||||
JsonNode *element_node = json_array_get_element (array, i);
|
||||
|
||||
if (JSON_NODE_TYPE (element_node) != JSON_NODE_OBJECT)
|
||||
{
|
||||
g_list_free_full (modules, g_object_unref);
|
||||
return FALSE;
|
||||
}
|
||||
module = NULL;
|
||||
|
||||
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_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);
|
||||
}
|
||||
else if (JSON_NODE_HOLDS_OBJECT (element_node))
|
||||
module = json_gobject_deserialize (BUILDER_TYPE_MODULE, element_node);
|
||||
|
||||
module = json_gobject_deserialize (BUILDER_TYPE_MODULE, element_node);
|
||||
if (module == NULL)
|
||||
{
|
||||
g_list_free_full (modules, g_object_unref);
|
||||
|
@ -867,6 +900,9 @@ builder_manifest_start (BuilderManifest *self,
|
|||
self->runtime,
|
||||
builder_manifest_get_runtime_version (self));
|
||||
|
||||
if (!expand_modules (self->modules, &self->expanded_modules, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -995,7 +1031,7 @@ builder_manifest_checksum_for_cleanup (BuilderManifest *self,
|
|||
builder_cache_checksum_str (cache, self->desktop_file_name_suffix);
|
||||
builder_cache_checksum_boolean (cache, self->appstream_compose);
|
||||
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
for (l = self->expanded_modules; l != NULL; l = l->next)
|
||||
{
|
||||
BuilderModule *m = l->data;
|
||||
builder_module_checksum_for_cleanup (m, cache, context);
|
||||
|
@ -1063,13 +1099,10 @@ builder_manifest_download (BuilderManifest *self,
|
|||
GList *l;
|
||||
|
||||
g_print ("Downloading sources\n");
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
for (l = self->expanded_modules; l != NULL; l = l->next)
|
||||
{
|
||||
BuilderModule *m = l->data;
|
||||
|
||||
if (builder_module_get_disabled (m))
|
||||
continue;
|
||||
|
||||
if (!builder_module_download_sources (m, update_vcs, context, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -1092,19 +1125,19 @@ builder_manifest_build (BuilderManifest *self,
|
|||
builder_context_set_separate_locales (context, self->separate_locales);
|
||||
|
||||
g_print ("Starting build of %s\n", self->id ? self->id : "app");
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
for (l = self->expanded_modules; l != NULL; l = l->next)
|
||||
{
|
||||
BuilderModule *m = l->data;
|
||||
g_autoptr(GPtrArray) changes = NULL;
|
||||
|
||||
if (builder_module_get_disabled (m))
|
||||
g_autofree char *stage = g_strdup_printf ("build-%s", builder_module_get_name (m));
|
||||
|
||||
if (!builder_module_get_sources (m))
|
||||
{
|
||||
g_print ("Skipping disabled module %s\n", builder_module_get_name (m));
|
||||
g_print ("Skipping module %s (no sources)\n", builder_module_get_name (m));
|
||||
continue;
|
||||
}
|
||||
|
||||
g_autofree char *stage = g_strdup_printf ("build-%s", builder_module_get_name (m));
|
||||
|
||||
builder_module_checksum (m, cache, context);
|
||||
|
||||
if (!builder_cache_lookup (cache, stage))
|
||||
|
@ -1386,13 +1419,10 @@ builder_manifest_cleanup (BuilderManifest *self,
|
|||
}
|
||||
}
|
||||
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
for (l = self->expanded_modules; l != NULL; l = l->next)
|
||||
{
|
||||
BuilderModule *m = l->data;
|
||||
|
||||
if (builder_module_get_disabled (m))
|
||||
continue;
|
||||
|
||||
builder_module_cleanup_collect (m, FALSE, context, to_remove_ht);
|
||||
}
|
||||
|
||||
|
@ -1864,13 +1894,10 @@ builder_manifest_create_platform (BuilderManifest *self,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
for (l = self->expanded_modules; l != NULL; l = l->next)
|
||||
{
|
||||
BuilderModule *m = l->data;
|
||||
|
||||
if (builder_module_get_disabled (m))
|
||||
continue;
|
||||
|
||||
builder_module_cleanup_collect (m, TRUE, context, to_remove_ht);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ struct BuilderModule
|
|||
char **cleanup;
|
||||
char **cleanup_platform;
|
||||
GList *sources;
|
||||
GList *modules;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
|
@ -88,6 +89,7 @@ enum {
|
|||
PROP_CLEANUP,
|
||||
PROP_CLEANUP_PLATFORM,
|
||||
PROP_POST_INSTALL,
|
||||
PROP_MODULES,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
|
@ -107,6 +109,7 @@ builder_module_finalize (GObject *object)
|
|||
g_list_free_full (self->sources, g_object_unref);
|
||||
g_strfreev (self->cleanup);
|
||||
g_strfreev (self->cleanup_platform);
|
||||
g_list_free_full (self->modules, g_object_unref);
|
||||
|
||||
if (self->changes)
|
||||
g_ptr_array_unref (self->changes);
|
||||
|
@ -192,6 +195,10 @@ builder_module_get_property (GObject *object,
|
|||
g_value_set_boxed (value, self->cleanup_platform);
|
||||
break;
|
||||
|
||||
case PROP_MODULES:
|
||||
g_value_set_pointer (value, self->modules);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -296,6 +303,12 @@ builder_module_set_property (GObject *object,
|
|||
g_strfreev (tmp);
|
||||
break;
|
||||
|
||||
case PROP_MODULES:
|
||||
g_list_free_full (self->modules, g_object_unref);
|
||||
/* NOTE: This takes ownership of the list! */
|
||||
self->modules = g_value_get_pointer (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -428,6 +441,12 @@ builder_module_class_init (BuilderModuleClass *klass)
|
|||
"",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_MODULES,
|
||||
g_param_spec_pointer ("modules",
|
||||
"",
|
||||
"",
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -441,7 +460,31 @@ builder_module_serialize_property (JsonSerializable *serializable,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
if (strcmp (property_name, "sources") == 0)
|
||||
if (strcmp (property_name, "modules") == 0)
|
||||
{
|
||||
BuilderModule *self = BUILDER_MODULE (serializable);
|
||||
JsonNode *retval = NULL;
|
||||
GList *l;
|
||||
|
||||
if (self->modules)
|
||||
{
|
||||
JsonArray *array;
|
||||
|
||||
array = json_array_sized_new (g_list_length (self->modules));
|
||||
|
||||
for (l = self->modules; l != NULL; l = l->next)
|
||||
{
|
||||
JsonNode *child = json_gobject_serialize (l->data);
|
||||
json_array_add_element (array, child);
|
||||
}
|
||||
|
||||
retval = json_node_init_array (json_node_alloc (), array);
|
||||
json_array_unref (array);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
else if (strcmp (property_name, "sources") == 0)
|
||||
{
|
||||
BuilderModule *self = BUILDER_MODULE (serializable);
|
||||
JsonNode *retval = NULL;
|
||||
|
@ -481,7 +524,56 @@ builder_module_deserialize_property (JsonSerializable *serializable,
|
|||
GParamSpec *pspec,
|
||||
JsonNode *property_node)
|
||||
{
|
||||
if (strcmp (property_name, "sources") == 0)
|
||||
if (strcmp (property_name, "modules") == 0)
|
||||
{
|
||||
if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL)
|
||||
{
|
||||
g_value_set_pointer (value, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
else if (JSON_NODE_TYPE (property_node) == JSON_NODE_ARRAY)
|
||||
{
|
||||
JsonArray *array = json_node_get_array (property_node);
|
||||
guint i, array_len = json_array_get_length (array);
|
||||
GList *modules = NULL;
|
||||
GObject *module;
|
||||
|
||||
for (i = 0; i < array_len; i++)
|
||||
{
|
||||
JsonNode *element_node = json_array_get_element (array, i);
|
||||
|
||||
module = NULL;
|
||||
|
||||
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_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);
|
||||
}
|
||||
else if (JSON_NODE_HOLDS_OBJECT (element_node))
|
||||
module = json_gobject_deserialize (BUILDER_TYPE_MODULE, element_node);
|
||||
|
||||
if (module == NULL)
|
||||
{
|
||||
g_list_free_full (modules, g_object_unref);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
modules = g_list_prepend (modules, module);
|
||||
}
|
||||
|
||||
g_value_set_pointer (value, g_list_reverse (modules));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
else if (strcmp (property_name, "sources") == 0)
|
||||
{
|
||||
if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL)
|
||||
{
|
||||
|
@ -556,6 +648,12 @@ builder_module_get_sources (BuilderModule *self)
|
|||
return self->sources;
|
||||
}
|
||||
|
||||
GList *
|
||||
builder_module_get_modules (BuilderModule *self)
|
||||
{
|
||||
return self->modules;
|
||||
}
|
||||
|
||||
gboolean
|
||||
builder_module_download_sources (BuilderModule *self,
|
||||
gboolean update_vcs,
|
||||
|
@ -1464,6 +1562,9 @@ builder_module_cleanup_collect (BuilderModule *self,
|
|||
const char **global_patterns;
|
||||
const char **local_patterns;
|
||||
|
||||
if (!self->changes)
|
||||
return;
|
||||
|
||||
if (platform)
|
||||
{
|
||||
global_patterns = builder_context_get_global_cleanup_platform (context);
|
||||
|
|
|
@ -42,6 +42,7 @@ GType builder_module_get_type (void);
|
|||
const char * builder_module_get_name (BuilderModule *self);
|
||||
gboolean builder_module_get_disabled (BuilderModule *self);
|
||||
GList * builder_module_get_sources (BuilderModule *self);
|
||||
GList * builder_module_get_modules (BuilderModule *self);
|
||||
GPtrArray * builder_module_get_changes (BuilderModule *self);
|
||||
void builder_module_set_changes (BuilderModule *self,
|
||||
GPtrArray *changes);
|
||||
|
|
Loading…
Reference in New Issue