Skip to content

Commit 03e1f4d

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 621c7c7 commit 03e1f4d

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

doc/flatpak-builder.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,17 @@
587587
</para></listitem>
588588
</varlistentry>
589589

590+
<varlistentry>
591+
<term><option>--compose-url-policy</option></term>
592+
593+
<listitem><para>
594+
Set the AppStream compose URL policy. Accepted values
595+
are <literal>partial</literal> and <literal>full</literal>.
596+
<literal>full</literal> requires AppStream version >= 0.16.3.
597+
Defaults to <literal>partial</literal> if unspecified.
598+
</para></listitem>
599+
</varlistentry>
600+
590601
<varlistentry>
591602
<term><option>--add-tag=TAG</option></term>
592603

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_URL_POLICY_PARTIAL = 0,
34+
BUILDER_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

@@ -606,6 +608,28 @@ main (int argc,
606608
builder_context_set_opt_export_only (build_context, opt_export_only);
607609
builder_context_set_opt_mirror_screenshots_url (build_context, opt_mirror_screenshots_url);
608610

611+
if (opt_mirror_screenshots_url)
612+
{
613+
if (opt_as_url_policy == NULL)
614+
builder_context_set_as_url_policy (build_context, BUILDER_URL_POLICY_PARTIAL);
615+
else if (g_strcmp0 (opt_as_url_policy, "full") == 0)
616+
{
617+
if (!appstream_version_check (0, 16, 3))
618+
{
619+
g_printerr ("AppStream version >= 0.16.3 required for 'full' compose URL policy\n");
620+
return 1;
621+
}
622+
builder_context_set_as_url_policy (build_context, BUILDER_URL_POLICY_FULL);
623+
}
624+
else if (g_strcmp0 (opt_as_url_policy, "partial") == 0)
625+
builder_context_set_as_url_policy (build_context, BUILDER_URL_POLICY_PARTIAL);
626+
else
627+
{
628+
g_printerr ("Invalid value for --compose-url-policy: %s\n", opt_as_url_policy);
629+
return 1;
630+
}
631+
}
632+
609633
git_init_email ();
610634

611635
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
@@ -2405,6 +2405,7 @@ cmpstringp (const void *p1, const void *p2)
24052405

24062406
static gboolean
24072407
appstreamcli_compose (GError **error,
2408+
BuilderAsUrlPolicy as_url_policy,
24082409
...)
24092410
{
24102411
g_autoptr(GPtrArray) args = NULL;
@@ -2415,7 +2416,10 @@ appstreamcli_compose (GError **error,
24152416
g_ptr_array_add (args, g_strdup ("appstreamcli"));
24162417
g_ptr_array_add (args, g_strdup ("compose"));
24172418

2418-
va_start (ap, error);
2419+
if (as_url_policy == BUILDER_URL_POLICY_FULL)
2420+
g_ptr_array_add (args, g_strdup ("--no-partial-urls"));
2421+
2422+
va_start (ap, as_url_policy);
24192423
while ((arg = va_arg (ap, const gchar *)))
24202424
g_ptr_array_add (args, g_strdup (arg));
24212425
g_ptr_array_add (args, NULL);
@@ -3049,6 +3053,8 @@ builder_manifest_cleanup (BuilderManifest *self,
30493053
const char *opt_mirror_screenshots_url = builder_context_get_opt_mirror_screenshots_url (context);
30503054
gboolean opt_export_only = builder_context_get_opt_export_only (context);
30513055

3056+
BuilderAsUrlPolicy as_url_policy = builder_context_get_as_url_policy (context);
3057+
30523058
if (opt_mirror_screenshots_url && !opt_export_only)
30533059
{
30543060
g_autofree char *url = g_build_filename (opt_mirror_screenshots_url, NULL);
@@ -3059,6 +3065,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30593065
g_print ("Running appstreamcli compose\n");
30603066
g_print ("Saving screenshots in %s\n", flatpak_file_get_path_cached (media_dir));
30613067
if (!appstreamcli_compose (error,
3068+
as_url_policy,
30623069
"--prefix=/",
30633070
origin,
30643071
arg_base_url,
@@ -3075,6 +3082,7 @@ builder_manifest_cleanup (BuilderManifest *self,
30753082
{
30763083
g_print ("Running appstreamcli compose\n");
30773084
if (!appstreamcli_compose (error,
3085+
as_url_policy,
30783086
"--prefix=/",
30793087
origin,
30803088
result_root_arg,

0 commit comments

Comments
 (0)