Skip to content

Commit ab72117

Browse files
alexlarssonrh-atomic-bot
authored andcommitted
Add --add/remove-tag options
We'd like to use these in flathub. Closes: #268 Approved by: alexlarsson
1 parent 21356f8 commit ab72117

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

doc/flatpak-builder.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,24 @@
534534
</para></listitem>
535535
</varlistentry>
536536

537+
<varlistentry>
538+
<term><option>--add-tag=TAG</option></term>
539+
540+
<listitem><para>
541+
Add this tag to the tags list of the manifest before building.
542+
</para></listitem>
543+
</varlistentry>
544+
545+
<varlistentry>
546+
<term><option>--remove-tag=TAG</option></term>
547+
548+
<listitem><para>
549+
Remove this tag to the tags list of the manifest before building. The remove
550+
happen before processing the --add-tag option, so if both are specified, then
551+
--app-tag wins.
552+
</para></listitem>
553+
</varlistentry>
554+
537555
<varlistentry>
538556
<term><option>--install-deps-from=REMOTE</option></term>
539557

src/builder-main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static char *opt_gpg_homedir;
7474
static char **opt_key_ids;
7575
static char **opt_sources_dirs;
7676
static char **opt_sources_urls;
77+
static char **opt_add_tags;
78+
static char **opt_remove_tags;
7779
static int opt_jobs;
7880
static char *opt_mirror_screenshots_url;
7981
static char *opt_install_deps_from;
@@ -89,6 +91,8 @@ static GOptionEntry entries[] = {
8991
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL },
9092
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Architecture to build for (must be host compatible)", "ARCH" },
9193
{ "default-branch", 0, 0, G_OPTION_ARG_STRING, &opt_default_branch, "Change the default branch", "BRANCH" },
94+
{ "add-tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_add_tags, "Add a tag to the build", "TAG"},
95+
{ "remove-tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_remove_tags, "Remove a tag from the build", "TAG"},
9296
{ "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory (see --run --help)", NULL },
9397
{ "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL },
9498
{ "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Disable cache lookups", NULL },
@@ -689,6 +693,12 @@ main (int argc,
689693
return 1;
690694
}
691695

696+
if (opt_remove_tags)
697+
builder_manifest_remove_tags (manifest, (const char **)opt_remove_tags);
698+
699+
if (opt_add_tags)
700+
builder_manifest_add_tags (manifest, (const char **)opt_add_tags);
701+
692702
if (opt_default_branch)
693703
builder_context_set_default_branch (build_context, opt_default_branch);
694704

src/builder-manifest.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,56 @@ builder_manifest_set_default_collection_id (BuilderManifest *self,
14151415
self->collection_id = g_strdup (default_collection_id);
14161416
}
14171417

1418+
void
1419+
builder_manifest_add_tags (BuilderManifest *self,
1420+
const char **add_tags)
1421+
{
1422+
GPtrArray *new_tags = g_ptr_array_new ();
1423+
int i;
1424+
1425+
for (i = 0; self->tags != NULL && self->tags[i] != NULL; i++)
1426+
g_ptr_array_add (new_tags, self->tags[i]);
1427+
1428+
for (i = 0; add_tags[i] != NULL; i++)
1429+
{
1430+
const char *new_tag = add_tags[i];
1431+
if (self->tags == NULL || !g_strv_contains ((const char **)self->tags, new_tag))
1432+
g_ptr_array_add (new_tags, g_strdup (new_tag));
1433+
}
1434+
1435+
g_ptr_array_add (new_tags, NULL);
1436+
1437+
g_free (self->tags);
1438+
self->tags = (char **)g_ptr_array_free (new_tags, FALSE);
1439+
1440+
}
1441+
1442+
void
1443+
builder_manifest_remove_tags (BuilderManifest *self,
1444+
const char **remove_tags)
1445+
{
1446+
GPtrArray *new_tags = g_ptr_array_new ();
1447+
int i;
1448+
1449+
if (self->tags)
1450+
{
1451+
for (i = 0; self->tags[i] != NULL; i++)
1452+
{
1453+
char *old_tag = self->tags[i];
1454+
if (g_strv_contains (remove_tags, old_tag))
1455+
g_free (old_tag);
1456+
else
1457+
g_ptr_array_add (new_tags, old_tag);
1458+
}
1459+
}
1460+
1461+
g_ptr_array_add (new_tags, NULL);
1462+
1463+
g_free (self->tags);
1464+
self->tags = (char **)g_ptr_array_free (new_tags, FALSE);
1465+
}
1466+
1467+
14181468
const char *
14191469
builder_manifest_get_extension_tag (BuilderManifest *self)
14201470
{

src/builder-manifest.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const char * builder_manifest_get_extension_tag (BuilderManifest *self);
6666
void builder_manifest_set_default_collection_id (BuilderManifest *self,
6767
const char *default_collection_id);
6868

69+
void builder_manifest_add_tags (BuilderManifest *self,
70+
const char **add_tags);
71+
void builder_manifest_remove_tags (BuilderManifest *self,
72+
const char **remove_tags);
73+
6974

7075
char ** builder_manifest_get_exclude_dirs (BuilderManifest *self);
7176

0 commit comments

Comments
 (0)