builder: Add collection ID support to the flatpak builder

Pass a --collection-id argument through to `flatpak build-export`.

Also add a ‘collection-id’ property to manifest files, which can be used
to set the collection ID on an exported repo (when using --repo) without
having to provide a command line option.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
tingping/wmclass
Philip Withnall 2017-06-27 13:09:57 +01:00 committed by Alexander Larsson
parent f3c898da05
commit 5b002edf06
5 changed files with 100 additions and 1 deletions

View File

@ -62,6 +62,7 @@ static char *opt_default_branch;
static char *opt_repo;
static char *opt_subject;
static char *opt_body;
static char *opt_collection_id = NULL;
static char *opt_gpg_homedir;
static char **opt_key_ids;
static char **opt_sources_dirs;
@ -98,6 +99,9 @@ static GOptionEntry entries[] = {
{ "repo", 0, 0, G_OPTION_ARG_STRING, &opt_repo, "Repo to export into", "DIR"},
{ "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject (passed to build-export)", "SUBJECT" },
{ "body", 'b', 0, G_OPTION_ARG_STRING, &opt_body, "Full description (passed to build-export)", "BODY" },
#ifdef FLATPAK_ENABLE_P2P
{ "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, "Collection ID (passed to build-export)", "COLLECTION-ID" },
#endif /* FLATPAK_ENABLE_P2P */
{ "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"},
{ "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"},
{ "force-clean", 0, 0, G_OPTION_ARG_NONE, &opt_force_clean, "Erase previous contents of DIRECTORY", NULL },
@ -165,6 +169,7 @@ do_export (BuilderContext *build_context,
const gchar *location,
const gchar *directory,
const gchar *branch,
const gchar *collection_id,
...)
{
va_list ap;
@ -195,8 +200,11 @@ do_export (BuilderContext *build_context,
for (i = 0; opt_key_ids != NULL && opt_key_ids[i] != NULL; i++)
g_ptr_array_add (args, g_strdup_printf ("--gpg-sign=%s", opt_key_ids[i]));
if (collection_id)
g_ptr_array_add (args, g_strdup_printf ("--collection-id=%s", collection_id));
/* Additional flags. */
va_start (ap, branch);
va_start (ap, collection_id);
while ((arg = va_arg (ap, const gchar *)))
if (arg != skip_arg)
g_ptr_array_add (args, g_strdup ((gchar *) arg));
@ -337,6 +345,15 @@ main (int argc,
manifest_rel_path = argv[argnr++];
manifest_basename = g_path_get_basename (manifest_rel_path);
#ifdef FLATPAK_ENABLE_P2P
if (opt_collection_id != NULL &&
!ostree_validate_collection_id (opt_collection_id, &error))
{
g_printerr ("%s is not a valid collection ID: %s", opt_collection_id, error->message);
return 1;
}
#endif /* FLATPAK_ENABLE_P2P */
if (app_dir_path)
app_dir = g_file_new_for_path (app_dir_path);
cwd = g_get_current_dir ();
@ -478,6 +495,9 @@ main (int argc,
if (opt_default_branch)
builder_manifest_set_default_branch (manifest, opt_default_branch);
if (opt_collection_id)
builder_manifest_set_default_collection_id (manifest, opt_collection_id);
if (is_run && argc == 3)
return usage (context, "Program to run must be specified");
@ -723,6 +743,7 @@ main (int argc,
if (!do_export (build_context, &error,
FALSE,
opt_repo, app_dir_path, builder_manifest_get_branch (manifest),
builder_manifest_get_collection_id (manifest),
"--exclude=/lib/debug/*",
"--include=/lib/debug/app",
builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg,
@ -755,6 +776,7 @@ main (int argc,
"/share/runtime/locale/", NULL);
if (!do_export (build_context, &error, TRUE,
opt_repo, app_dir_path, builder_manifest_get_branch (manifest),
builder_manifest_get_collection_id (manifest),
metadata_arg,
files_arg,
NULL))
@ -773,6 +795,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE,
opt_repo, app_dir_path, builder_manifest_get_branch (manifest),
builder_manifest_get_collection_id (manifest),
"--metadata=metadata.debuginfo",
builder_context_get_build_runtime (build_context) ? "--files=usr/lib/debug" : "--files=files/lib/debug",
NULL))
@ -791,6 +814,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE,
opt_repo, app_dir_path, builder_manifest_get_branch (manifest),
builder_manifest_get_collection_id (manifest),
"--metadata=metadata.sources",
"--files=sources",
NULL))
@ -809,6 +833,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE,
opt_repo, app_dir_path, builder_manifest_get_branch (manifest),
builder_manifest_get_collection_id (manifest),
"--metadata=metadata.platform",
"--files=platform",
builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg,
@ -841,6 +866,7 @@ main (int argc,
files_arg = g_strconcat ("--files=platform/share/runtime/locale/", NULL);
if (!do_export (build_context, &error, TRUE,
opt_repo, app_dir_path, builder_manifest_get_branch (manifest),
builder_manifest_get_collection_id (manifest),
metadata_arg,
files_arg,
NULL))

View File

@ -57,6 +57,7 @@ struct BuilderManifest
char *id;
char *id_platform;
char *branch;
char *collection_id;
char *type;
char *runtime;
char *runtime_commit;
@ -147,6 +148,7 @@ enum {
PROP_COPY_ICON,
PROP_DESKTOP_FILE_NAME_PREFIX,
PROP_DESKTOP_FILE_NAME_SUFFIX,
PROP_COLLECTION_ID,
LAST_PROP
};
@ -157,6 +159,7 @@ builder_manifest_finalize (GObject *object)
g_free (self->id);
g_free (self->branch);
g_free (self->collection_id);
g_free (self->runtime);
g_free (self->runtime_commit);
g_free (self->runtime_version);
@ -399,6 +402,10 @@ builder_manifest_get_property (GObject *object,
g_value_set_string (value, self->desktop_file_name_suffix);
break;
case PROP_COLLECTION_ID:
g_value_set_string (value, self->collection_id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -614,6 +621,11 @@ builder_manifest_set_property (GObject *object,
self->desktop_file_name_suffix = g_value_dup_string (value);
break;
case PROP_COLLECTION_ID:
g_free (self->collection_id);
self->collection_id = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -900,6 +912,13 @@ builder_manifest_class_init (BuilderManifestClass *klass)
"",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_COLLECTION_ID,
g_param_spec_string ("collection-id",
"",
"",
NULL,
G_PARAM_READWRITE));
}
static void
@ -1126,6 +1145,20 @@ builder_manifest_set_default_branch (BuilderManifest *self,
self->branch = g_strdup (default_branch);
}
const char *
builder_manifest_get_collection_id (BuilderManifest *self)
{
return self->collection_id;
}
void
builder_manifest_set_default_collection_id (BuilderManifest *self,
const char *default_collection_id)
{
if (self->collection_id == NULL)
self->collection_id = g_strdup (default_collection_id);
}
static const char *
builder_manifest_get_base_version (BuilderManifest *self)
{

View File

@ -59,6 +59,9 @@ GList * builder_manifest_get_modules (BuilderManifest *self);
const char * builder_manifest_get_branch (BuilderManifest *self);
void builder_manifest_set_default_branch (BuilderManifest *self,
const char *default_branch);
const char * builder_manifest_get_collection_id (BuilderManifest *self);
void builder_manifest_set_default_collection_id (BuilderManifest *self,
const char *default_collection_id);
gboolean builder_manifest_start (BuilderManifest *self,
gboolean allow_missing_runtimes,

View File

@ -99,6 +99,16 @@
new commits added, or the first module where some changes to the <arg choice="plain">MANIFEST</arg> file caused
the build environment to change. This makes flatpak-builder very efficient for incremental builds.
</para>
<!-- FIXME: Uncomment this when enable-p2p is enabled unconditionally.
<para>
When building a flatpak to be published to the internet,
<option>-FIXME-collection-id=COLLECTION-ID</option> should be specified
as a globally unique reverse DNS value to identify the collection of
flatpaks this will be added to. Setting a globally unique collection
ID allows the apps in the repository to be shared over peer to peer
systems without needing further configuration.
</para>
-->
</refsect1>
<refsect1>
@ -314,6 +324,21 @@
</para></listitem>
</varlistentry>
<!-- FIXME: Uncomment this when enable-p2p is enabled unconditionally.
<varlistentry>
<term><option>-FIXME-collection-id=COLLECTION-ID</option></term>
<listitem><para>
Set as the collection ID of the repository. Setting a globally
unique collection ID allows the apps in the repository to be shared over
peer to peer systems without needing further configuration.
If building in an existing repository, the collection ID
must match the existing configured collection ID for that
repository.
</para></listitem>
</varlistentry>
-->
<varlistentry>
<term><option>--gpg-sign=KEYID</option></term>

View File

@ -60,6 +60,18 @@
<term><option>branch</option> (string)</term>
<listitem><para>The branch of the application, defaults to master.</para></listitem>
</varlistentry>
<!-- FIXME: Uncomment this when enable-p2p is enabled unconditionally.
<varlistentry>
<term><option>collection-id</option> (string)</term>
<listitem><para>The collection ID of the repository,
defaults to being unset. Setting a globally
unique collection ID allows the apps in the repository to be shared over
peer to peer systems without needing further configuration.
If building in an existing repository, the collection ID
must match the existing configured collection ID for that
repository.</para></listitem>
</varlistentry>
-->
<varlistentry>
<term><option>runtime</option> (string)</term>
<listitem><para>The name of the runtime that the application uses.</para></listitem>