Move to kernel style SPDX license identifiers
[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 ENABLE_DEBUG_INFO
16 # define BT_ENABLE_DEBUG_INFO 1
17 #else
18 # define BT_ENABLE_DEBUG_INFO 0
19 #endif
20
21 #ifdef BT_SET_DEFAULT_IN_TREE_CONFIGURATION
22
23 struct bt_config *bt_config_cli_args_create_with_default(int argc,
24 const char *argv[], int *retcode,
25 const bt_interrupter *interrupter)
26 {
27 bt_value *initial_plugin_paths;
28 struct bt_config *cfg = NULL;
29 int ret;
30
31 initial_plugin_paths = bt_value_array_create();
32 if (!initial_plugin_paths) {
33 goto error;
34 }
35
36 ret = bt_config_append_plugin_paths(initial_plugin_paths,
37 CONFIG_IN_TREE_PLUGIN_PATH);
38 if (ret) {
39 goto error;
40 }
41
42 #ifdef CONFIG_IN_TREE_PROVIDER_DIR
43 /*
44 * Set LIBBABELTRACE2_PLUGIN_PROVIDER_DIR to load the in-tree Python
45 * plugin provider, if the env variable is already set, do not overwrite
46 * it.
47 */
48 g_setenv("LIBBABELTRACE2_PLUGIN_PROVIDER_DIR", CONFIG_IN_TREE_PROVIDER_DIR, 0);
49 #else
50 /*
51 * If the Pyhton plugin provider is disabled, use a non-exitent path to avoid
52 * loading the system installed provider if it exit, if the env variable is
53 * already set, do not overwrite it.
54 */
55 g_setenv("LIBBABELTRACE2_PLUGIN_PROVIDER_DIR", "/nonexistent", 0);
56 #endif
57
58 cfg = bt_config_cli_args_create(argc, argv, retcode, true, true,
59 initial_plugin_paths, interrupter);
60 goto end;
61
62 error:
63 *retcode = 1;
64 BT_OBJECT_PUT_REF_AND_RESET(cfg);
65
66 end:
67 bt_value_put_ref(initial_plugin_paths);
68 return cfg;
69 }
70
71 #else /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */
72
73 struct bt_config *bt_config_cli_args_create_with_default(int argc,
74 const char *argv[], int *retcode,
75 const bt_interrupter *interrupter)
76 {
77 return bt_config_cli_args_create(argc, argv, retcode, false, false,
78 NULL, interrupter);
79 }
80
81 #endif /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */
This page took 0.029992 seconds and 4 git commands to generate.