Skip to content

Commit 056354c

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 7538b8c commit 056354c

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
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: 24 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 ('partial' or 'full'). Partial if unspecified.", "POLICY" },
147149
{ NULL }
148150
};
149151

@@ -608,6 +610,28 @@ 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+
if (opt_as_url_policy == NULL)
616+
builder_context_set_as_url_policy (build_context, BUILDER_AS_URL_POLICY_PARTIAL);
617+
else if (g_strcmp0 (opt_as_url_policy, "full") == 0)
618+
{
619+
if (!appstream_version_check (0, 16, 3))
620+
{
621+
g_printerr ("AppStream version >= 0.16.3 required for 'full' compose URL policy\n");
622+
return 1;
623+
}
624+
builder_context_set_as_url_policy (build_context, BUILDER_AS_URL_POLICY_FULL);
625+
}
626+
else if (g_strcmp0 (opt_as_url_policy, "partial") == 0)
627+
builder_context_set_as_url_policy (build_context, BUILDER_AS_URL_POLICY_PARTIAL);
628+
else
629+
{
630+
g_printerr ("Invalid value for --compose-url-policy: %s\n", opt_as_url_policy);
631+
return 1;
632+
}
633+
}
634+
611635
git_init_email ();
612636

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

src/builder-manifest.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ cmpstringp (const void *p1, const void *p2)
24232423

24242424
static gboolean
24252425
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);
@@ -3067,6 +3071,8 @@ builder_manifest_cleanup (BuilderManifest *self,
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);
30693073

3074+
BuilderAsUrlPolicy as_url_policy = builder_context_get_as_url_policy (context);
3075+
30703076
if (opt_mirror_screenshots_url && !opt_export_only)
30713077
{
30723078
g_autofree char *url = g_build_filename (opt_mirror_screenshots_url, NULL);
@@ -3077,6 +3083,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30773083
g_print ("Running appstreamcli compose\n");
30783084
g_print ("Saving screenshots in %s\n", flatpak_file_get_path_cached (media_dir));
30793085
if (!appstreamcli_compose (error,
3086+
as_url_policy,
30803087
"--prefix=/",
30813088
origin,
30823089
arg_base_url,
@@ -3093,6 +3100,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30933100
{
30943101
g_print ("Running appstreamcli compose\n");
30953102
if (!appstreamcli_compose (error,
3103+
as_url_policy,
30963104
"--prefix=/",
30973105
origin,
30983106
result_root_arg,

0 commit comments

Comments
 (0)