mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-26 01:19:34 -04:00
builder: Add support for --run to start a command in the build dir
This commit is contained in:
1 parent
c07b1807d1
commit
6c5feb4e05
4 files changed
+125
-7
No files matched your search
@@ -1758,3 +1758,83 @@ builder_manifest_create_platform (BuilderManifest *self,
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
builder_manifest_run (BuilderManifest *self,
|
||||
BuilderContext *context,
|
||||
char **argv,
|
||||
int argc,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GSubprocessLauncher) launcher = NULL;
|
||||
g_autoptr(GSubprocess) subp = NULL;
|
||||
g_autoptr(GPtrArray) args = NULL;
|
||||
g_autofree char *commandline = NULL;
|
||||
g_autofree char *build_dir_path = NULL;
|
||||
g_autofree char *ccache_dir_path = NULL;
|
||||
g_auto(GStrv) env = NULL;
|
||||
g_auto(GStrv) build_args = NULL;
|
||||
int i;
|
||||
|
||||
if (!gs_file_ensure_directory (builder_context_get_build_dir (context), TRUE,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
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"));
|
||||
|
||||
build_dir_path = g_file_get_path (builder_context_get_build_dir (context));
|
||||
g_ptr_array_add (args, g_strdup_printf ("--bind-mount=/run/build=%s", build_dir_path));
|
||||
|
||||
if (g_file_query_exists (builder_context_get_ccache_dir (context), NULL))
|
||||
{
|
||||
ccache_dir_path = g_file_get_path (builder_context_get_ccache_dir (context));
|
||||
g_ptr_array_add (args, g_strdup_printf ("--bind-mount=/run/ccache=%s", ccache_dir_path));
|
||||
}
|
||||
|
||||
build_args = builder_options_get_build_args (self->build_options, context);
|
||||
|
||||
if (build_args)
|
||||
{
|
||||
for (i = 0; build_args[i] != NULL; i++)
|
||||
g_ptr_array_add (args, g_strdup (build_args[i]));
|
||||
}
|
||||
|
||||
env = builder_options_get_env (self->build_options, context);
|
||||
if (env)
|
||||
{
|
||||
for (i = 0; env[i] != NULL; i++)
|
||||
g_ptr_array_add (args, g_strdup_printf ("--env=%s", env[i]));
|
||||
}
|
||||
|
||||
/* Inherit all finish args except the filesystem ones so the
|
||||
* command gets the same access as the final app */
|
||||
if (self->finish_args)
|
||||
{
|
||||
for (i = 0; self->finish_args[i] != NULL; i++)
|
||||
{
|
||||
const char *arg = self->finish_args[i];
|
||||
if (!g_str_has_prefix (arg, "--filesystem"))
|
||||
g_ptr_array_add (args, g_strdup (arg));
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_add (args, g_file_get_path (builder_context_get_app_dir (context)));
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
g_ptr_array_add (args, g_strdup (argv[i]));
|
||||
g_ptr_array_add (args, NULL);
|
||||
|
||||
commandline = g_strjoinv (" ", (char **) args->pdata);
|
||||
|
||||
if (!execvp ((char *)args->pdata[0], (char **)args->pdata))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Unable to start xdg-app build");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Not reached */
|
||||
return TRUE;
|
||||
}
|
||||
@@ -62,6 +62,11 @@ gboolean builder_manifest_build (BuilderManifest *self,
|
||||
BuilderCache *cache,
|
||||
BuilderContext *context,
|
||||
GError **error);
|
||||
gboolean builder_manifest_run (BuilderManifest *self,
|
||||
BuilderContext *context,
|
||||
char **argv,
|
||||
int argc,
|
||||
GError **error);
|
||||
void builder_manifest_checksum (BuilderManifest *self,
|
||||
BuilderCache *cache,
|
||||
BuilderContext *context);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
static gboolean opt_verbose;
|
||||
static gboolean opt_version;
|
||||
static gboolean opt_run;
|
||||
static gboolean opt_disable_cache;
|
||||
static gboolean opt_download_only;
|
||||
static gboolean opt_build_only;
|
||||
@@ -51,6 +52,7 @@ static char **opt_key_ids;
|
||||
static GOptionEntry entries[] = {
|
||||
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
|
||||
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL },
|
||||
{ "run", 0, 0, G_OPTION_ARG_NONE, &opt_run, "Run a command in the build directory", NULL },
|
||||
{ "ccache", 0, 0, G_OPTION_ARG_NONE, &opt_ccache, "Use ccache", NULL },
|
||||
{ "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Disable cache", NULL },
|
||||
{ "disable-download", 0, 0, G_OPTION_ARG_NONE, &opt_disable_download, "Don't download any new sources", NULL },
|
||||
@@ -216,13 +218,6 @@ main (int argc,
|
||||
base_dir = g_file_new_for_path (g_get_current_dir ());
|
||||
app_dir = g_file_new_for_path (app_dir_path);
|
||||
|
||||
if (g_file_query_exists (app_dir, NULL) && !directory_is_empty (app_dir_path))
|
||||
{
|
||||
g_printerr ("App dir '%s' is not empty. Please delete "
|
||||
"the existing contents.\n", app_dir_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
build_context = builder_context_new (base_dir, app_dir);
|
||||
|
||||
builder_context_set_keep_build_dirs (build_context, opt_keep_build_dirs);
|
||||
@@ -234,6 +229,34 @@ main (int argc,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (opt_run)
|
||||
{
|
||||
if (argc == 3)
|
||||
return usage (context, "Program to run must be specified");
|
||||
|
||||
if (!g_file_query_exists (app_dir, NULL) ||
|
||||
directory_is_empty (app_dir_path))
|
||||
{
|
||||
g_printerr ("App dir '%s' is empty or doesn't exist.\n", app_dir_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!builder_manifest_run (manifest, build_context, argv + 3, argc - 3, &error))
|
||||
{
|
||||
g_printerr ("Error running %s: %s\n", argv[3], error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_file_query_exists (app_dir, NULL) && !directory_is_empty (app_dir_path))
|
||||
{
|
||||
g_printerr ("App dir '%s' is not empty. Please delete "
|
||||
"the existing contents.\n", app_dir_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!builder_manifest_start (manifest, build_context, &error))
|
||||
{
|
||||
g_print ("Failed to init: %s\n", error->message);
|
||||
|
||||
@@ -532,6 +532,16 @@
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--run</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Run a command in a sandbox based on the build dir. This starts xdg-app build, with some extra
|
||||
arguments to give the same environment as the build, and the same permissions the final app
|
||||
will have.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--download-only</option></term>
|
||||
|
||||
|
||||
Reference in new issue
Block a user