builder: Add --delete-build-dirs

This makes sure we always delete build dirs, even if there
was a build failure. This is useful for automatic build systems
like flathub or continuous integration.

This fixes https://github.com/flatpak/flatpak/issues/646
tingping/wmclass
Alexander Larsson 2017-08-18 16:27:59 +02:00
parent 326507602c
commit 37fa3461c9
5 changed files with 92 additions and 42 deletions

View File

@ -62,6 +62,7 @@ struct BuilderContext
BuilderOptions *options;
gboolean keep_build_dirs;
gboolean delete_build_dirs;
int jobs;
char **cleanup;
char **cleanup_platform;
@ -537,6 +538,13 @@ builder_context_set_keep_build_dirs (BuilderContext *self,
self->keep_build_dirs = keep_build_dirs;
}
void
builder_context_set_delete_build_dirs (BuilderContext *self,
gboolean delete_build_dirs)
{
self->delete_build_dirs = delete_build_dirs;
}
void
builder_context_set_global_cleanup (BuilderContext *self,
const char **cleanup)
@ -571,6 +579,12 @@ builder_context_get_keep_build_dirs (BuilderContext *self)
return self->keep_build_dirs;
}
gboolean
builder_context_get_delete_build_dirs (BuilderContext *self)
{
return self->delete_build_dirs;
}
void
builder_context_set_sandboxed (BuilderContext *self,
gboolean sandboxed)

View File

@ -76,6 +76,9 @@ void builder_context_set_jobs (BuilderContext *self,
int n_jobs);
void builder_context_set_keep_build_dirs (BuilderContext *self,
gboolean keep_build_dirs);
gboolean builder_context_get_delete_build_dirs (BuilderContext *self);
void builder_context_set_delete_build_dirs (BuilderContext *self,
gboolean delete_build_dirs);
gboolean builder_context_get_keep_build_dirs (BuilderContext *self);
void builder_context_set_sandboxed (BuilderContext *self,
gboolean sandboxed);

View File

