Generate a binary looking for in-tree plug-ins
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 17 Jan 2017 01:07:33 +0000 (20:07 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:08 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
converter/Makefile.am
converter/babeltrace-cfg.c
converter/babeltrace-cfg.h
converter/babeltrace.c
converter/babeltrace.in [deleted file]
converter/default-cfg.c [new file with mode: 0644]
converter/default-cfg.h [new file with mode: 0644]

index 4d1cbeed29908f12cc8db1d67bdcecb7415781d8..4adacc0be227e3e872623d1060cbaca04733e36b 100644 (file)
@@ -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])
index e6c8dac8a88ddb205031570fc604c886b9999b57..6c8db944ab0923f0dd33f6b0520fbb066a605745 100644 (file)
@@ -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
index 5b9c838f599b78a6e4f868b29db115a7b2c01f58..8b3eebcfa262a2922982d34d969f8fb342e08095 100644 (file)
@@ -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;
 }
index fea844c52865c982eb9bf752538c576d56e7a22c..fe385a2083511e53a440012a72970c5434e24892 100644 (file)
@@ -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 */
index f969f8d73cc0d728ea4d373d932d820d3b0b2b22..42a4f3088a8dc57d69bbbaf1095b792fbafeca54 100644 (file)
@@ -39,6 +39,7 @@
 #include <string.h>
 #include <stdio.h>
 #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 (executable)
index ad99787..0000000
+++ /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 (file)
index 0000000..b4cd705
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * default-cfg.c
+ *
+ * Babeltrace Trace Converter - Default Configuration
+ *
+ * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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/values.h>
+#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 (file)
index 0000000..9d9cd6b
--- /dev/null
@@ -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 <jeremie.galarneau@efficios.com>
+ *
+ * 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 */
This page took 0.031496 seconds and 4 git commands to generate.