From 09fc237ba2de4aa08993dc3131cea86f3c7e1c57 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 8 Apr 2019 12:53:56 -0400 Subject: [PATCH] python-plugin-provider: Make it build This patch fixes building with --enable-python-plugins. One problem is that the python plugin provider uses some functions coming from the internal headers of the lib, which use some logging functions that are internal to the lib, but not included by those internal headers. Trying to add the relevant include file (lib-logging-internal.h) conflicts with python-plugin-provider's own logger. python-plugin-provider doesn't really need to have its own logger. Even though it is built as a separate shared object (so that we can package it separately), it can be considered as internal to the library (and that's why it includes some internal lib headers). Therefore, the easiest way to fix this is to get rid of its logger and make the lib header files that use lib logging include the required header file (lib-logging-internal.h). This requires the python-plugin-provider shared object to access a few additional symbols not currently exposed by libbabeltrace, which requires the removal of a few BT_HIDDEN. I have also included fixes to the python-plugin-provider which I have on hand. However, it won't work until the Python bindings are up and running, so I have marked it as skipped. Change-Id: I9b46d91fc635d670fef2e4d3c8b32203ec34443f Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/1101 Reviewed-by: Philippe Proulx --- configure.ac | 1 + include/babeltrace/lib-logging-internal.h | 2 +- include/babeltrace/plugin/plugin-internal.h | 1 + .../babeltrace/plugin/plugin-so-internal.h | 1 - lib/lib-logging.c | 1 - lib/plugin/plugin-so.c | 1 - python-plugin-provider/Makefile.am | 2 +- python-plugin-provider/logging.c | 27 --------------- python-plugin-provider/logging.h | 31 ----------------- .../python-plugin-provider.c | 9 ++--- tests/python-plugin-provider/.gitignore | 1 + .../bt_plugin_test_python_plugin_provider.py | 6 ++-- .../test_python_plugin_provider.py | 4 ++- .../test_python_plugin_provider_env.in | 34 +++++++++++++++++++ 14 files changed, 48 insertions(+), 73 deletions(-) delete mode 100644 python-plugin-provider/logging.c delete mode 100644 python-plugin-provider/logging.h create mode 100644 tests/python-plugin-provider/test_python_plugin_provider_env.in diff --git a/configure.ac b/configure.ac index 5950c670..d23373bb 100644 --- a/configure.ac +++ b/configure.ac @@ -815,6 +815,7 @@ AS_IF([test "x$enable_python_bindings" = xyes], AS_IF([test "x$enable_python_plugins" = "xyes"], [AC_CONFIG_FILES([tests/python-plugin-provider/test_python_plugin_provider], [chmod +x tests/python-plugin-provider/test_python_plugin_provider])] + [AC_CONFIG_FILES([tests/python-plugin-provider/test_python_plugin_provider_env], [chmod +x tests/python-plugin-provider/test_python_plugin_provider_env])] ) AC_OUTPUT diff --git a/include/babeltrace/lib-logging-internal.h b/include/babeltrace/lib-logging-internal.h index ec8ce7f2..ae7fb9e6 100644 --- a/include/babeltrace/lib-logging-internal.h +++ b/include/babeltrace/lib-logging-internal.h @@ -186,7 +186,7 @@ int bt_lib_log_level; * Use one of the BT_LIB_LOGF*() macros above instead of calling this * function directly. */ -BT_HIDDEN + void bt_lib_log(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...); diff --git a/include/babeltrace/plugin/plugin-internal.h b/include/babeltrace/plugin/plugin-internal.h index 763a68b2..781c4ef3 100644 --- a/include/babeltrace/plugin/plugin-internal.h +++ b/include/babeltrace/plugin/plugin-internal.h @@ -32,6 +32,7 @@ #include #include #include +#include #include enum bt_plugin_type { diff --git a/include/babeltrace/plugin/plugin-so-internal.h b/include/babeltrace/plugin/plugin-so-internal.h index 41544d18..fb41e659 100644 --- a/include/babeltrace/plugin/plugin-so-internal.h +++ b/include/babeltrace/plugin/plugin-so-internal.h @@ -57,7 +57,6 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path); BT_HIDDEN struct bt_plugin_set *bt_plugin_so_create_all_from_static(void); -BT_HIDDEN void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, struct bt_component_class *comp_class); diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 0011475c..7e897fa3 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -1387,7 +1387,6 @@ update_fmt: *out_fmt_ch = fmt_ch; } -BT_HIDDEN void bt_lib_log(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...) { diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index ac0ec75b..ac701ec2 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -1602,7 +1602,6 @@ void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class, "comp-cls-addr=%p", comp_class); } -BT_HIDDEN void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, struct bt_component_class *comp_class) { diff --git a/python-plugin-provider/Makefile.am b/python-plugin-provider/Makefile.am index 28a45e80..84093881 100644 --- a/python-plugin-provider/Makefile.am +++ b/python-plugin-provider/Makefile.am @@ -3,7 +3,7 @@ AM_CPPFLAGS += $(PYTHON_INCLUDE) lib_LTLIBRARIES = libbabeltrace-python-plugin-provider.la libbabeltrace_python_plugin_provider_la_SOURCES = \ - python-plugin-provider.c logging.c logging.h + python-plugin-provider.c libbabeltrace_python_plugin_provider_la_LDFLAGS = \ $(LT_NO_UNDEFINED) \ -version-info $(BABELTRACE_LIBRARY_VERSION) \ diff --git a/python-plugin-provider/logging.c b/python-plugin-provider/logging.c deleted file mode 100644 index c6ba4381..00000000 --- a/python-plugin-provider/logging.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017 Philippe Proulx - * - * 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. - */ - -#define BT_LOG_OUTPUT_LEVEL python_plugin_provider_log_level -#include - -BT_LOG_INIT_LOG_LEVEL(python_plugin_provider_log_level, - "BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL"); diff --git a/python-plugin-provider/logging.h b/python-plugin-provider/logging.h deleted file mode 100644 index d5ab7ef4..00000000 --- a/python-plugin-provider/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PYTHON_PLUGIN_PROVIDER_LOGGING_H -#define PYTHON_PLUGIN_PROVIDER_LOGGING_H - -/* - * Copyright (c) 2017 Philippe Proulx - * - * 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. - */ - -#define BT_LOG_OUTPUT_LEVEL python_plugin_provider_log_level -#include - -BT_LOG_LEVEL_EXTERN_SYMBOL(python_plugin_provider_log_level); - -#endif /* PYTHON_PLUGIN_PROVIDER_LOGGING_H */ diff --git a/python-plugin-provider/python-plugin-provider.c b/python-plugin-provider/python-plugin-provider.c index f4747ef7..631a971b 100644 --- a/python-plugin-provider/python-plugin-provider.c +++ b/python-plugin-provider/python-plugin-provider.c @@ -25,7 +25,6 @@ */ #define BT_LOG_TAG "PLUGIN-PY" -#include "logging.h" #include #include @@ -157,9 +156,9 @@ void fini_python(void) { } static -const bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) +bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) { - const bt_plugin *plugin = NULL; + bt_plugin *plugin = NULL; PyObject *py_name = NULL; PyObject *py_author = NULL; PyObject *py_description = NULL; @@ -367,8 +366,6 @@ const bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) } } - bt_plugin_freeze(plugin); - goto end; error: @@ -390,7 +387,7 @@ G_MODULE_EXPORT bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path) { bt_plugin_set *plugin_set = NULL; - const bt_plugin *plugin = NULL; + bt_plugin *plugin = NULL; PyObject *py_plugin_info = NULL; gchar *basename = NULL; size_t path_len; diff --git a/tests/python-plugin-provider/.gitignore b/tests/python-plugin-provider/.gitignore index 557bfd33..a0f0c488 100644 --- a/tests/python-plugin-provider/.gitignore +++ b/tests/python-plugin-provider/.gitignore @@ -1,3 +1,4 @@ htmlcov .coverage test_python_plugin_provider +test_python_plugin_provider_env diff --git a/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py b/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py index 83f5e3dc..2f53ccaa 100644 --- a/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py +++ b/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py @@ -1,19 +1,19 @@ import bt2 -class MyIter(bt2._UserNotificationIterator): +class MyIter(bt2._UserMessageIterator): pass @bt2.plugin_component_class class MySource(bt2._UserSourceComponent, - notification_iterator_class=MyIter): + message_iterator_class=MyIter): pass @bt2.plugin_component_class class MyFilter(bt2._UserFilterComponent, - notification_iterator_class=MyIter): + message_iterator_class=MyIter): pass diff --git a/tests/python-plugin-provider/test_python_plugin_provider.py b/tests/python-plugin-provider/test_python_plugin_provider.py index a1071c9c..12bdac5a 100644 --- a/tests/python-plugin-provider/test_python_plugin_provider.py +++ b/tests/python-plugin-provider/test_python_plugin_provider.py @@ -3,9 +3,11 @@ import bt2 import os +@unittest.skip('depends on Python bindings, which are broken') class PythonPluginProviderTestCase(unittest.TestCase): def test_python_plugin_provider(self): - pset = bt2.find_plugins(os.environ['PYTHON_PLUGIN_PROVIDER_TEST_PLUGIN_PATH']) + path = os.environ['PYTHON_PLUGIN_PROVIDER_TEST_PLUGIN_PATH'] + pset = bt2.find_plugins(path) self.assertEqual(len(pset), 1) plugin = pset[0] self.assertEqual(plugin.name, 'sparkling') diff --git a/tests/python-plugin-provider/test_python_plugin_provider_env.in b/tests/python-plugin-provider/test_python_plugin_provider_env.in new file mode 100644 index 00000000..84307786 --- /dev/null +++ b/tests/python-plugin-provider/test_python_plugin_provider_env.in @@ -0,0 +1,34 @@ +#!/bin/bash +# +# Copyright (C) 2017 - Philippe Proulx +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +. "@abs_top_builddir@/tests/utils/common.sh" + +export PYTHON_PLUGIN_PROVIDER_TEST_PLUGIN_PATH="${BT_SRC_PATH}/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py" + +PYTHON_BUILD_DIR="${BT_BUILD_PATH}/bindings/python/bt2/build/build_lib" +TESTS_UTILS_PYTHON_DIR="${BT_SRC_PATH}/tests/utils/python" +export PYTHONPATH="${PYTHON_BUILD_DIR}:${TESTS_UTILS_PYTHON_DIR}" + +if [ "x${MSYSTEM}" != "x" ]; then + export PATH="${BT_BUILD_PATH}/lib/.libs:${BT_BUILD_PATH}/python-plugin-provider/.libs:${PATH}" +else + export LD_LIBRARY_PATH="${BT_BUILD_PATH}/lib/.libs:${BT_BUILD_PATH}/python-plugin-provider/.libs:${LD_LIBRARY_PATH}" +fi + +exec "$*" -- 2.34.1