From 30581bf63a346a1505f7269f2f6cb375db9e3f07 Mon Sep 17 00:00:00 2001 From: Seppo Yli-Olli Date: Sun, 12 May 2019 22:04:42 +0300 Subject: [PATCH] Support multiple instances of install-deps-from Closes: #284 Approved by: alexlarsson --- src/builder-main.c | 4 +- src/builder-manifest.c | 149 ++++++++++++++++++++++++++++++----------- src/builder-manifest.h | 2 +- 3 files changed, 114 insertions(+), 41 deletions(-) diff --git a/src/builder-main.c b/src/builder-main.c index 8df45f97..f165ddcf 100644 --- a/src/builder-main.c +++ b/src/builder-main.c @@ -78,7 +78,7 @@ 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; +static char **opt_install_deps_from; static gboolean opt_install_deps_only; static gboolean opt_user; static char *opt_installation; @@ -129,7 +129,7 @@ static GOptionEntry entries[] = { { "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"}, { "install", 0, 0, G_OPTION_ARG_NONE, &opt_install, "Install if build succeeds", NULL}, - { "install-deps-from", 0, 0, G_OPTION_ARG_STRING, &opt_install_deps_from, "Install build dependencies from this remote", "REMOTE"}, + { "install-deps-from", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_install_deps_from, "Install build dependencies from this remote", "REMOTE"}, { "install-deps-only", 0, 0, G_OPTION_ARG_NONE, &opt_install_deps_only, "Stop after installing dependencies"}, { "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, "Install dependencies in user installations", NULL }, { "system", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &opt_user, "Install dependencies in system-wide installations (default)", NULL }, diff --git a/src/builder-manifest.c b/src/builder-manifest.c index 751aad94..b2658f13 100644 --- a/src/builder-manifest.c +++ b/src/builder-manifest.c @@ -3754,44 +3754,53 @@ builder_manifest_show_deps (BuilderManifest *self, } static gboolean -builder_manifest_install_dep (BuilderManifest *self, - BuilderContext *context, - const char *remote, - gboolean opt_user, - const char *opt_installation, - const char *runtime, - const char *version, - gboolean opt_yes, - GError **error) +builder_manifest_install_single_dep (const char *ref, + const char *remote, + gboolean opt_user, + const char *opt_installation, + GError **error) { - g_autofree char *ref = NULL; - g_autofree char *commit = NULL; g_autoptr(GPtrArray) args = NULL; - gboolean installed; - - if (version == NULL) - version = builder_manifest_get_runtime_version (self); - - ref = flatpak_build_untyped_ref (runtime, - version, - builder_context_get_arch (context)); - - commit = flatpak_info (opt_user, opt_installation, "--show-commit", ref, NULL); - installed = (commit != NULL); - args = g_ptr_array_new_with_free_func (g_free); g_ptr_array_add (args, g_strdup ("flatpak")); add_installation_args (args, opt_user, opt_installation); - if (installed) + + g_ptr_array_add (args, g_strdup ("install")); + g_ptr_array_add (args, g_strdup (remote)); + + g_ptr_array_add (args, g_strdup ("-y")); + if (flatpak_version_check (1, 2, 0)) + g_ptr_array_add (args, g_strdup ("--noninteractive")); + + g_ptr_array_add (args, g_strdup (ref)); + g_ptr_array_add (args, NULL); + + if (!builder_maybe_host_spawnv (NULL, NULL, 0, error, (const char * const *)args->pdata)) { - g_ptr_array_add (args, g_strdup ("update")); - g_ptr_array_add (args, g_strdup ("--subpath=")); + g_autofree char *commandline = flatpak_quote_argv ((const char **)args->pdata); + g_prefix_error (error, "running `%s`: ", commandline); + return FALSE; } else { - g_ptr_array_add (args, g_strdup ("install")); - g_ptr_array_add (args, g_strdup (remote)); + return TRUE; } +} + + +static gboolean +builder_manifest_update_single_dep (const char *ref, + gboolean opt_user, + const char *opt_installation, + GError **error) +{ + g_autoptr(GPtrArray) args = NULL; + args = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (args, g_strdup ("flatpak")); + add_installation_args (args, opt_user, opt_installation); + + g_ptr_array_add (args, g_strdup ("update")); + g_ptr_array_add (args, g_strdup ("--subpath=")); g_ptr_array_add (args, g_strdup ("-y")); if (flatpak_version_check (1, 2, 0)) @@ -3806,8 +3815,72 @@ builder_manifest_install_dep (BuilderManifest *self, g_prefix_error (error, "running `%s`: ", commandline); return FALSE; } + else + { + return TRUE; + } +} - return TRUE; +static gboolean +builder_manifest_install_dep (BuilderManifest *self, + BuilderContext *context, + char *const *remotes, + gboolean opt_user, + const char *opt_installation, + const char *runtime, + const char *version, + gboolean opt_yes, + GError **error) +{ + g_autofree char *ref = NULL; + g_autofree char *commit = NULL; + + if (version == NULL) + version = builder_manifest_get_runtime_version (self); + + ref = flatpak_build_untyped_ref (runtime, + version, + builder_context_get_arch (context)); + + commit = flatpak_info (opt_user, opt_installation, "--show-commit", ref, NULL); + + if (commit != NULL) + { + g_print("Updating %s\n", ref); + if (builder_manifest_update_single_dep(ref, opt_user, opt_installation, + error)) + { + return TRUE; + } + } + else + { + gboolean multiple_remotes = (*(remotes+1) != NULL); + for (const char *remote = *remotes; remote != NULL; remote = *(++remotes)) + { + g_autoptr(GError) current_error = NULL; + if (multiple_remotes) + { + g_print("Trying to install %s from %s\n", ref, remote); + } + else { + g_print("Installing %s from %s\n", ref, remote); + } + if (builder_manifest_install_single_dep (ref, remote, opt_user, opt_installation, + ¤t_error)) + { + current_error = g_steal_pointer(error); + return TRUE; + } + else if (*error == NULL) + { + *error = g_steal_pointer(¤t_error); + } + if ((*error)->domain != G_SPAWN_EXIT_ERROR) + return FALSE; + } + } + return FALSE; } static gboolean @@ -3816,7 +3889,7 @@ builder_manifest_install_extension_deps (BuilderManifest *self, const char *runtime, const char *runtime_version, char **runtime_extensions, - const char *remote, + char * const *remotes, gboolean opt_user, const char *opt_installation, gboolean opt_yes, @@ -3864,7 +3937,7 @@ builder_manifest_install_extension_deps (BuilderManifest *self, extension_version = g_strdup (runtime_version); g_print ("Dependency Extension: %s %s\n", runtime_extensions[i], extension_version); - if (!builder_manifest_install_dep (self, context, remote, opt_user, opt_installation, + if (!builder_manifest_install_dep (self, context, remotes, opt_user, opt_installation, runtime_extensions[i], extension_version, opt_yes, error)) @@ -3877,7 +3950,7 @@ builder_manifest_install_extension_deps (BuilderManifest *self, gboolean builder_manifest_install_deps (BuilderManifest *self, BuilderContext *context, - const char *remote, + char * const *remotes, gboolean opt_user, const char *opt_installation, gboolean opt_yes, @@ -3902,7 +3975,7 @@ builder_manifest_install_deps (BuilderManifest *self, /* Sdk */ g_print ("Dependency Sdk: %s %s\n", sdk, sdk_branch); - if (!builder_manifest_install_dep (self, context, remote, opt_user, opt_installation, + if (!builder_manifest_install_dep (self, context, remotes, opt_user, opt_installation, sdk, sdk_branch, opt_yes, error)) @@ -3910,7 +3983,7 @@ builder_manifest_install_deps (BuilderManifest *self, /* Runtime */ g_print ("Dependency Runtime: %s %s\n", self->runtime, builder_manifest_get_runtime_version (self)); - if (!builder_manifest_install_dep (self, context, remote, opt_user, opt_installation, + if (!builder_manifest_install_dep (self, context, remotes, opt_user, opt_installation, self->runtime, builder_manifest_get_runtime_version (self), opt_yes, error)) @@ -3919,7 +3992,7 @@ builder_manifest_install_deps (BuilderManifest *self, if (self->base) { g_print ("Dependency Base: %s %s\n", self->base, builder_manifest_get_base_version (self)); - if (!builder_manifest_install_dep (self, context, remote, opt_user, opt_installation, + if (!builder_manifest_install_dep (self, context, remotes, opt_user, opt_installation, self->base, builder_manifest_get_base_version (self), opt_yes, error)) @@ -3928,7 +4001,7 @@ builder_manifest_install_deps (BuilderManifest *self, if (!builder_manifest_install_extension_deps (self, context, sdk, sdk_branch, self->sdk_extensions, - remote,opt_user, opt_installation, + remotes, opt_user, opt_installation, opt_yes, error)) return FALSE; @@ -3936,7 +4009,7 @@ builder_manifest_install_deps (BuilderManifest *self, if (!builder_manifest_install_extension_deps (self, context, self->runtime, builder_manifest_get_runtime_version (self), self->platform_extensions, - remote, opt_user, opt_installation, + remotes, opt_user, opt_installation, opt_yes, error)) return FALSE; @@ -3951,7 +4024,7 @@ builder_manifest_install_deps (BuilderManifest *self, continue; g_print ("Dependency Extension: %s %s\n", name, version); - if (!builder_manifest_install_dep (self, context, remote, opt_user, opt_installation, + if (!builder_manifest_install_dep (self, context, remotes, opt_user, opt_installation, name, version, opt_yes, error)) diff --git a/src/builder-manifest.h b/src/builder-manifest.h index 845cca44..e4f31d94 100644 --- a/src/builder-manifest.h +++ b/src/builder-manifest.h @@ -98,7 +98,7 @@ gboolean builder_manifest_build (BuilderManifest *self, GError **error); gboolean builder_manifest_install_deps (BuilderManifest *self, BuilderContext *context, - const char *remote, + char * const *remotes, gboolean opt_user, const char *opt_installation, gboolean opt_yes,