2015-03-23 11:17:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2014-12-18 16:51:37 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdlib.h>
|
2014-12-18 19:33:41 +00:00
|
|
|
#include <string.h>
|
2014-12-18 16:51:37 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2015-03-20 15:21:19 +00:00
|
|
|
#include <string.h>
|
2014-12-18 16:51:37 +00:00
|
|
|
|
|
|
|
#include "libgsystem.h"
|
2015-03-20 15:21:19 +00:00
|
|
|
#include "libglnx/libglnx.h"
|
2014-12-18 16:51:37 +00:00
|
|
|
|
|
|
|
#include "xdg-app-builtins.h"
|
|
|
|
#include "xdg-app-utils.h"
|
2015-01-27 21:33:51 +00:00
|
|
|
#include "xdg-app-dbus.h"
|
2015-02-13 09:29:41 +00:00
|
|
|
#include "xdg-app-run.h"
|
2014-12-18 16:51:37 +00:00
|
|
|
|
|
|
|
static char *opt_arch;
|
|
|
|
static char *opt_branch;
|
2014-12-18 19:45:55 +00:00
|
|
|
static char *opt_command;
|
2014-12-18 19:53:35 +00:00
|
|
|
static gboolean opt_devel;
|
2015-02-06 11:08:51 +00:00
|
|
|
static char *opt_runtime;
|
2016-01-12 08:57:20 +00:00
|
|
|
static char *opt_runtime_version;
|
2014-12-18 16:51:37 +00:00
|
|
|
|
|
|
|
static GOptionEntry options[] = {
|
2015-01-14 05:40:21 +00:00
|
|
|
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Arch to use", "ARCH" },
|
|
|
|
{ "command", 0, 0, G_OPTION_ARG_STRING, &opt_command, "Command to run", "COMMAND" },
|
2015-01-14 23:09:21 +00:00
|
|
|
{ "branch", 0, 0, G_OPTION_ARG_STRING, &opt_branch, "Branch to use", "BRANCH" },
|
2015-01-08 16:50:54 +00:00
|
|
|
{ "devel", 'd', 0, G_OPTION_ARG_NONE, &opt_devel, "Use development runtime", NULL },
|
2015-02-06 11:08:51 +00:00
|
|
|
{ "runtime", 0, 0, G_OPTION_ARG_STRING, &opt_runtime, "Runtime to use", "RUNTIME" },
|
2016-01-12 08:57:20 +00:00
|
|
|
{ "runtime-version", 0, 0, G_OPTION_ARG_STRING, &opt_runtime_version, "Runtime version to use", "VERSION" },
|
2014-12-18 16:51:37 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **error)
|
|
|
|
{
|
2015-09-28 14:40:19 +00:00
|
|
|
g_autoptr(GOptionContext) context = NULL;
|
2015-05-12 09:03:36 +00:00
|
|
|
g_autoptr(XdgAppDeploy) app_deploy = NULL;
|
2015-03-20 15:21:19 +00:00
|
|
|
g_autofree char *app_ref = NULL;
|
2014-12-18 16:51:37 +00:00
|
|
|
const char *app;
|
|
|
|
const char *branch = "master";
|
|
|
|
int i;
|
2014-12-18 20:49:49 +00:00
|
|
|
int rest_argv_start, rest_argc;
|
2015-05-22 14:55:45 +00:00
|
|
|
g_autoptr(XdgAppContext) arg_context = NULL;
|
2014-12-18 16:51:37 +00:00
|
|
|
|
2014-12-18 19:45:55 +00:00
|
|
|
context = g_option_context_new ("APP [args...] - Run an app");
|
2014-12-18 16:51:37 +00:00
|
|
|
|
2014-12-18 20:49:49 +00:00
|
|
|
rest_argc = 0;
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
/* The non-option is the command, take it out of the arguments */
|
|
|
|
if (argv[i][0] != '-')
|
|
|
|
{
|
|
|
|
rest_argv_start = i;
|
|
|
|
rest_argc = argc - i;
|
|
|
|
argc = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 16:51:37 +00:00
|
|
|
|
2015-05-22 14:55:45 +00:00
|
|
|
arg_context = xdg_app_context_new ();
|
|
|
|
g_option_context_add_group (context, xdg_app_context_get_options (arg_context));
|
|
|
|
|
2015-01-14 00:54:19 +00:00
|
|
|
if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2015-01-14 00:54:19 +00:00
|
|
|
|
2014-12-18 20:49:49 +00:00
|
|
|
if (rest_argc == 0)
|
2015-09-28 14:40:19 +00:00
|
|
|
return usage_error (context, "APP must be specified", error);
|
2014-12-18 16:51:37 +00:00
|
|
|
|
2014-12-18 20:49:49 +00:00
|
|
|
app = argv[rest_argv_start];
|
2014-12-18 16:51:37 +00:00
|
|
|
|
|
|
|
if (opt_branch)
|
|
|
|
branch = opt_branch;
|
|
|
|
|
2015-12-15 13:58:12 +00:00
|
|
|
app_ref = xdg_app_compose_ref (TRUE, app, branch, opt_arch, error);
|
|
|
|
if (app_ref == NULL)
|
|
|
|
return FALSE;
|
2014-12-18 16:51:37 +00:00
|
|
|
|
2015-05-12 09:03:36 +00:00
|
|
|
app_deploy = xdg_app_find_deploy_for_ref (app_ref, cancellable, error);
|
2014-12-18 16:51:37 +00:00
|
|
|
if (app_deploy == NULL)
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 16:51:37 +00:00
|
|
|
|
2015-12-07 11:27:53 +00:00
|
|
|
if (!xdg_app_run_app (app_ref, app_deploy,
|
|
|
|
arg_context,
|
|
|
|
opt_runtime,
|
2016-01-12 08:57:20 +00:00
|
|
|
opt_runtime_version,
|
2015-12-07 11:27:53 +00:00
|
|
|
opt_devel ? XDG_APP_RUN_FLAG_DEVEL : 0,
|
|
|
|
opt_command,
|
|
|
|
&argv[rest_argv_start + 1],
|
|
|
|
rest_argc - 1,
|
|
|
|
cancellable,
|
|
|
|
error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 16:51:37 +00:00
|
|
|
|
|
|
|
/* Not actually reached... */
|
2015-09-28 14:40:19 +00:00
|
|
|
return TRUE;
|
2014-12-18 16:51:37 +00:00
|
|
|
}
|