@ -48,6 +48,7 @@ static gboolean opt_disable_updates;
static gboolean opt_ccache;
static gboolean opt_require_changes;
static gboolean opt_keep_build_dirs;
static gboolean opt_delete_build_dirs;
static gboolean opt_force_clean;
static gboolean opt_allow_missing_runtimes;
static gboolean opt_sandboxed;
@ -96,6 +97,7 @@ static GOptionEntry entries[] = {
{ "show-deps", 0, 0, G_OPTION_ARG_NONE, &opt_show_deps, "List the dependencies of the json file (see --show-deps --help)", NULL },
{ "require-changes", 0, 0, G_OPTION_ARG_NONE, &opt_require_changes, "Don't create app dir or export if no changes", NULL },
{ "keep-build-dirs", 0, 0, G_OPTION_ARG_NONE, &opt_keep_build_dirs, "Don't remove build directories after install", NULL },
{ "delete-build-dirs", 0, 0, G_OPTION_ARG_NONE, &opt_delete_build_dirs, "Always remove build directories, even after build failure", NULL },
{ "repo", 0, 0, G_OPTION_ARG_STRING, &opt_repo, "Repo to export into", "DIR"},
{ "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject (passed to build-export)", "SUBJECT" },
{ "body", 'b', 0, G_OPTION_ARG_STRING, &opt_body, "Full description (passed to build-export)", "BODY" },
@ -363,6 +365,7 @@ main (int argc,
builder_context_set_use_rofiles (build_context, !opt_disable_rofiles);
builder_context_set_keep_build_dirs (build_context, opt_keep_build_dirs);
builder_context_set_delete_build_dirs (build_context, opt_delete_build_dirs);
builder_context_set_sandboxed (build_context, opt_sandboxed);
builder_context_set_jobs (build_context, opt_jobs);
builder_context_set_rebuild_on_sdk_change (build_context, opt_rebuild_on_sdk_change);

View File

@ -1203,12 +1203,13 @@ builder_module_ensure_writable (BuilderModule *self,
return TRUE;
}
gboolean
builder_module_build (BuilderModule *self,
BuilderCache *cache,
BuilderContext *context,
gboolean run_shell,
GError **error)
static gboolean
builder_module_build_helper (BuilderModule *self,
BuilderCache *cache,
BuilderContext *context,
GFile *source_dir,
gboolean run_shell,
GError **error)
{
GFile *app_dir = builder_context_get_app_dir (context);
g_autofree char *make_j = NULL;
@ -1217,9 +1218,7 @@ builder_module_build (BuilderModule *self,
gboolean autotools = FALSE, cmake = FALSE, cmake_ninja = FALSE, meson = FALSE, simple = FALSE;
g_autoptr(GFile) configure_file = NULL;
GFile *build_parent_dir = NULL;
g_autoptr(GFile) build_dir = NULL;
g_autoptr(GFile) build_link = NULL;
g_autofree char *build_dir_relative = NULL;
gboolean has_configure;
gboolean var_require_builddir;
@ -1228,44 +1227,14 @@ builder_module_build (BuilderModule *self,
g_auto(GStrv) env = NULL;
g_auto(GStrv) build_args = NULL;
g_auto(GStrv) config_opts = NULL;
g_autoptr(GFile) source_dir = NULL;
g_autoptr(GFile) source_subdir = NULL;
const char *source_subdir_relative = NULL;
g_autofree char *source_dir_path = NULL;
g_autofree char *buildname = NULL;
g_autoptr(GError) my_error = NULL;
BuilderPostProcessFlags post_process_flags = 0;
source_dir = builder_context_allocate_build_subdir (context, self->name, error);
if (source_dir == NULL)
{
g_prefix_error (error, "module %s: ", self->name);
return FALSE;
}
build_parent_dir = g_file_get_parent (source_dir);
buildname = g_file_get_basename (source_dir);
source_dir_path = g_file_get_path (source_dir);
/* Make an unversioned symlink */
build_link = g_file_get_child (build_parent_dir, self->name);
if (!g_file_delete (build_link, NULL, &my_error) &&
!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_propagate_error (error, g_steal_pointer (&my_error));
g_prefix_error (error, "module %s: ", self->name);
return FALSE;
}
g_clear_error (&my_error);
if (!g_file_make_symbolic_link (build_link,
buildname,
NULL, error))
{
g_prefix_error (error, "module %s: ", self->name);
return FALSE;
}
g_print ("========================================================================\n");
g_print ("Building module %s in %s\n", self->name, source_dir_path);
g_print ("========================================================================\n");
@ -1622,12 +1591,63 @@ builder_module_build (BuilderModule *self,
return FALSE;
}
return TRUE;
}
gboolean
builder_module_build (BuilderModule *self,
BuilderCache *cache,
BuilderContext *context,
gboolean run_shell,
GError **error)
{
g_autoptr(GFile) source_dir = NULL;
g_autoptr(GFile) build_parent_dir = NULL;
g_autoptr(GFile) build_link = NULL;
g_autoptr(GError) my_error = NULL;
g_autofree char *buildname = NULL;
gboolean res;
source_dir = builder_context_allocate_build_subdir (context, self->name, error);
if (source_dir == NULL)
{
g_prefix_error (error, "module %s: ", self->name);
return FALSE;
}
build_parent_dir = g_file_get_parent (source_dir);
buildname = g_file_get_basename (source_dir);
/* Make an unversioned symlink */
build_link = g_file_get_child (build_parent_dir, self->name);
if (!g_file_delete (build_link, NULL, &my_error) &&
!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_propagate_error (error, g_steal_pointer (&my_error));
g_prefix_error (error, "module %s: ", self->name);
return FALSE;
}
g_clear_error (&my_error);
if (!g_file_make_symbolic_link (build_link,
buildname,
NULL, error))
{
g_prefix_error (error, "module %s: ", self->name);
return FALSE;
}
res = builder_module_build_helper (self, cache, context, source_dir, run_shell, error);
/* Clean up build dir */
builder_set_term_title (_("Cleanup %s"), self->name);
if (!builder_context_get_keep_build_dirs (context))
if (!run_shell &&
(!builder_context_get_keep_build_dirs (context) &&
(res || builder_context_get_delete_build_dirs (context))))
{
builder_set_term_title (_("Cleanup %s"), self->name);
if (!g_file_delete (build_link, NULL, error))
{
g_prefix_error (error, "module %s: ", self->name);
@ -1641,7 +1661,7 @@ builder_module_build (BuilderModule *self,
}
}
return TRUE;
return res;
}
gboolean

View File

@ -276,6 +276,16 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--delete-build-dirs</option></term>
<listitem><para>
Always remove the sources and build after having built each module, even if the build
failed. The default is to keep failed build directories but remote successful ones.
This is useful in e.g. automatic build systems.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--ccache</option></term>