manifest: Add default-branch key

This is similar to branch and used if branch is not set. However, this
key (as opposed to branch) is overridden by the --default-branch option.

The idea is that most apps in flathub would use default-branch=stable, so
that a standart flatpak-builder command will build a "stable" release.
However, when building a test build we can use --default-branch=test to
override that. Then special cases like theme extensions and other things
that require a specific branch value to work at all can use branch="1.0".

Closes: #264
Approved by: alexlarsson
auto
Alexander Larsson 2019-01-25 17:20:08 +01:00 committed by Atomic Bot
parent 09b2736693
commit 00f63cfe7e
6 changed files with 80 additions and 26 deletions

View File

@ -58,7 +58,24 @@
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><option>branch</option> (string)</term> <term><option>branch</option> (string)</term>
<listitem><para>The branch of the application, defaults to master.</para></listitem> <listitem><para>The branch to use when exporting
the application. If this is unset the defaults
come from the default-branch option.</para>
<para>This key overrides both the default-branch
key, and the --default-branch commandline
option. Unless you need a very specific branchname
(like for a runtime or an extension) it is
recommended to use the default-branch key instead, because
you can then override the default using --default-branch when
building for instance a test build.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>default-branch</option> (string)</term>
<listitem><para>The default branch to use when
exporting the application. Defaults to master. </para>
<para>This key can be overriden by the
--default-branch commandline
option.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><option>collection-id</option> (string)</term> <term><option>collection-id</option> (string)</term>

View File

@ -48,6 +48,7 @@ struct BuilderContext
SoupSession *soup_session; SoupSession *soup_session;
CURL *curl_session; CURL *curl_session;
char *arch; char *arch;
char *default_branch;
char *stop_at; char *stop_at;
gint64 source_date_epoch; gint64 source_date_epoch;
@ -119,6 +120,7 @@ builder_context_finalize (GObject *object)
g_clear_object (&self->options); g_clear_object (&self->options);
g_clear_object (&self->sdk_config); g_clear_object (&self->sdk_config);
g_free (self->arch); g_free (self->arch);
g_free (self->default_branch);
g_free (self->state_subdir); g_free (self->state_subdir);
g_free (self->stop_at); g_free (self->stop_at);
g_strfreev (self->cleanup); g_strfreev (self->cleanup);
@ -566,6 +568,20 @@ builder_context_set_arch (BuilderContext *self,
self->arch = g_strdup (arch); self->arch = g_strdup (arch);
} }
const char *
builder_context_get_default_branch (BuilderContext *self)
{
return (const char *) self->default_branch;
}
void
builder_context_set_default_branch (BuilderContext *self,
const char *default_branch)
{
g_free (self->default_branch);
self->default_branch = g_strdup (default_branch);
}
void void
builder_context_set_source_date_epoch (BuilderContext *self, builder_context_set_source_date_epoch (BuilderContext *self,
gint64 source_date_epoch) gint64 source_date_epoch)

View File

@ -74,6 +74,9 @@ CURL * builder_context_get_curl_session (BuilderContext *self);
const char * builder_context_get_arch (BuilderContext *self); const char * builder_context_get_arch (BuilderContext *self);
void builder_context_set_arch (BuilderContext *self, void builder_context_set_arch (BuilderContext *self,
const char *arch); const char *arch);
const char * builder_context_get_default_branch (BuilderContext *self);
void builder_context_set_default_branch (BuilderContext *self,
const char *default_branch);
void builder_context_set_source_date_epoch (BuilderContext *self, void builder_context_set_source_date_epoch (BuilderContext *self,
gint64 source_date_epoch); gint64 source_date_epoch);
const char * builder_context_get_stop_at (BuilderContext *self); const char * builder_context_get_stop_at (BuilderContext *self);

View File

