Skip to content

Commit 280e988

Browse files
committed
builder-manifest: Add argument to run compose with selected url policy
appstream-glib always composed with full urls. The URL policy got unintentionallly switched to partial urls during libappstream port in 1.3.x. Such a break in behaviour makes sense for unstable releases but we cannot revert back to full urls in a stable release. Using full URLs is desired for Flathub. So add a cli arg to control the behaviour and default to partial url. This may be flipped later in the next unstable release to default to full urls again. This is an alternative to #576
1 parent 05c79a6 commit 280e988

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

doc/flatpak-builder.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,21 @@
589589
</para></listitem>
590590
</varlistentry>
591591

592+
<varlistentry>
593+
<term><option>--compose-url-policy=POLICY</option></term>
594+
595+
<listitem><para>
596+
Set the AppStream compose URL policy. Accepted values
597+
are <literal>partial</literal> and <literal>full</literal>.
598+
<literal>full</literal> requires AppStream version >= 0.16.3.
599+
Defaults to <literal>partial</literal> if unspecified.
600+
This policy only takes effect when used in conjunction
601+
with <option>--mirror-screenshots-url=URL</option>;
602+
otherwise the Appstream catalogue will preserve
603+
the source media URLs.
604+
</para></listitem>
605+
</varlistentry>
606+
592607
<varlistentry>
593608
<term><option>--add-tag=TAG</option></term>
594609

src/builder-context.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct BuilderContext
8888
char *opt_mirror_screenshots_url;
8989

9090
BuilderSdkConfig *sdk_config;
91+
92+
BuilderAsUrlPolicy as_url_policy;
9193
};
9294

9395
typedef struct
@@ -1241,6 +1243,19 @@ builder_context_create_state_dir (BuilderContext *self,
12411243
return TRUE;
12421244
}
12431245

1246+
void
1247+
builder_context_set_as_url_policy (BuilderContext *self,
1248+
BuilderAsUrlPolicy policy)
1249+
{
1250+
self->as_url_policy = policy;
1251+
}
1252+
1253+
BuilderAsUrlPolicy
1254+
builder_context_get_as_url_policy (BuilderContext *self)
1255+
{
1256+
return self->as_url_policy;
1257+
}
1258+
12441259
BuilderContext *
12451260
builder_context_new (GFile *run_dir,
12461261
GFile *app_dir,

src/builder-context.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
G_BEGIN_DECLS
3131

32+
typedef enum {
33+
BUILDER_AS_URL_POLICY_PARTIAL = 0,
34+
BUILDER_AS_URL_POLICY_FULL,
35+
} BuilderAsUrlPolicy;
36+
3237
/* Same as SOUP_HTTP_URI_FLAGS, means all possible flags for http uris */
3338

3439
#if GLIB_CHECK_VERSION (2, 68, 0)
@@ -185,6 +190,10 @@ BuilderSdkConfig * builder_context_get_sdk_config (BuilderContext *self);
185190
gboolean builder_context_create_state_dir (BuilderContext *self,
186191
GError **error);
187192

193+
void builder_context_set_as_url_policy (BuilderContext *self,
194+
BuilderAsUrlPolicy policy);
195+
BuilderAsUrlPolicy builder_context_get_as_url_policy (BuilderContext *self);
196+
188197
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BuilderContext, g_object_unref)
189198

190199
G_END_DECLS

src/builder-main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static gboolean opt_log_session_bus;
8989
static gboolean opt_log_system_bus;
9090
static gboolean opt_yes;
9191
static gint64 opt_source_date_epoch = -1;
92+
static gchar *opt_as_url_policy = NULL;
9293

