builder: Add --stop-at=module

Stop building at a specified module from the json file.
This is useful during development. For instance, you can do --stop-at=main-app
to build all the dependencies into the appdir, then you can do a build of an
already checked out git repo (possibly with changes).
tingping/wmclass
Alexander Larsson 2016-08-19 11:25:23 +02:00
parent f622b014a7
commit fb3bfae85b
5 changed files with 56 additions and 5 deletions

View File

@ -39,6 +39,7 @@ struct BuilderContext
GFile *base_dir;
SoupSession *soup_session;
char *arch;
char *stop_at;
GFile *download_dir;
GFile *state_dir;
@ -85,6 +86,7 @@ builder_context_finalize (GObject *object)
g_clear_object (&self->soup_session);
g_clear_object (&self->options);
g_free (self->arch);
g_free (self->stop_at);
g_strfreev (self->cleanup);
g_strfreev (self->cleanup_platform);
@ -266,6 +268,20 @@ builder_context_set_arch (BuilderContext *self,
self->arch = g_strdup (arch);
}
const char *
builder_context_get_stop_at (BuilderContext *self)
{
return self->stop_at;
}
void
builder_context_set_stop_at (BuilderContext *self,
const char *module)
{
g_free (self->stop_at);
self->stop_at = g_strdup (module);
}
BuilderOptions *
builder_context_get_options (BuilderContext *self)
{

View File

@ -46,6 +46,9 @@ SoupSession * builder_context_get_soup_session (BuilderContext *self);
const char * builder_context_get_arch (BuilderContext *self);
void builder_context_set_arch (BuilderContext *self,
const char *arch);
const char * builder_context_get_stop_at (BuilderContext *self);
void builder_context_set_stop_at (BuilderContext *self,
const char *module);
int builder_context_get_n_cpu (BuilderContext *self);
void builder_context_set_keep_build_dirs (BuilderContext *self,
gboolean keep_build_dirs);

View File

@ -44,6 +44,7 @@ static gboolean opt_ccache;
static gboolean opt_require_changes;
static gboolean opt_keep_build_dirs;
static gboolean opt_force_clean;
static char *opt_stop_at;
static char *opt_arch;
static char *opt_repo;
static char *opt_subject;
@ -70,6 +71,7 @@ static GOptionEntry entries[] = {
{ "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"},
{ "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"},
{ "force-clean", 0, 0, G_OPTION_ARG_NONE, &opt_force_clean, "Erase previous contents of DIRECTORY", NULL },
{ "stop-at", 0, 0, G_OPTION_ARG_STRING, &opt_stop_at, "Stop building at this module (implies --build-only)", "MODULENAME"},
{ NULL }
};
@ -285,6 +287,12 @@ main (int argc,
if (opt_arch)
builder_context_set_arch (build_context, opt_arch);
if (opt_stop_at)
{
opt_build_only = TRUE;
builder_context_set_stop_at (build_context, opt_stop_at);
}
if (opt_ccache &&
!builder_context_enable_ccache (build_context, &error))
{

View File

@ -906,6 +906,7 @@ builder_manifest_start (BuilderManifest *self,
{
g_autofree char *arch_option = NULL;
g_autoptr(GHashTable) names = g_hash_table_new (g_str_hash, g_str_equal);
const char *stop_at;
if (self->sdk == NULL)
{
@ -933,6 +934,10 @@ builder_manifest_start (BuilderManifest *self,
if (!expand_modules (self->modules, &self->expanded_modules, names, error))
return FALSE;
stop_at = builder_context_get_stop_at (context);
if (stop_at != NULL && g_hash_table_lookup (names, stop_at) == NULL)
return flatpak_fail (error, "No module named %s (specified with --stop-at)", stop_at);
return TRUE;
}
@ -1153,6 +1158,7 @@ builder_manifest_build (BuilderManifest *self,
BuilderContext *context,
GError **error)
{
const char *stop_at = builder_context_get_stop_at (context);
GList *l;
builder_context_set_options (context, self->build_options);
@ -1166,12 +1172,19 @@ builder_manifest_build (BuilderManifest *self,
{
BuilderModule *m = l->data;
g_autoptr(GPtrArray) changes = NULL;
const char *name = builder_module_get_name (m);
g_autofree char *stage = g_strdup_printf ("build-%s", builder_module_get_name (m));
g_autofree char *stage = g_strdup_printf ("build-%s", name);
if (stop_at != NULL && strcmp (name, stop_at) == 0)
{
g_print ("Stopping at module %s\n", stop_at);
return TRUE;
}
if (!builder_module_get_sources (m))
{
g_print ("Skipping module %s (no sources)\n", builder_module_get_name (m));
g_print ("Skipping module %s (no sources)\n", name);
continue;
}
@ -1180,7 +1193,7 @@ builder_manifest_build (BuilderManifest *self,
if (!builder_cache_lookup (cache, stage))
{
g_autofree char *body =
g_strdup_printf ("Built %s\n", builder_module_get_name (m));
g_strdup_printf ("Built %s\n", name);
if (!builder_module_build (m, cache, context, error))
return FALSE;
if (!builder_cache_commit (cache, body, error))
@ -1188,8 +1201,7 @@ builder_manifest_build (BuilderManifest *self,
}
else
{
g_print ("Cache hit for %s, skipping build\n",
builder_module_get_name (m));
g_print ("Cache hit for %s, skipping build\n", name);
}
changes = builder_cache_get_changes (cache, error);

View File

@ -671,6 +671,18 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--stop-at=MODULENAME</option></term>
<listitem><para>
Stop building at the specified module, ignoring all the following ones.
This is useful for debugging and development. For instance, you can
build all the dependencies, but stop at the main application so that
you can then do a build from a pre-existing checkout.
Implies --build-only.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--repo=DIR</option></term>