Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for external dir hasher #575

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
46 changes: 45 additions & 1 deletion src/builder-source-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct BuilderSourceDir
{
BuilderSource parent;

char **hash_cmd;
char *path;
char **skip;
};
Expand All @@ -49,6 +50,7 @@ G_DEFINE_TYPE (BuilderSourceDir, builder_source_dir, BUILDER_TYPE_SOURCE);

enum {
PROP_0,
PROP_HASH_CMD,
PROP_PATH,
PROP_SKIP,
LAST_PROP
Expand All @@ -75,6 +77,10 @@ builder_source_dir_get_property (GObject *object,

switch (prop_id)
{
case PROP_HASH_CMD:
g_value_set_boxed (value, self->hash_cmd);
break;

case PROP_PATH:
g_value_set_string (value, self->path);
break;
Expand All @@ -99,6 +105,12 @@ builder_source_dir_set_property (GObject *object,

switch (prop_id)
{
case PROP_HASH_CMD:
tmp = self->hash_cmd;
self->hash_cmd = g_strdupv (g_value_get_boxed (value));
g_strfreev (tmp);
break;

case PROP_PATH:
g_free (self->path);
self->path = g_value_dup_string (value);
Expand Down Expand Up @@ -266,12 +278,36 @@ builder_source_dir_update (BuilderSource *source,
return TRUE;
}

static GError*
builder_source_dir_external_hash_from_cmd(BuilderSourceDir *self,
BuilderCache *cache)
{
GError *error = NULL;
gchar *stdout_output = NULL;
if (!g_spawn_sync(NULL, self->hash_cmd, NULL, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_SEARCH_PATH, NULL, NULL, &stdout_output, NULL, NULL, &error)) {
return error;
}
builder_cache_checksum_data(cache, stdout_output, strlen(stdout_output) + 1);
g_free (stdout_output);
return NULL;
}

static void
builder_source_dir_checksum (BuilderSource *source,
BuilderCache *cache,
BuilderContext *context)
{
/* We can't realistically checksum a directory, so always rebuild */
BuilderSourceDir *self = BUILDER_SOURCE_DIR (source);
if (self->hash_cmd) {
GError* error = builder_source_dir_external_hash_from_cmd(self, cache);
if (!error)
return;

g_error_free(error);
}

/* Checksumming a directory is a non-trivial pursuit. We currently opt to not integrate into flatpak directly
and rather always rebuild */
builder_cache_checksum_random (cache);
}

Expand All @@ -292,6 +328,14 @@ builder_source_dir_class_init (BuilderSourceDirClass *klass)
source_class->update = builder_source_dir_update;
source_class->checksum = builder_source_dir_checksum;

g_object_class_install_property (object_class,
PROP_HASH_CMD,
g_param_spec_boxed ("hash-cmd",
"",
"",
G_TYPE_STRV,
G_PARAM_READWRITE));

g_object_class_install_property (object_class,
PROP_PATH,
g_param_spec_string ("path",
Expand Down