e75b187178ee18d76a69bf5a857a6f205b1f3700
[babeltrace.git] / src / cli / babeltrace2-cfg-cli-args-default.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
6 */
7
8 #include <glib.h>
9
10 #include <babeltrace2/babeltrace.h>
11 #include "babeltrace2-cfg.h"
12 #include "babeltrace2-cfg-cli-args.h"
13 #include "babeltrace2-cfg-cli-args-default.h"
14
15 #ifdef BT_SET_DEFAULT_IN_TREE_CONFIGURATION
16
17 struct bt_config *bt_config_cli_args_create_with_default(int argc,
18 const char *argv[], int *retcode,
19 const bt_interrupter *interrupter)
20 {
21 bt_value *initial_plugin_paths;
22 struct bt_config *cfg = NULL;
23 int ret;
24
25 initial_plugin_paths = bt_value_array_create();
26 if (!initial_plugin_paths) {
27 goto error;
28 }
29
30 ret = bt_config_append_plugin_paths(initial_plugin_paths,
31 CONFIG_IN_TREE_PLUGIN_PATH);
32 if (ret) {
33 goto error;
34 }
35
36 #ifdef CONFIG_IN_TREE_PROVIDER_DIR
37 /*
38 * Set LIBBABELTRACE2_PLUGIN_PROVIDER_DIR to load the in-tree Python
39 * plugin provider, if the env variable is already set, do not overwrite
40 * it.
41 */
42 g_setenv("LIBBABELTRACE2_PLUGIN_PROVIDER_DIR", CONFIG_IN_TREE_PROVIDER_DIR, 0);
43 #else
44 /*
45 * If the Pyhton plugin provider is disabled, use a non-exitent path to avoid
46 * loading the system installed provider if it exit, if the env variable is
47 * already set, do not overwrite it.
48 */
49 g_setenv("LIBBABELTRACE2_PLUGIN_PROVIDER_DIR", "/nonexistent", 0);
50 #endif
51
52 cfg = bt_config_cli_args_create(argc, argv, retcode, true, true,
53 initial_plugin_paths, interrupter);
54 goto end;
55
56 error:
57 *retcode = 1;
58 BT_OBJECT_PUT_REF_AND_RESET(cfg);
59
60 end:
61 bt_value_put_ref(initial_plugin_paths);
62 return cfg;
63 }
64
65 #else /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */
66
67 struct bt_config *bt_config_cli_args_create_with_default(int argc,
68 const char *argv[], int *retcode,
69 const bt_interrupter *interrupter)
70 {
71 return bt_config_cli_args_create(argc, argv, retcode, false, false,
72 NULL, interrupter);
73 }
74
75 #endif /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */
This page took 0.033574 seconds and 3 git commands to generate.