Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/flatpak-builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--alt=ALTNAME</option></term>

<listitem><para>
Build an alternative version of the manifest specified by the name and the alt options
(like e.g. only-alts) in the manifest. If this is not specified the alternative used is
called "default".
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--stop-at=MODULENAME</option></term>

Expand Down
24 changes: 22 additions & 2 deletions doc/flatpak-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@
<term><option>arch</option> (object)</term>
<listitem><para>This is a dictionary defining for each arch a separate build options object that override the main one.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>alt</option> (object)</term>
<listitem><para>This is a dictionary defining for each named alternate build a separate options object that override the main one. This object may also have per-arch sub-options.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2>
Expand Down Expand Up @@ -539,6 +543,14 @@
<term><option>skip-arches</option> (array of strings)</term>
<listitem><para>Don't build on any of the arches listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>only-alts</option> (array of strings)</term>
<listitem><para>If non-empty, only build the module on the alternative builds listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>skip-alts</option> (array of strings)</term>
<listitem><para>Don't build in any of the alternative builds listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>cleanup-platform</option> (array of strings)</term>
<listitem><para>Extra files to clean up in the platform.</para></listitem>
Expand Down Expand Up @@ -578,11 +590,19 @@
<variablelist>
<varlistentry>
<term><option>only-arches</option> (array of strings)</term>
<listitem><para>If non-empty, only build the module on the arches listed.</para></listitem>
<listitem><para>If non-empty, only include the source on the arches listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>skip-arches</option> (array of strings)</term>
<listitem><para>Don't build on any of the arches listed.</para></listitem>
<listitem><para>Don't include the source on any of the arches listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>only-alts</option> (array of strings)</term>
<listitem><para>If non-empty, only include the source on the alternative builds listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>skip-alts</option> (array of strings)</term>
<listitem><para>Don't include the source on any of the alternative builds listed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>dest</option> (string)</term>
Expand Down
28 changes: 28 additions & 0 deletions src/builder-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct BuilderContext
SoupSession *soup_session;
CURL *curl_session;
char *arch;
char *alt;
char *stop_at;

GFile *download_dir;
Expand Down Expand Up @@ -118,6 +119,7 @@ builder_context_finalize (GObject *object)
g_clear_object (&self->options);
g_clear_object (&self->sdk_config);
g_free (self->arch);
g_free (self->alt);
g_free (self->state_subdir);
g_free (self->stop_at);
g_strfreev (self->cleanup);
Expand Down Expand Up @@ -563,6 +565,32 @@ builder_context_set_arch (BuilderContext *self,
self->arch = g_strdup (arch);
}

const char *
builder_context_get_alt (BuilderContext *self)
{
return (const char *) self->alt;
}

const char *
builder_context_get_defaulted_alt (BuilderContext *self)
{
if (self->alt == NULL)
return "default";
return (const char *) self->alt;
}

void
builder_context_set_alt (BuilderContext *self,
const char *alt)
{
g_free (self->alt);

if (g_strcmp0 (alt, "default") == 0)
alt = NULL;

self->alt = g_strdup (alt);
}

