From ab72117fdd136b935779bf32e93ea4b9ec36e5c9 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 4 Feb 2019 10:46:14 +0100 Subject: [PATCH] Add --add/remove-tag options We'd like to use these in flathub. Closes: #268 Approved by: alexlarsson --- doc/flatpak-builder.xml | 18 +++++++++++++++ src/builder-main.c | 10 +++++++++ src/builder-manifest.c | 50 +++++++++++++++++++++++++++++++++++++++++ src/builder-manifest.h | 5 +++++ 4 files changed, 83 insertions(+) diff --git a/doc/flatpak-builder.xml b/doc/flatpak-builder.xml index 3343c736..cc8d16de 100644 --- a/doc/flatpak-builder.xml +++ b/doc/flatpak-builder.xml @@ -534,6 +534,24 @@ + + + + + Add this tag to the tags list of the manifest before building. + + + + + + + + Remove this tag to the tags list of the manifest before building. The remove + happen before processing the --add-tag option, so if both are specified, then + --app-tag wins. + + + diff --git a/src/builder-main.c b/src/builder-main.c index 51325514..b723f2b3 100644 --- a/src/builder-main.c +++ b/src/builder-main.c @@ -74,6 +74,8 @@ static char *opt_gpg_homedir; static char **opt_key_ids; static char **opt_sources_dirs; static char **opt_sources_urls; +static char **opt_add_tags; +static char **opt_remove_tags; static int opt_jobs; static char *opt_mirror_screenshots_url; static char *opt_install_deps_from; @@ -89,6 +91,8 @@ static GOptionEntry entries[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL }, { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Architecture to build for (must be host compatible)", "ARCH" }, { "default-branch", 0, 0, G_OPTION_ARG_STRING, &opt_default_branch, "Change the default branch", "BRANCH" }, + { "add-tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_add_tags, "Add a tag to the build", "TAG"}, + { "remove-tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_remove_tags, "Remove a tag from the build", "TAG"}, { "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory (see --run --help)", NULL }, { "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL }, { "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Disable cache lookups", NULL }, @@ -689,6 +693,12 @@ main (int argc, return 1; } + if (opt_remove_tags) + builder_manifest_remove_tags (manifest, (const char **)opt_remove_tags); + + if (opt_add_tags) + builder_manifest_add_tags (manifest, (const char **)opt_add_tags); + if (opt_default_branch) builder_context_set_default_branch (build_context, opt_default_branch); diff --git a/src/builder-manifest.c b/src/builder-manifest.c index f0defbdd..4e45a30e 100644 --- a/src/builder-manifest.c +++ b/src/builder-manifest.c @@ -1415,6 +1415,56 @@ builder_manifest_set_default_collection_id (BuilderManifest *self, self->collection_id = g_strdup (default_collection_id); } +void +builder_manifest_add_tags (BuilderManifest *self, + const char **add_tags) +{ + GPtrArray *new_tags = g_ptr_array_new (); + int i; + + for (i = 0; self->tags != NULL && self->tags[i] != NULL; i++) + g_ptr_array_add (new_tags, self->tags[i]); + + for (i = 0; add_tags[i] != NULL; i++) + { + const char *new_tag = add_tags[i]; + if (self->tags == NULL || !g_strv_contains ((const char **)self->tags, new_tag)) + g_ptr_array_add (new_tags, g_strdup (new_tag)); + } + + g_ptr_array_add (new_tags, NULL); + + g_free (self->tags); + self->tags = (char **)g_ptr_array_free (new_tags, FALSE); + +} + +void +builder_manifest_remove_tags (BuilderManifest *self, + const char **remove_tags) +{ + GPtrArray *new_tags = g_ptr_array_new (); + int i; + + if (self->tags) + { + for (i = 0; self->tags[i] != NULL; i++) + { + char *old_tag = self->tags[i]; + if (g_strv_contains (remove_tags, old_tag)) + g_free (old_tag); + else + g_ptr_array_add (new_tags, old_tag); + } + } + + g_ptr_array_add (new_tags, NULL); + + g_free (self->tags); + self->tags = (char **)g_ptr_array_free (new_tags, FALSE); +} + + const char * builder_manifest_get_extension_tag (BuilderManifest *self) { diff --git a/src/builder-manifest.h b/src/builder-manifest.h index 8deb5f54..845cca44 100644 --- a/src/builder-manifest.h +++ b/src/builder-manifest.h @@ -66,6 +66,11 @@ const char * builder_manifest_get_extension_tag (BuilderManifest *self); void builder_manifest_set_default_collection_id (BuilderManifest *self, const char *default_collection_id); +void builder_manifest_add_tags (BuilderManifest *self, + const char **add_tags); +void builder_manifest_remove_tags (BuilderManifest *self, + const char **remove_tags); + char ** builder_manifest_get_exclude_dirs (BuilderManifest *self);