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
16 changes: 14 additions & 2 deletions doc/flatpak-builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,20 @@
<term><option>--ccache</option></term>

<listitem><para>
Enable use of ccache in the build (needs ccache in the sdk). The default ccache folder can be
overridden by setting the environment variable CCACHE_DIR.
This option is deprecated since 1.5.0 and kept for compatibility
as ccache is enabled by default if it exists in the SDK.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--no-ccache</option></term>

<listitem><para>
Disable use of ccache in the build.

ccache is enabled by default if it exists in the
SDK. The default ccache folder can be overridden by
setting the CCACHE_DIR environment variable.
</para></listitem>
</varlistentry>

Expand Down
32 changes: 32 additions & 0 deletions src/builder-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,38 @@ builder_context_get_sdk_config (BuilderContext *self)
return self->sdk_config;
}

gboolean
builder_context_ccache_available_in_sdk (BuilderContext *self,
const char *sdk_path)
{
static const char ccache_path[] = "files/bin/ccache";

glnx_autofd int root_dfd = -1;
glnx_autofd int fd = -1;
struct stat st;

if (!glnx_opendirat (AT_FDCWD, sdk_path, TRUE, &root_dfd, NULL))
return FALSE;

fd = glnx_chaseat (root_dfd,
ccache_path,
GLNX_CHASE_RESOLVE_BENEATH |
GLNX_CHASE_MUST_BE_REGULAR,
NULL);
if (fd < 0)
return FALSE;

if (fstat (fd, &st) < 0)
return FALSE;

if ((st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0)
return FALSE;

g_print ("Found ccache at %s/%s\n", sdk_path, ccache_path);

return TRUE;
}

gboolean
builder_context_create_state_dir (BuilderContext *self,
GError **error)
Expand Down
3 changes: 3 additions & 0 deletions src/builder-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ const char * builder_context_get_opt_mirror_screenshots_url (BuilderContext *

BuilderSdkConfig * builder_context_get_sdk_config (BuilderContext *self);

gboolean builder_context_ccache_available_in_sdk (BuilderContext *self,
const char *sdk_path);

gboolean builder_context_create_state_dir (BuilderContext *self,
GError **error);

Expand Down
34 changes: 25 additions & 9 deletions src/builder-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static gboolean opt_show_deps;
static gboolean opt_show_manifest;
static gboolean opt_disable_download;
static gboolean opt_disable_updates;
static gboolean opt_ccache;
static gboolean opt_ccache; /* deprecated, kept for compat */
static gboolean opt_no_ccache;
static gboolean opt_require_changes;
static gboolean opt_keep_build_dirs;
static gboolean opt_delete_build_dirs;
Expand Down Expand Up @@ -99,7 +100,8 @@ static GOptionEntry entries[] = {
{ "add-tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_add_tags, "Add a tag to the build", "TAG"},
{ "remove-tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_remove_tags, "Remove a tag from the build", "TAG"},
{ "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory (see --run --help)", NULL },
{ "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL },
{ "ccache", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache (deprecated as it is auto-enabled when available in SDK)", NULL },
{ "no-ccache", 0, 0, G_OPTION_ARG_NONE, &opt_no_ccache, "Disable ccache use", NULL },
{ "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Disable cache lookups", NULL },
{ "disable-tests", 0, 0, G_OPTION_ARG_NONE, &opt_disable_tests, "Don't run tests", NULL },
{ "disable-rofiles-fuse", 0, 0, G_OPTION_ARG_NONE, &opt_disable_rofiles, "Disable rofiles-fuse use", NULL },
Expand Down Expand Up @@ -155,7 +157,8 @@ static GOptionEntry run_entries[] = {
{ "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory", NULL },
{ "log-session-bus", 0, 0, G_OPTION_ARG_NONE, &opt_log_session_bus, N_("Log session bus calls"), NULL },
{ "log-system-bus", 0, 0, G_OPTION_ARG_NONE, &opt_log_system_bus, N_("Log system bus calls"), NULL },
{ "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL },
{ "ccache", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache (deprecated as it is auto-enabled when available in SDK)", NULL },
{ "no-ccache", 0, 0, G_OPTION_ARG_NONE, &opt_no_ccache, "Disable ccache use", NULL },
{ "state-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_state_dir, "Use this directory for state instead of .flatpak-builder", "PATH" },
{ NULL }
};
Expand Down Expand Up @@ -691,12 +694,6 @@ main (int argc,
builder_context_set_stop_at (build_context, opt_stop_at);
}

if (!builder_context_set_enable_ccache (build_context, opt_ccache, &error))
{
g_printerr ("Can't initialize ccache use: %s\n", error->message);
return 1;
}

if (opt_from_git)
{
g_autofree char *manifest_dirname = g_path_get_dirname (manifest_rel_path);
Expand Down Expand Up @@ -953,6 +950,25 @@ main (int argc,
return 1;
}

if (!opt_no_ccache)
{
gboolean want_ccache = FALSE;
const char *sdk_path = builder_manifest_get_sdk_path (manifest);

if (sdk_path != NULL)
want_ccache = builder_context_ccache_available_in_sdk (build_context, sdk_path);

if (!want_ccache && opt_ccache)
g_printerr ("Warning: --ccache passed but ccache not found in SDK, ignoring\n");

if (want_ccache &&
!builder_context_set_enable_ccache (build_context, TRUE, &error))
{
g_printerr ("Can't initialize ccache use: %s\n", error->message);
return 1;
}
}

if (!opt_finish_only &&
!opt_export_only &&
!opt_disable_download &&
Expand Down
16 changes: 12 additions & 4 deletions src/builder-manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct BuilderManifest
char *runtime_version;
char *sdk;
char *sdk_commit;
char *sdk_path;
char *var;
char *base;
char *base_commit;
Expand Down Expand Up @@ -195,6 +196,7 @@ builder_manifest_finalize (GObject *object)
g_free (self->runtime_version);
g_free (self->sdk);
g_free (self->sdk_commit);
g_free (self->sdk_path);
g_free (self->base);
g_free (self->base_commit);
g_free (self->base_version);
Expand Down Expand Up @@ -1477,6 +1479,12 @@ builder_manifest_get_runtime_version (BuilderManifest *self)
return self->runtime_version ? self->runtime_version : "master";
}

const char *
builder_manifest_get_sdk_path (BuilderManifest *self)
{
return self->sdk_path;
}

const char *
builder_manifest_get_branch (BuilderManifest *self,
BuilderContext *context)
Expand Down Expand Up @@ -1687,7 +1695,6 @@ 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);
g_autofree char *sdk_path = NULL;
const char *stop_at;

self->source_date_epoch = builder_context_get_source_date_epoch (context);
Expand All @@ -1714,9 +1721,10 @@ builder_manifest_start (BuilderManifest *self,
builder_manifest_get_runtime_version (self),
self->sdk_commit);

sdk_path = flatpak_info_show_path (self->sdk, builder_manifest_get_runtime_version (self), context);
if (sdk_path != NULL &&
!builder_context_load_sdk_config (context, sdk_path, error))
g_free (self->sdk_path);
self->sdk_path = flatpak_info_show_path (self->sdk, builder_manifest_get_runtime_version (self), context);
if (self->sdk_path != NULL &&
!builder_context_load_sdk_config (context, self->sdk_path, error))
return FALSE;

self->runtime_commit = flatpak (NULL, "info", arch_option, "--show-commit", self->runtime,
Expand Down
1 change: 1 addition & 0 deletions src/builder-manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ char * builder_manifest_get_debug_id (BuilderManifest *self);
char * builder_manifest_get_sources_id (BuilderManifest *self);
const char * builder_manifest_get_id_platform (BuilderManifest *self);
char * builder_manifest_get_locale_id_platform (BuilderManifest *self);
const char * builder_manifest_get_sdk_path (BuilderManifest *self);
BuilderOptions *builder_manifest_get_build_options (BuilderManifest *self);
GList * builder_manifest_get_modules (BuilderManifest *self);
GList * builder_manifest_get_add_extensions (BuilderManifest *self);
Expand Down