const char *
builder_context_get_stop_at (BuilderContext *self)
{
Expand Down
4 changes: 4 additions & 0 deletions src/builder-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ CURL * builder_context_get_curl_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_alt (BuilderContext *self);
const char * builder_context_get_defaulted_alt (BuilderContext *self);
void builder_context_set_alt (BuilderContext *self,
const char *alt);
const char * builder_context_get_stop_at (BuilderContext *self);
void builder_context_set_stop_at (BuilderContext *self,
const char *module);
Expand Down
45 changes: 27 additions & 18 deletions src/builder-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static char *opt_installation;
static gboolean opt_log_session_bus;
static gboolean opt_log_system_bus;
static gboolean opt_yes;
static char *opt_alt;

static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
Expand Down Expand Up @@ -133,6 +134,7 @@ static GOptionEntry entries[] = {
{ "state-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_state_dir, "Use this directory for state instead of .flatpak-builder", "PATH" },
{ "assumeyes", 'y', 0, G_OPTION_ARG_NONE, &opt_yes, N_("Automatically answer yes for all questions"), NULL },
{ "no-shallow-clone", 0, 0, G_OPTION_ARG_NONE, &opt_no_shallow_clone, "Don't use shallow clones when mirroring git repos", NULL },
{ "alt", 0, 0, G_OPTION_ARG_STRING, &opt_alt, "Build an alternative build", "ALTNAME"},
{ NULL }
};

Expand Down Expand Up @@ -317,8 +319,6 @@ main (int argc,
g_autoptr(GFile) manifest_file = NULL;
g_autoptr(GFile) app_dir = NULL;
g_autoptr(BuilderCache) cache = NULL;
g_autofree char *cache_branch = NULL;
g_autofree char *escaped_cache_branch = NULL;
g_autoptr(GFileEnumerator) dir_enum = NULL;
g_autoptr(GFileEnumerator) dir_enum2 = NULL;
g_autofree char *cwd = NULL;
Expand Down Expand Up @@ -450,6 +450,7 @@ main (int argc,
builder_context_set_jobs (build_context, opt_jobs);
builder_context_set_rebuild_on_sdk_change (build_context, opt_rebuild_on_sdk_change);
builder_context_set_bundle_sources (build_context, opt_bundle_sources);
builder_context_set_alt (build_context, opt_alt);

if (opt_sources_dirs)
{
Expand Down Expand Up @@ -723,23 +724,31 @@ main (int argc,
return 0;
}

if (opt_state_dir)
{
/* If the state dir can be shared we need to use a global identifier for the key */
g_autofree char *manifest_path = g_file_get_path (manifest_file);
cache_branch = g_strconcat (builder_context_get_arch (build_context), "-", manifest_path + 1, NULL);
}
else
cache_branch = g_strconcat (builder_context_get_arch (build_context), "-", manifest_basename, NULL);

escaped_cache_branch = g_uri_escape_string (cache_branch, "", TRUE);
for (p = escaped_cache_branch; *p; p++)
{
if (*p == '%')
*p = '_';
}
{
g_autofree char *cache_branch = NULL;
g_autofree char *escaped_cache_branch = NULL;
g_autofree char *manifest_path = g_file_get_path (manifest_file);
const char *reference = manifest_basename;
const char *alt = builder_context_get_alt (build_context);

/* If the state dir can be shared we need to use a global identifier for the key */
if (opt_state_dir)
reference = manifest_path + 1;

cache_branch = g_strconcat (builder_context_get_arch (build_context),
alt ? "-" : "", alt ? alt : "",
"-", reference, NULL);

escaped_cache_branch = g_uri_escape_string (cache_branch, "", TRUE);
for (p = escaped_cache_branch; *p; p++)
{
if (*p == '%')
*p = '_';
}

cache = builder_cache_new (build_context, app_dir, escaped_cache_branch);
}

cache = builder_cache_new (build_context, app_dir, escaped_cache_branch);
if (!builder_cache_open (cache, &error))
{
g_printerr ("Error opening cache: %s\n", error->message);
Expand Down
1 change: 0 additions & 1 deletion src/builder-manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,6 @@ builder_manifest_checksum (BuilderManifest *self,
builder_cache_checksum_str (cache, self->base_commit);
builder_cache_checksum_strv (cache, self->base_extensions);
builder_cache_checksum_compat_str (cache, self->extension_tag);

if (self->build_options)
builder_options_checksum (self->build_options, cache, context);

Expand Down
53 changes: 52 additions & 1 deletion src/builder-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct BuilderModule
char **ensure_writable;
char **only_arches;
char **skip_arches;
char **only_alts;
char **skip_alts;
gboolean disabled;
gboolean rm_configure;
gboolean no_autogen;
Expand Down Expand Up @@ -103,8 +105,10 @@ enum {
PROP_MAKE_INSTALL_ARGS,
PROP_ENSURE_WRITABLE,
PROP_ONLY_ARCHES,
PROP_RUN_TESTS,
PROP_SKIP_ARCHES,
PROP_ONLY_ALTS,
PROP_SKIP_ALTS,
PROP_RUN_TESTS,
PROP_SOURCES,
PROP_BUILD_OPTIONS,
PROP_CLEANUP,
Expand Down Expand Up @@ -149,6 +153,8 @@ builder_module_finalize (GObject *object)
g_strfreev (self->ensure_writable);
g_strfreev (self->only_arches);
g_strfreev (self->skip_arches);
g_strfreev (self->only_alts);
g_strfreev (self->skip_alts);
g_clear_object (&self->build_options);
g_list_free_full (self->sources, g_object_unref);
g_strfreev (self->cleanup);
Expand Down Expand Up @@ -249,6 +255,14 @@ builder_module_get_property (GObject *object,
g_value_set_boxed (value, self->skip_arches);
break;

case PROP_ONLY_ALTS:
g_value_set_boxed (value, self->only_alts);
break;

case PROP_SKIP_ALTS:
g_value_set_boxed (value, self->skip_alts);
break;

case PROP_POST_INSTALL:
g_value_set_boxed (value, self->post_install);
break;
Expand Down Expand Up @@ -398,6 +412,18 @@ builder_module_set_property (GObject *object,
g_strfreev (tmp);
break;

case PROP_ONLY_ALTS:
tmp = self->only_alts;
self->only_alts = g_strdupv (g_value_get_boxed (value));
g_strfreev (tmp);
break;

case PROP_SKIP_ALTS:
tmp = self->skip_alts;
self->skip_alts = g_strdupv (g_value_get_boxed (value));
g_strfreev (tmp);
break;

case PROP_POST_INSTALL:
tmp = self->post_install;
self->post_install = g_strdupv (g_value_get_boxed (value));
Expand Down Expand Up @@ -601,6 +627,20 @@ builder_module_class_init (BuilderModuleClass *klass)
"",
G_TYPE_STRV,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_ONLY_ALTS,
g_param_spec_boxed ("only-alts",
"",
"",
G_TYPE_STRV,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_SKIP_ALTS,
g_param_spec_boxed ("skip-alts",
"",
"",
G_TYPE_STRV,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_POST_INSTALL,
g_param_spec_boxed ("post-install",
Expand Down Expand Up @@ -947,6 +987,15 @@ builder_module_is_enabled (BuilderModule *self,
g_strv_contains ((const char * const *)self->skip_arches, builder_context_get_arch (context)))
return FALSE;

if (self->only_alts != NULL &&
self->only_alts[0] != NULL &&
!g_strv_contains ((const char * const *) self->only_alts, builder_context_get_defaulted_alt (context)))
return FALSE;

if (self->skip_alts != NULL &&
g_strv_contains ((const char * const *)self->skip_alts, builder_context_get_defaulted_alt (context)))
return FALSE;

return TRUE;
}

Expand Down Expand Up @@ -1961,6 +2010,8 @@ builder_module_checksum (BuilderModule *self,
builder_cache_checksum_strv (cache, self->ensure_writable);
builder_cache_checksum_strv (cache, self->only_arches);
builder_cache_checksum_strv (cache, self->skip_arches);
builder_cache_checksum_compat_strv (cache, self->only_alts);
builder_cache_checksum_compat_strv (cache, self->skip_alts);
builder_cache_checksum_boolean (cache, self->rm_configure);
builder_cache_checksum_boolean (cache, self->no_autogen);
builder_cache_checksum_boolean (cache, self->disabled);
Expand Down
Loading