From c1870f576149d488615883a7cfd12eddf78bd46a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 16 Jan 2017 20:07:33 -0500 Subject: [PATCH] Generate a binary looking for in-tree plug-ins MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- configure.ac | 2 +- converter/Makefile.am | 15 ++++-- converter/babeltrace-cfg.c | 97 ++++++++++++++++++-------------------- converter/babeltrace-cfg.h | 7 ++- converter/babeltrace.c | 17 ++++++- converter/babeltrace.in | 5 -- converter/default-cfg.c | 54 +++++++++++++++++++++ converter/default-cfg.h | 32 +++++++++++++ 8 files changed, 167 insertions(+), 62 deletions(-) delete mode 100755 converter/babeltrace.in create mode 100644 converter/default-cfg.c create mode 100644 converter/default-cfg.h diff --git a/configure.ac b/configure.ac index 4d1cbeed..4adacc0b 100644 --- a/configure.ac +++ b/configure.ac @@ -432,7 +432,7 @@ AC_CONFIG_FILES([ babeltrace-ctf.pc ]) -AC_CONFIG_FILES([converter/babeltrace], [chmod +x converter/babeltrace]) +#AC_CONFIG_FILES([converter/babeltrace], [chmod +x converter/babeltrace]) AC_CONFIG_FILES([tests/lib/test_ctf_writer_complete], [chmod +x tests/lib/test_ctf_writer_complete]) AC_CONFIG_FILES([tests/lib/test_seek_big_trace], [chmod +x tests/lib/test_seek_big_trace]) AC_CONFIG_FILES([tests/lib/test_seek_empty_packet], [chmod +x tests/lib/test_seek_empty_packet]) diff --git a/converter/Makefile.am b/converter/Makefile.am index e6c8dac8..6c8db944 100644 --- a/converter/Makefile.am +++ b/converter/Makefile.am @@ -1,13 +1,18 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include \ - -DINSTALL_LIBDIR=\"$(libdir)\" + -DINSTALL_LIBDIR=\"$(libdir)\" \ + -DCONFIG_IN_TREE_PLUGIN_DIR=\"$(abs_top_builddir)/plugins/\" AM_LDFLAGS = -lpopt bin_PROGRAMS = babeltrace.bin babeltrace-log +noinst_PROGRAMS = babeltrace +#check_PROGRAMS = babeltrace babeltrace_bin_SOURCES = \ babeltrace.c \ babeltrace-cfg.c \ - babeltrace-cfg.h + babeltrace-cfg.h \ + default-cfg.h \ + default-cfg.c # -Wl,--no-as-needed is needed for recent gold linker who seems to think # it knows better and considers libraries with constructors having @@ -49,4 +54,8 @@ babeltrace_log_LDADD += -lrpcrt4 -lintl -liconv -lole32 -lpopt -lpthread babeltrace_bin_LDADD += -lrpcrt4 -lintl -liconv -lole32 -lpopt -lpthread endif -check_SCRIPTS = babeltrace +# Only used for in-tree execution and tests +babeltrace_SOURCES = $(babeltrace_bin_SOURCES) +babeltrace_LDFLAGS = $(babeltrace_bin_LDFLAGS) +babeltrace_LDADD = $(babeltrace_bin_LDADD) +babeltrace_CFLAGS = $(AM_CFLAGS) -DBT_SET_DEFAULT_IN_TREE_CONFIGURATION diff --git a/converter/babeltrace-cfg.c b/converter/babeltrace-cfg.c index 5b9c838f..8b3eebcf 100644 --- a/converter/babeltrace-cfg.c +++ b/converter/babeltrace-cfg.c @@ -148,9 +148,6 @@ enum legacy_output_format { LEGACY_OUTPUT_FORMAT_DUMMY, }; -static bool omit_system_plugin_path; -static bool omit_home_plugin_path; - /* * Prints the "out of memory" error. */ @@ -2287,7 +2284,7 @@ end: static int add_internal_plugin_paths(struct bt_config *cfg) { - if (!omit_home_plugin_path) { + if (!cfg->omit_home_plugin_path) { char path[PATH_MAX]; const char *home_dir; @@ -2311,7 +2308,7 @@ static int add_internal_plugin_paths(struct bt_config *cfg) } } - if (!omit_system_plugin_path) { + if (!cfg->omit_system_plugin_path) { if (plugin_paths_from_arg(cfg->plugin_paths, SYSTEM_PLUGIN_PATH)) { printf_err("Invalid system plugin path\n"); @@ -2347,19 +2344,51 @@ error: return -1; } +struct bt_config *bt_config_create(void) +{ + struct bt_config *cfg; + + /* Create config */ + cfg = g_new0(struct bt_config, 1); + if (!cfg) { + print_err_oom(); + goto error; + } + + bt_object_init(cfg, bt_config_destroy); + cfg->sources = g_ptr_array_new_with_free_func((GDestroyNotify) bt_put); + if (!cfg->sources) { + print_err_oom(); + goto error; + } + + cfg->sinks = g_ptr_array_new_with_free_func((GDestroyNotify) bt_put); + if (!cfg->sinks) { + print_err_oom(); + goto error; + } + + cfg->plugin_paths = bt_value_array_create(); + if (!cfg->plugin_paths) { + print_err_oom(); + goto error; + } +end: + return cfg; +error: + BT_PUT(cfg); + goto end; +} + /* * Returns a Babeltrace configuration, out of command-line arguments, * containing everything that is needed to instanciate specific * components with given parameters. * - * *exit_code is set to the appropriate exit code to use as far as this - * function goes. - * - * Return value is NULL on error, otherwise it's owned by the caller. + * Return value is set to the appropriate exit code to use. */ -struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_code) +int bt_config_init_from_args(struct bt_config *cfg, int argc, const char *argv[]) { - struct bt_config *cfg = NULL; poptContext pc = NULL; char *arg = NULL; struct ctf_legacy_opts ctf_legacy_opts; @@ -2375,11 +2404,10 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_co enum bt_config_component_dest cur_cfg_comp_dest = BT_CONFIG_COMPONENT_DEST_SOURCE; struct bt_value *cur_base_params = NULL; - int opt, nr_omit_opt = 0; + int opt, ret = 0; memset(&ctf_legacy_opts, 0, sizeof(ctf_legacy_opts)); memset(&text_legacy_opts, 0, sizeof(text_legacy_opts)); - *exit_code = 0; text_legacy_opts.output = g_string_new(NULL); if (!text_legacy_opts.output) { @@ -2405,26 +2433,6 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_co goto error; } - /* Create config */ - cfg = g_new0(struct bt_config, 1); - if (!cfg) { - print_err_oom(); - goto error; - } - - bt_object_init(cfg, bt_config_destroy); - cfg->sources = g_ptr_array_new_with_free_func((GDestroyNotify) bt_put); - if (!cfg->sources) { - print_err_oom(); - goto error; - } - - cfg->sinks = g_ptr_array_new_with_free_func((GDestroyNotify) bt_put); - if (!cfg->sinks) { - print_err_oom(); - goto error; - } - legacy_input_paths = bt_value_array_create(); if (!legacy_input_paths) { print_err_oom(); @@ -2442,12 +2450,6 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_co DEFAULT_SOURCE_COMPONENT_NAME); } - cfg->plugin_paths = bt_value_array_create(); - if (!cfg->plugin_paths) { - print_err_oom(); - goto error; - } - /* Parse options */ pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 0); if (!pc) { @@ -2472,12 +2474,10 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_co } break; case OPT_OMIT_SYSTEM_PLUGIN_PATH: - omit_system_plugin_path = true; - nr_omit_opt += 2; + cfg->omit_system_plugin_path = true; break; case OPT_OMIT_HOME_PLUGIN_PATH: - omit_home_plugin_path = true; - nr_omit_opt += 2; + cfg->omit_home_plugin_path = true; break; case OPT_OUTPUT_PATH: if (text_legacy_opts.output->len > 0) { @@ -2859,9 +2859,9 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_co arg = NULL; } - if (argc - nr_omit_opt <= 1) { + if (argc <= 1) { print_usage(stdout); - goto put_cfg; + goto end; } /* Check for option parsing error */ @@ -2962,10 +2962,7 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_co goto end; error: - *exit_code = 1; -put_cfg: - BT_PUT(cfg); - cfg = NULL; + ret = 1; end: if (pc) { poptFreeContext(pc); @@ -2990,5 +2987,5 @@ end: BT_PUT(text_legacy_opts.names); BT_PUT(text_legacy_opts.fields); BT_PUT(legacy_input_paths); - return cfg; + return ret; } diff --git a/converter/babeltrace-cfg.h b/converter/babeltrace-cfg.h index fea844c5..fe385a20 100644 --- a/converter/babeltrace-cfg.h +++ b/converter/babeltrace-cfg.h @@ -54,6 +54,8 @@ struct bt_config { bool verbose; bool do_list; bool force_correlate; + bool omit_system_plugin_path; + bool omit_home_plugin_path; }; static inline @@ -63,6 +65,9 @@ struct bt_config_component *bt_config_get_component(GPtrArray *array, return bt_get(g_ptr_array_index(array, index)); } -struct bt_config *bt_config_from_args(int argc, const char *argv[], int *exit_code); +struct bt_config *bt_config_create(void); + +int bt_config_init_from_args(struct bt_config *cfg, int argc, + const char *argv[]); #endif /* BABELTRACE_CONVERTER_CFG_H */ diff --git a/converter/babeltrace.c b/converter/babeltrace.c index f969f8d7..42a4f308 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -39,6 +39,7 @@ #include #include #include "babeltrace-cfg.h" +#include "default-cfg.h" static struct bt_component_factory *component_factory; @@ -408,8 +409,20 @@ int main(int argc, const char **argv) enum bt_component_status sink_status; struct bt_config_component *source_cfg = NULL, *sink_cfg = NULL; - cfg = bt_config_from_args(argc, argv, &ret); - if (cfg) { + cfg = bt_config_create(); + if (!cfg) { + fprintf(stderr, "Failed to create Babeltrace configuration\n"); + ret = 1; + goto end; + } + + ret = set_default_config(cfg); + if (ret) { + goto end; + } + + ret = bt_config_init_from_args(cfg, argc, argv); + if (ret == 0) { print_cfg(cfg); } else { goto end; diff --git a/converter/babeltrace.in b/converter/babeltrace.in deleted file mode 100755 index ad99787e..00000000 --- a/converter/babeltrace.in +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -@abs_top_builddir@/converter/babeltrace.bin \ - --omit-system-plugin-path --omit-home-plugin-path \ - --plugin-path "@abs_top_builddir@/plugins" ${*} diff --git a/converter/default-cfg.c b/converter/default-cfg.c new file mode 100644 index 00000000..b4cd7051 --- /dev/null +++ b/converter/default-cfg.c @@ -0,0 +1,54 @@ +/* + * default-cfg.c + * + * Babeltrace Trace Converter - Default Configuration + * + * Copyright 2016 - Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "default-cfg.h" +#include "config.h" + +#ifdef BT_SET_DEFAULT_IN_TREE_CONFIGURATION + +int set_default_config(struct bt_config *cfg) +{ + int ret; + + cfg->omit_system_plugin_path = true; + cfg->omit_home_plugin_path = true; + ret = bt_value_array_append_string(cfg->plugin_paths, + CONFIG_IN_TREE_PLUGIN_DIR); + return ret; +} + +#else /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */ + +int set_default_config(struct bt_config *cfg) +{ + /* Nothing to set. */ + return 0; +} + +#endif /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */ diff --git a/converter/default-cfg.h b/converter/default-cfg.h new file mode 100644 index 00000000..9d9cd6bf --- /dev/null +++ b/converter/default-cfg.h @@ -0,0 +1,32 @@ +#ifndef BABELTRACE_DEFAULT_CFG_H +#define BABELTRACE_DEFAULT_CFG_H + +/* + * Babeltrace Trace Converter - Default Configuration + * + * Copyright 2016 Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "babeltrace-cfg.h" + +int set_default_config(struct bt_config *cfg); + +#endif /* BABELTRACE_DEFAULT_CFG_H */ -- 2.34.1