builder: Add support for exporting with --repo=foo

tingping/wmclass
Alexander Larsson 2016-01-11 15:35:17 +01:00
parent e2b347ba76
commit 13d07d6a6f
5 changed files with 99 additions and 8 deletions

View File

@ -66,9 +66,14 @@ metadata_get_arch (GFile *file, char **out_arch, GError **error)
if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, error))
return FALSE;
runtime = g_key_file_get_string (keyfile, opt_runtime ? "Runtime" : "Application", "runtime", error);
if (*error)
return FALSE;
runtime = g_key_file_get_string (keyfile,
opt_runtime ? "Runtime" : "Application",
"runtime", NULL);
if (runtime == NULL)
{
*out_arch = g_strdup (xdg_app_get_arch ());
return TRUE;
}
parts = g_strsplit (runtime, "/", 0);
if (g_strv_length (parts) != 3)

View File

@ -250,10 +250,16 @@ builder_cache_checkout (BuilderCache *self, const char *commit)
return TRUE;
}
gboolean
builder_cache_has_checkout (BuilderCache *self)
{
return self->disabled;
}
void
builder_cache_ensure_checkout (BuilderCache *self)
{
if (self->disabled)
if (builder_cache_has_checkout (self))
return;
if (self->last_parent)
@ -263,6 +269,8 @@ builder_cache_ensure_checkout (BuilderCache *self)
if (!builder_cache_checkout (self, self->last_parent))
g_error ("Failed to check out cache");
}
self->disabled = TRUE;
}
gboolean

View File

@ -43,6 +43,7 @@ gboolean builder_cache_open (BuilderCache *self,
GChecksum * builder_cache_get_checksum (BuilderCache *self);
gboolean builder_cache_lookup (BuilderCache *self);
void builder_cache_ensure_checkout (BuilderCache *self);
gboolean builder_cache_has_checkout (BuilderCache *self);
gboolean builder_cache_commit (BuilderCache *self,
const char *body,
GError **error);

View File

@ -1119,12 +1119,30 @@ builder_manifest_finish (BuilderManifest *self,
if (g_file_query_exists (debuginfo_dir, NULL))
{
g_autoptr(GFile) metadata_file = NULL;
g_autoptr(GFile) metadata_debuginfo_file = NULL;
g_autofree char *metadata_contents = NULL;
g_autofree char *extension_contents = NULL;
g_autoptr(GFileOutputStream) output = NULL;
metadata_file = g_file_get_child (app_dir, "metadata");
metadata_debuginfo_file = g_file_get_child (app_dir, "metadata.debuginfo");
extension_contents = g_strdup_printf("\n"
"[Extension %s.Debug]\n"
"directory=lib/debug\n",
self->app_id);
output = g_file_append_to (metadata_file, G_FILE_CREATE_NONE, NULL, error);
if (output == NULL)
return FALSE;
if (!g_output_stream_write_all (G_OUTPUT_STREAM (output), extension_contents, strlen (extension_contents),
NULL, NULL, error))
return FALSE;
metadata_file = g_file_get_child (app_dir, "metadata.debuginfo");
metadata_contents = g_strdup_printf("[Runtime]\n"
"name=%s.Debug\n", self->app_id);
if (!g_file_replace_contents (metadata_file,
if (!g_file_replace_contents (metadata_debuginfo_file,
metadata_contents, strlen (metadata_contents), NULL, FALSE,
G_FILE_CREATE_REPLACE_DESTINATION,
NULL, NULL, error))

View File

@ -40,6 +40,7 @@ static gboolean opt_disable_download;
static gboolean opt_disable_updates;
static gboolean opt_require_changes;
static gboolean opt_keep_build_dirs;
static char *opt_repo;
static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
@ -49,8 +50,9 @@ static GOptionEntry entries[] = {
{ "disable-updates", 0, 0, G_OPTION_ARG_NONE, &opt_disable_updates, "Only download missing sources, never update to latest vcs version", NULL },
{ "download-only", 0, 0, G_OPTION_ARG_NONE, &opt_download_only, "Only download sources, don't build", NULL },
{ "build-only", 0, 0, G_OPTION_ARG_NONE, &opt_build_only, "Stop after build, don't run clean and finish phases", NULL },
{ "require-changes", 0, 0, G_OPTION_ARG_NONE, &opt_require_changes, "Don't create app dir if no changes", 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 },
{ "repo", 0, 0, G_OPTION_ARG_STRING, &opt_repo, "Repo to export into", "DIR"},
{ NULL }
};
@ -76,6 +78,40 @@ usage (GOptionContext *context, const char *message)
return 1;
}
static gboolean
do_export (GError **error,
...)
{
va_list ap;
const char *arg;
g_autoptr(GPtrArray) args = NULL;
g_autoptr(GSubprocess) subp = NULL;
args = g_ptr_array_new_with_free_func (g_free);
g_ptr_array_add (args, g_strdup ("xdg-app"));
g_ptr_array_add (args, g_strdup ("build-export"));
va_start (ap, error);
while ((arg = va_arg (ap, const gchar *)))
g_ptr_array_add (args, g_strdup ((gchar *) arg));
va_end (ap);
g_ptr_array_add (args, NULL);
subp =
g_subprocess_newv ((const gchar * const *) args->pdata,
G_SUBPROCESS_FLAGS_NONE,
error);
if (subp == NULL ||
!g_subprocess_wait_check (subp, NULL, error))
return FALSE;
return TRUE;
}
int
main (int argc,
char **argv)
@ -227,7 +263,30 @@ main (int argc,
}
if (!opt_require_changes)
builder_cache_ensure_checkout (cache);
{
builder_cache_ensure_checkout (cache);
}
if (opt_repo && builder_cache_has_checkout (cache))
{
g_autoptr(GFile) debuginfo_metadata = NULL;
if (!do_export (&error,"--exclude=/lib/debug/*", opt_repo, app_dir_path, NULL))
{
g_print ("Export failed: %s\n", error->message);
return 1;
}
debuginfo_metadata = g_file_get_child (app_dir, "metadata.debuginfo");
if (g_file_query_exists (debuginfo_metadata, NULL))
{
if (!do_export (&error, "--runtime", "--metadata=metadata.debuginfo", "--files=files/lib/debug", opt_repo, app_dir_path, NULL))
{
g_print ("Export failed: %s\n", error->message);
return 1;
}
}
}
if (!builder_gc (cache, &error))
{