9394
static GOptionEntry entries[] = {
9495
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
@@ -144,6 +145,7 @@ static GOptionEntry entries[] = {
144145
{ "assumeyes", 'y', 0, G_OPTION_ARG_NONE, &opt_yes, N_("Automatically answer yes for all questions"), NULL },
145146
{ "no-shallow-clone", 0, 0, G_OPTION_ARG_NONE, &opt_no_shallow_clone, "Don't use shallow clones when mirroring git repos", NULL },
146147
{ "override-source-date-epoch", 0, 0, G_OPTION_ARG_INT64, &opt_source_date_epoch, "Use this timestamp to perform the build, instead of the last modification time of the manifest.", NULL },
148+
{ "compose-url-policy", 0, 0, G_OPTION_ARG_STRING, &opt_as_url_policy, "Set the AppStream compose URL policy to either 'partial' (default) or 'full'", "POLICY" },
147149
{ NULL }
148150
};
149151

@@ -608,6 +610,29 @@ main (int argc,
608610
builder_context_set_opt_export_only (build_context, opt_export_only);
609611
builder_context_set_opt_mirror_screenshots_url (build_context, opt_mirror_screenshots_url);
610612

613+
if (opt_mirror_screenshots_url)
614+
{
615+
BuilderAsUrlPolicy policy = BUILDER_AS_URL_POLICY_PARTIAL;
616+
617+
if (g_strcmp0 (opt_as_url_policy, "full") == 0)
618+
policy = BUILDER_AS_URL_POLICY_FULL;
619+
else if (g_strcmp0 (opt_as_url_policy, "partial") == 0)
620+
policy = BUILDER_AS_URL_POLICY_PARTIAL;
621+
else if (opt_as_url_policy != NULL)
622+
{
623+
g_printerr ("Invalid value for --compose-url-policy: %s\n", opt_as_url_policy);
624+
return 1;
625+
}
626+
627+
if (policy == BUILDER_AS_URL_POLICY_FULL && !appstream_has_version (0, 16, 3))
628+
{
629+
g_printerr ("AppStream version >= 0.16.3 required for 'full' compose URL policy\n");
630+
return 1;
631+
}
632+
633+
builder_context_set_as_url_policy (build_context, policy);
634+
}
635+
611636
git_init_email ();
612637

613638
if (!builder_context_create_state_dir (build_context, &error))

src/builder-manifest.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,8 @@ cmpstringp (const void *p1, const void *p2)
24222422
}
24232423

24242424
static gboolean
2425-
appstreamcli_compose (GError **error,
2425+
appstreamcli_compose (GError **error,
2426+
BuilderAsUrlPolicy as_url_policy,
24262427
...)
24272428
{
24282429
g_autoptr(GPtrArray) args = NULL;
@@ -2433,7 +2434,10 @@ appstreamcli_compose (GError **error,
24332434
g_ptr_array_add (args, g_strdup ("appstreamcli"));
24342435
g_ptr_array_add (args, g_strdup ("compose"));
24352436

2436-
va_start (ap, error);
2437+
if (as_url_policy == BUILDER_AS_URL_POLICY_FULL)
2438+
g_ptr_array_add (args, g_strdup ("--no-partial-urls"));
2439+
2440+
va_start (ap, as_url_policy);
24372441
while ((arg = va_arg (ap, const gchar *)))
24382442
g_ptr_array_add (args, g_strdup (arg));
24392443
g_ptr_array_add (args, NULL);
@@ -3066,6 +3070,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30663070
flatpak_file_get_path_cached (icon_out));
30673071
const char *opt_mirror_screenshots_url = builder_context_get_opt_mirror_screenshots_url (context);
30683072
gboolean opt_export_only = builder_context_get_opt_export_only (context);
3073+
BuilderAsUrlPolicy as_url_policy = builder_context_get_as_url_policy (context);
30693074

30703075
if (opt_mirror_screenshots_url && !opt_export_only)
30713076
{
@@ -3077,6 +3082,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30773082
g_print ("Running appstreamcli compose\n");
30783083
g_print ("Saving screenshots in %s\n", flatpak_file_get_path_cached (media_dir));
30793084
if (!appstreamcli_compose (error,
3085+
as_url_policy,
30803086
"--prefix=/",
30813087
origin,
30823088
arg_base_url,
@@ -3093,6 +3099,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30933099
{
30943100
g_print ("Running appstreamcli compose\n");
30953101
if (!appstreamcli_compose (error,
3102+
as_url_policy,
30963103
"--prefix=/",
30973104
origin,
30983105
result_root_arg,

0 commit comments

Comments
 (0)