Record the built extensions in the metadata

This adds a section to the main metadata like:
```
[Build]
built-extension=org.the.App.Locale;
```

This can be used to figure out what refs where built that are
related to the app, for example if you want to bundle them all.

Closes: #128
Approved by: alexlarsson
auto
Alexander Larsson 2018-04-19 13:22:18 +02:00 committed by Atomic Bot
parent 28984bcd81
commit 3d62f01610
3 changed files with 97 additions and 3 deletions

View File

@ -61,6 +61,9 @@ typedef void (*FlatpakLoadUriProgress) (guint64 downloaded_bytes,
#define FLATPAK_METADATA_KEY_SDK "sdk"
#define FLATPAK_METADATA_KEY_TAGS "tags"
#define FLATPAK_METADATA_GROUP_BUILD "Build"
#define FLATPAK_METADATA_KEY_BUILD_EXTENSIONS "built-extensions"
/* https://github.com/GNOME/libglnx/pull/38
* Note by using #define rather than wrapping via a static inline, we
* don't have to re-define attributes like G_GNUC_PRINTF.

View File

@ -2553,6 +2553,7 @@ builder_manifest_finish (BuilderManifest *self,
if (!builder_cache_lookup (cache, "finish"))
{
GFile *app_dir = NULL;
g_autoptr(GPtrArray) sub_ids = g_ptr_array_new_with_free_func (g_free);
g_autofree char *ref = NULL;
g_print ("Finishing app\n");
@ -2835,8 +2836,9 @@ builder_manifest_finish (BuilderManifest *self,
metadata_contents, strlen (metadata_contents),
error))
return FALSE;
}
g_ptr_array_add (sub_ids, g_strdup (locale_id));
}
if (g_file_query_exists (debuginfo_dir, NULL))
{
@ -2874,8 +2876,9 @@ builder_manifest_finish (BuilderManifest *self,
if (!g_file_set_contents (flatpak_file_get_path_cached (metadata_debuginfo_file),
metadata_contents, strlen (metadata_contents), error))
return FALSE;
}
g_ptr_array_add (sub_ids, g_strdup (debug_id));
}
for (l = self->add_extensions; l != NULL; l = l->next)
{
@ -2903,6 +2906,33 @@ builder_manifest_finish (BuilderManifest *self,
if (!g_file_set_contents (flatpak_file_get_path_cached (metadata_extension_file),
metadata_contents, strlen (metadata_contents), error))
return FALSE;
g_ptr_array_add (sub_ids, g_strdup (builder_extension_get_name (e)));
}
if (sub_ids->len > 0)
{
g_autoptr(GFile) metadata_file = NULL;
g_autoptr(GFileOutputStream) output = NULL;
g_autoptr(GString) extension_contents = g_string_new ("\n"
"[Build]\n");
g_string_append (extension_contents, FLATPAK_METADATA_KEY_BUILD_EXTENSIONS"=");
for (i = 0; i < sub_ids->len; i++)
{
g_string_append (extension_contents, (const char *)sub_ids->pdata[i]);
g_string_append (extension_contents, ";");
}
metadata_file = g_file_get_child (app_dir, "metadata");
output = g_file_append_to (metadata_file, G_FILE_CREATE_NONE, NULL, error);
if (output == NULL)
return FALSE;
if (!g_output_stream_write_all (G_OUTPUT_STREAM (output),
extension_contents->str, extension_contents->len,
NULL, NULL, error))
return FALSE;
}
if (!builder_context_disable_rofiles (context, error))
@ -2945,6 +2975,7 @@ builder_manifest_create_platform (BuilderManifest *self,
g_autoptr(GPtrArray) args = NULL;
GFile *app_dir = NULL;
g_autofree char *ref = NULL;
g_autoptr(GPtrArray) sub_ids = g_ptr_array_new_with_free_func (g_free);
g_print ("Creating platform based on %s\n", self->runtime);
@ -3246,6 +3277,33 @@ builder_manifest_create_platform (BuilderManifest *self,
metadata_contents, strlen (metadata_contents),
error))
return FALSE;
g_ptr_array_add (sub_ids, g_strdup (locale_id));
}
if (sub_ids->len > 0)
{
g_autoptr(GFile) metadata_file = NULL;
g_autoptr(GFileOutputStream) output = NULL;
g_autoptr(GString) extension_contents = g_string_new ("\n"
"[Build]\n");
g_string_append (extension_contents, FLATPAK_METADATA_KEY_BUILD_EXTENSIONS"=");
for (i = 0; i < sub_ids->len; i++)
{
g_string_append (extension_contents, (const char *)sub_ids->pdata[i]);
g_string_append (extension_contents, ";");
}
metadata_file = g_file_get_child (app_dir, "metadata.platform");
output = g_file_append_to (metadata_file, G_FILE_CREATE_NONE, NULL, error);
if (output == NULL)
return FALSE;
if (!g_output_stream_write_all (G_OUTPUT_STREAM (output),
extension_contents->str, extension_contents->len,
NULL, NULL, error))
return FALSE;
}
if (!builder_context_disable_rofiles (context, error))
@ -3276,10 +3334,15 @@ builder_manifest_bundle_sources (BuilderManifest *self,
g_autofree char *sources_id = builder_manifest_get_sources_id (self);
GFile *app_dir;
g_autoptr(GFile) metadata_sources_file = NULL;
g_autoptr(GFile) metadata = NULL;
g_autoptr(GFile) json_dir = NULL;
g_autofree char *manifest_filename = NULL;
g_autoptr(GFile) manifest_file = NULL;
g_autofree char *metadata_contents = NULL;
g_autoptr(GKeyFile) metadata_keyfile = g_key_file_new ();
g_autoptr(GPtrArray) subs = g_ptr_array_new ();
g_auto(GStrv) old_subs = NULL;
gsize i;
GList *l;
g_print ("Bundling sources\n");
@ -3316,6 +3379,34 @@ builder_manifest_bundle_sources (BuilderManifest *self,
return FALSE;
}
metadata = g_file_get_child (app_dir, "metadata");
if (!g_key_file_load_from_file (metadata_keyfile,
flatpak_file_get_path_cached (metadata),
G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
error))
{
g_prefix_error (error, "Can't load main metadata file: ");
return FALSE;
}
old_subs = g_key_file_get_string_list (metadata_keyfile, "Build", "built-extensions", NULL, NULL);
for (i = 0; old_subs != NULL && old_subs[i] != NULL; i++)
g_ptr_array_add (subs, old_subs[i]);
g_ptr_array_add (subs, sources_id);
g_key_file_set_string_list (metadata_keyfile, FLATPAK_METADATA_GROUP_BUILD,
FLATPAK_METADATA_KEY_BUILD_EXTENSIONS,
(const char * const *)subs->pdata, subs->len);
if (!g_key_file_save_to_file (metadata_keyfile,
flatpak_file_get_path_cached (metadata),
error))
{
g_prefix_error (error, "Can't save metadata.platform: ");
return FALSE;
}
if (!builder_context_disable_rofiles (context, error))
return FALSE;

View File

@ -40,7 +40,7 @@ typedef struct BuilderManifest BuilderManifest;
/* Bump this if format changes in incompatible ways to force rebuild */
#define BUILDER_MANIFEST_CHECKSUM_VERSION "5"
#define BUILDER_MANIFEST_CHECKSUM_CLEANUP_VERSION "1"
#define BUILDER_MANIFEST_CHECKSUM_FINISH_VERSION "2"
#define BUILDER_MANIFEST_CHECKSUM_FINISH_VERSION "3"
#define BUILDER_MANIFEST_CHECKSUM_BUNDLE_SOURCES_VERSION "1"
#define BUILDER_MANIFEST_CHECKSUM_PLATFORM_VERSION "1"