builder: Add support for screenshot mirroring

Specify --mirror-screenshots-url=URL and then copy the resulting
appdata/screenshots directory to the URL, then these
will be used instead of the upstream screenshots.
This commit is contained in:
Alexander Larsson
2017-05-22 16:18:45 +02:00
parent e47a726061
commit e41cb789fa
2 changed files with 56 additions and 0 deletions

View File

@@ -65,6 +65,7 @@ static char *opt_gpg_homedir;
static char **opt_key_ids;
static char **opt_sources_dirs;
static int opt_jobs;
static char *opt_mirror_screenshots_url;
static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
@@ -100,6 +101,7 @@ static GOptionEntry entries[] = {
{ "build-shell", 0, 0, G_OPTION_ARG_STRING, &opt_build_shell, "Extract and prepare sources for module, then start build shell", "MODULENAME"},
{ "from-git", 0, 0, G_OPTION_ARG_STRING, &opt_from_git, "Get input files from git repo", "URL"},
{ "from-git-branch", 0, 0, G_OPTION_ARG_STRING, &opt_from_git_branch, "Branch to use in --from-git", "BRANCH"},
{ "mirror-screenshots-url", 0, 0, G_OPTION_ARG_STRING, &opt_mirror_screenshots_url, "Download and rewrite screenshots to match this url", "URL"},
{ NULL }
};
@@ -608,6 +610,49 @@ main (int argc,
if (!opt_require_changes)
builder_cache_ensure_checkout (cache);
if (opt_mirror_screenshots_url)
{
g_autofree char *screenshot_subdir = g_strdup_printf ("%s-%s", builder_manifest_get_id (manifest),
builder_manifest_get_branch (manifest, opt_default_branch));
g_autofree char *url = g_build_filename (opt_mirror_screenshots_url, screenshot_subdir, NULL);
g_autofree char *xml_relpath = g_strdup_printf ("files/share/app-info/xmls/%s.xml.gz", builder_manifest_get_id (manifest));
g_autoptr(GFile) xml = g_file_resolve_relative_path (app_dir, xml_relpath);
g_autoptr(GFile) cache = flatpak_build_file (builder_context_get_state_dir (build_context), "screenshots-cache", NULL);
g_autoptr(GFile) screenshots = flatpak_build_file (app_dir, "screenshots", NULL);
g_autoptr(GFile) screenshots_sub = flatpak_build_file (screenshots, screenshot_subdir, NULL);
const char *argv[] = {
"appstream-util",
"mirror-screenshots",
flatpak_file_get_path_cached (xml),
url,
flatpak_file_get_path_cached (cache),
flatpak_file_get_path_cached (screenshots_sub),
NULL
};
g_print ("Mirroring screenshots from appdata\n");
if (!flatpak_mkdir_p (screenshots, NULL, &error))
{
g_printerr ("Error creating screenshot dir: %s\n", error->message);
return 1;
}
if (g_file_query_exists (xml, NULL))
{
if (!builder_maybe_host_spawnv (NULL,
NULL,
&error,
argv))
{
g_printerr ("Error mirroring screenshots: %s\n", error->message);
return 1;
}
}
g_print ("Saved screenshots in %s\n", flatpak_file_get_path_cached (screenshots));
}
if (!opt_build_only && opt_repo && builder_cache_has_checkout (cache))
{
g_autoptr(GFile) debuginfo_metadata = NULL;

View File

@@ -383,6 +383,17 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--mirror-screenshots-url=URL</option></term>
<listitem><para>
Mirror any screenshots in the appstream and rewrite the appstream xml
as if they were on the specified URL. The resulting files will
be stored in the "screenshots" subdirectory in the app directory
and needs to be copied to the specified URL for the appdata to work.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--from-git=GIT</option></term>