@ -690,7 +690,7 @@ main (int argc,
} }
if (opt_default_branch) if (opt_default_branch)
builder_manifest_set_default_branch (manifest, opt_default_branch); builder_context_set_default_branch (build_context, opt_default_branch);
if (opt_collection_id) if (opt_collection_id)
builder_manifest_set_default_collection_id (manifest, opt_collection_id); builder_manifest_set_default_collection_id (manifest, opt_collection_id);
@ -928,7 +928,7 @@ main (int argc,
if (opt_mirror_screenshots_url && !opt_export_only) if (opt_mirror_screenshots_url && !opt_export_only)
{ {
g_autofree char *screenshot_subdir = g_strdup_printf ("%s-%s", builder_manifest_get_id (manifest), g_autofree char *screenshot_subdir = g_strdup_printf ("%s-%s", builder_manifest_get_id (manifest),
builder_manifest_get_branch (manifest)); builder_manifest_get_branch (manifest, build_context));
g_autofree char *url = g_build_filename (opt_mirror_screenshots_url, screenshot_subdir, NULL); g_autofree char *url = g_build_filename (opt_mirror_screenshots_url, screenshot_subdir, NULL);
g_autofree char *xml_relpath = g_strdup_printf ("files/share/app-info/xmls/%s.xml.gz", builder_manifest_get_id (manifest)); g_autofree char *xml_relpath = g_strdup_printf ("files/share/app-info/xmls/%s.xml.gz", builder_manifest_get_id (manifest));
g_autoptr(GFile) xml = g_file_resolve_relative_path (app_dir, xml_relpath); g_autoptr(GFile) xml = g_file_resolve_relative_path (app_dir, xml_relpath);
@ -1010,7 +1010,7 @@ main (int argc,
if (!do_export (build_context, &error, if (!do_export (build_context, &error,
FALSE, FALSE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, exclude_dirs, builder_manifest_get_branch (manifest), app_dir_path, exclude_dirs, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
"--exclude=/lib/debug/*", "--exclude=/lib/debug/*",
"--include=/lib/debug/app", "--include=/lib/debug/app",
@ -1044,7 +1044,7 @@ main (int argc,
"/share/runtime/locale/", NULL); "/share/runtime/locale/", NULL);
if (!do_export (build_context, &error, TRUE, if (!do_export (build_context, &error, TRUE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, NULL, builder_manifest_get_branch (manifest), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
metadata_arg, metadata_arg,
files_arg, files_arg,
@ -1064,7 +1064,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE, if (!do_export (build_context, &error, TRUE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, NULL, builder_manifest_get_branch (manifest), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
"--metadata=metadata.debuginfo", "--metadata=metadata.debuginfo",
builder_context_get_build_runtime (build_context) ? "--files=usr/lib/debug" : "--files=files/lib/debug", builder_context_get_build_runtime (build_context) ? "--files=usr/lib/debug" : "--files=files/lib/debug",
@ -1095,7 +1095,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE, if (!do_export (build_context, &error, TRUE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, NULL, builder_manifest_get_branch (manifest), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
metadata_arg, files_arg, metadata_arg, files_arg,
NULL)) NULL))
@ -1114,7 +1114,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE, if (!do_export (build_context, &error, TRUE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, NULL, builder_manifest_get_branch (manifest), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
"--metadata=metadata.sources", "--metadata=metadata.sources",
"--files=sources", "--files=sources",
@ -1134,7 +1134,7 @@ main (int argc,
if (!do_export (build_context, &error, TRUE, if (!do_export (build_context, &error, TRUE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, NULL, builder_manifest_get_branch (manifest), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
"--metadata=metadata.platform", "--metadata=metadata.platform",
"--files=platform", "--files=platform",
@ -1168,7 +1168,7 @@ main (int argc,
files_arg = g_strconcat ("--files=platform/share/runtime/locale/", NULL); files_arg = g_strconcat ("--files=platform/share/runtime/locale/", NULL);
if (!do_export (build_context, &error, TRUE, if (!do_export (build_context, &error, TRUE,
flatpak_file_get_path_cached (export_repo), flatpak_file_get_path_cached (export_repo),
app_dir_path, NULL, builder_manifest_get_branch (manifest), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
builder_manifest_get_collection_id (manifest), builder_manifest_get_collection_id (manifest),
metadata_arg, metadata_arg,
files_arg, files_arg,
@ -1188,7 +1188,7 @@ main (int argc,
g_printerr ("NOTE: No export due to --require-changes, ignoring --install\n"); g_printerr ("NOTE: No export due to --require-changes, ignoring --install\n");
else if (!do_install (build_context, flatpak_file_get_path_cached (export_repo), else if (!do_install (build_context, flatpak_file_get_path_cached (export_repo),
builder_manifest_get_id (manifest), builder_manifest_get_id (manifest),
builder_manifest_get_branch (manifest), builder_manifest_get_branch (manifest, build_context),
&error)) &error))
{ {
g_printerr ("Install failed: %s\n", error->message); g_printerr ("Install failed: %s\n", error->message);

View File

@ -61,6 +61,7 @@ struct BuilderManifest
char *id; char *id;
char *id_platform; char *id_platform;
char *branch; char *branch;
char *default_branch;
char *collection_id; char *collection_id;
char *extension_tag; char *extension_tag;
char *type; char *type;
@ -123,6 +124,7 @@ enum {
PROP_ID, PROP_ID,
PROP_ID_PLATFORM, PROP_ID_PLATFORM,
PROP_BRANCH, PROP_BRANCH,
PROP_DEFAULT_BRANCH,
PROP_RUNTIME, PROP_RUNTIME,
PROP_RUNTIME_VERSION, PROP_RUNTIME_VERSION,
PROP_RUNTIME_COMMIT, PROP_RUNTIME_COMMIT,
@ -175,6 +177,7 @@ builder_manifest_finalize (GObject *object)
g_free (self->id); g_free (self->id);
g_free (self->branch); g_free (self->branch);
g_free (self->default_branch);
g_free (self->collection_id); g_free (self->collection_id);
g_free (self->extension_tag); g_free (self->extension_tag);
g_free (self->runtime); g_free (self->runtime);
@ -284,6 +287,10 @@ builder_manifest_get_property (GObject *object,
g_value_set_string (value, self->branch); g_value_set_string (value, self->branch);
break; break;
case PROP_DEFAULT_BRANCH:
g_value_set_string (value, self->default_branch);
break;
case PROP_RUNTIME: case PROP_RUNTIME:
g_value_set_string (value, self->runtime); g_value_set_string (value, self->runtime);
break; break;
@ -488,6 +495,11 @@ builder_manifest_set_property (GObject *object,
self->branch = g_value_dup_string (value); self->branch = g_value_dup_string (value);
break; break;
case PROP_DEFAULT_BRANCH:
g_free (self->default_branch);
self->default_branch = g_value_dup_string (value);
break;
case PROP_RUNTIME: case PROP_RUNTIME:
g_free (self->runtime); g_free (self->runtime);
self->runtime = g_value_dup_string (value); self->runtime = g_value_dup_string (value);
@ -748,6 +760,13 @@ builder_manifest_class_init (BuilderManifestClass *klass)
"", "",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_DEFAULT_BRANCH,
g_param_spec_string ("default-branch",
"",
"",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_RUNTIME, PROP_RUNTIME,
g_param_spec_string ("runtime", g_param_spec_string ("runtime",
@ -1366,20 +1385,20 @@ builder_manifest_get_runtime_version (BuilderManifest *self)
} }
const char * const char *
builder_manifest_get_branch (BuilderManifest *self) builder_manifest_get_branch (BuilderManifest *self,
BuilderContext *context)
{ {
if (self->branch) if (self->branch)
return self->branch; return self->branch;
return "master"; if (context &&
} builder_context_get_default_branch (context))
return builder_context_get_default_branch (context);
void if (self->default_branch)
builder_manifest_set_default_branch (BuilderManifest *self, return self->default_branch;
const char *default_branch)
{ return "master";
if (self->branch == NULL)
self->branch = g_strdup (default_branch);
} }
const char * const char *
@ -1405,7 +1424,7 @@ builder_manifest_get_extension_tag (BuilderManifest *self)
static const char * static const char *
builder_manifest_get_base_version (BuilderManifest *self) builder_manifest_get_base_version (BuilderManifest *self)
{ {
return self->base_version ? self->base_version : builder_manifest_get_branch (self); return self->base_version ? self->base_version : builder_manifest_get_branch (self, NULL);
} }
G_GNUC_NULL_TERMINATED G_GNUC_NULL_TERMINATED
@ -2713,7 +2732,7 @@ builder_manifest_finish (BuilderManifest *self,
ref = flatpak_compose_ref (!self->build_runtime && !self->build_extension, ref = flatpak_compose_ref (!self->build_runtime && !self->build_extension,
builder_manifest_get_id (self), builder_manifest_get_id (self),
builder_manifest_get_branch (self), builder_manifest_get_branch (self, context),
builder_context_get_arch (context)); builder_context_get_arch (context));
if (self->metadata) if (self->metadata)
@ -3132,7 +3151,7 @@ builder_manifest_create_platform (BuilderManifest *self,
ref = flatpak_compose_ref (!self->build_runtime && !self->build_extension, ref = flatpak_compose_ref (!self->build_runtime && !self->build_extension,
builder_manifest_get_id_platform (self), builder_manifest_get_id_platform (self),
builder_manifest_get_branch (self), builder_manifest_get_branch (self, context),
builder_context_get_arch (context)); builder_context_get_arch (context));
platform_dir = g_file_get_child (app_dir, "platform"); platform_dir = g_file_get_child (app_dir, "platform");

View File

@ -59,9 +59,8 @@ BuilderOptions *builder_manifest_get_build_options (BuilderManifest *self);
GList * builder_manifest_get_modules (BuilderManifest *self); GList * builder_manifest_get_modules (BuilderManifest *self);
GList * builder_manifest_get_add_extensions (BuilderManifest *self); GList * builder_manifest_get_add_extensions (BuilderManifest *self);
GList * builder_manifest_get_add_build_extensions (BuilderManifest *self); GList * builder_manifest_get_add_build_extensions (BuilderManifest *self);
const char * builder_manifest_get_branch (BuilderManifest *self); const char * builder_manifest_get_branch (BuilderManifest *self,
void builder_manifest_set_default_branch (BuilderManifest *self, BuilderContext *context);
const char *default_branch);
const char * builder_manifest_get_collection_id (BuilderManifest *self); const char * builder_manifest_get_collection_id (BuilderManifest *self);
const char * builder_manifest_get_extension_tag (BuilderManifest *self); const char * builder_manifest_get_extension_tag (BuilderManifest *self);
void builder_manifest_set_default_collection_id (BuilderManifest *self, void builder_manifest_set_default_collection_id (BuilderManifest *self,