build: don't hardcode triplet, allow specifying custom lib dir 23/33923/18
authorDamjan Marion <damarion@cisco.com>
Thu, 30 Sep 2021 18:04:14 +0000 (20:04 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 5 Oct 2021 16:44:32 +0000 (16:44 +0000)
Type: fix
Change-Id: I33f364fda88914f88f9b976cb83e6d3ff466f0bb
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Ray Kinsella <mdr@ashroe.eu>
12 files changed:
Makefile
src/CMakeLists.txt
src/pkg/debian/rules.in
src/vat/main.c
src/vat2/main.c
src/vlib/unix/plugin.c
src/vlib/unix/plugin.h
src/vpp/conf/startup.conf
src/vpp/vnet/main.c
src/vppinfra/config.h.in
test/framework.py
test/test_vcl.py

index 5c16b9a..28e44ce 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -377,8 +377,6 @@ wipe-release: test-wipe $(BR)/.deps.ok
 .PHONY: rebuild-release
 rebuild-release: wipe-release build-release
 
-libexpand = $(subst $(subst ,, ),:,$(foreach lib,$(1),$(BR)/install-$(2)-native/vpp/$(lib)/$(3)))
-
 export TEST_DIR ?= $(WS_ROOT)/test
 export RND_SEED ?= $(shell python3 -c 'import time; print(time.time())')
 
@@ -388,10 +386,7 @@ define test
        make -C test \
          VPP_BUILD_DIR=$(BR)/build-$(2)-native \
          VPP_BIN=$(BR)/install-$(2)-native/vpp/bin/vpp \
-         VPP_PLUGIN_PATH=$(call libexpand,$(libs),$(2),vpp_plugins) \
-         VPP_TEST_PLUGIN_PATH=$(call libexpand,$(libs),$(2),vpp_api_test_plugins) \
          VPP_INSTALL_PATH=$(BR)/install-$(2)-native/ \
-         LD_LIBRARY_PATH=$(call libexpand,$(libs),$(2),) \
          EXTENDED_TESTS=$(EXTENDED_TESTS) \
          PYTHON=$(PYTHON) \
          OS_ID=$(OS_ID) \
index 7bb5caa..0448a5b 100644 (file)
@@ -33,6 +33,10 @@ if(CMAKE_VERSION VERSION_LESS 3.12)
   endmacro()
 endif()
 
+if(NOT DEFINED CMAKE_INSTALL_LIBDIR AND EXISTS "/etc/debian_version")
+  set(CMAKE_INSTALL_LIBDIR "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
+endif()
+
 include(CheckCCompilerFlag)
 include(CheckIPOSupported)
 include(GNUInstallDirs)
@@ -152,7 +156,7 @@ endif()
 ##############################################################################
 option(VPP_SET_RPATH "Set rpath for resulting binaries and libraries." ON)
 if(VPP_SET_RPATH)
-  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${VPP_LIBRARY_DIR}")
 endif()
 set(CMAKE_INSTALL_MESSAGE NEVER)
 
index 15f8eb6..2af1fe7 100755 (executable)
@@ -23,8 +23,6 @@ build3vers := $(shell py3versions -sv)
 override_dh_strip:
        dh_strip --dbg-package=vpp-dbg
 
-DEB_HOST_MULTIARCH = $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
-
 override_dh_install:
        @for c in @VPP_COMPONENTS@; do \
          @CMAKE_COMMAND@ \
@@ -33,11 +31,6 @@ override_dh_install:
            -D CMAKE_INSTALL_PREFIX=@VPP_BINARY_DIR@/debian/$$c \
            -P @CMAKE_BINARY_DIR@/cmake_install.cmake 2>&1 \
            | grep -v 'Set runtime path of' ; \
-         if [ -d debian/$$c/lib ] ; then \
-           mv debian/$$c/lib debian/$$c/$(DEB_HOST_MULTIARCH) ; \
-           mkdir -p debian/$$c/usr/lib ; \
-           mv debian/$$c/$(DEB_HOST_MULTIARCH) debian/$$c/usr/lib ; \
-         fi ; \
          for d in bin include share ; do \
            if [ -d debian/$$c/$$d ] ; then \
              mkdir -p debian/$$c/usr ; \
index 70352e6..c718197 100644 (file)
@@ -313,8 +313,7 @@ vat_find_plugin_path ()
     return;
   *p = 0;
 
-  s = format (0, "%s/lib/" CLIB_TARGET_TRIPLET "/vpp_api_test_plugins:"
-             "%s/lib/vpp_api_test_plugins", path, path);
+  s = format (0, "%s/" CLIB_LIB_DIR "/vpp_api_test_plugins", path, path);
   vec_add1 (s, 0);
   vat_plugin_path = (char *) s;
 }
index 2d14847..dc27c6e 100644 (file)
@@ -85,8 +85,7 @@ vat2_find_plugin_path ()
     return;
   *p = 0;
 
-  s = format (0, "%s/lib/" CLIB_TARGET_TRIPLET "/vat2_plugins:"
-              "%s/lib/vat2_plugins", path, path);
+  s = format (0, "%s/" CLIB_LIB_DIR "/vat2_plugins", path, path);
   vec_add1 (s, 0);
   vat2_plugin_path = (char *) s;
 }
index 4a7ff27..891e2cb 100644 (file)
@@ -594,7 +594,12 @@ vlib_plugin_early_init (vlib_main_t * vm)
                                        0x7FFFFFFF /* aka no rate limit */ );
 
   if (pm->plugin_path == 0)
-    pm->plugin_path = format (0, "%s%c", vlib_plugin_path, 0);
+    pm->plugin_path = format (0, "%s", vlib_plugin_path);
+
+  if (pm->plugin_path_add)
+    pm->plugin_path = format (pm->plugin_path, ":%s", pm->plugin_path_add);
+
+  pm->plugin_path = format (pm->plugin_path, "%c", 0);
 
   PLUGIN_LOG_DBG ("plugin path %s", pm->plugin_path);
 
@@ -756,6 +761,8 @@ done:
       u8 *s = 0;
       if (unformat (input, "path %s", &s))
        pm->plugin_path = s;
+      else if (unformat (input, "add-path %s", &s))
+       pm->plugin_path_add = s;
       else if (unformat (input, "name-filter %s", &s))
        pm->plugin_name_filter = s;
       else if (unformat (input, "vat-path %s", &s))
index e3555fe..1c46e6b 100644 (file)
@@ -123,6 +123,7 @@ typedef struct
 
   /* paths and name filters */
   u8 *plugin_path;
+  u8 *plugin_path_add;
   u8 *plugin_name_filter;
   u8 *vat_plugin_path;
   u8 *vat_plugin_name_filter;
index ee10faa..a879db3 100644 (file)
@@ -201,6 +201,8 @@ cpu {
 # plugins {
        ## Adjusting the plugin path depending on where the VPP plugins are
        #       path /ws/vpp/build-root/install-vpp-native/vpp/lib/vpp_plugins
+       ## Add additional directory to the plugin path
+       #       add-path /tmp/vpp_plugins
 
        ## Disable all plugins by default and then selectively enable specific plugins
        # plugin default { disable }
index e0c7b0d..e9cef5e 100644 (file)
@@ -60,13 +60,11 @@ vpp_find_plugin_path ()
     return;
   *p = 0;
 
-  s = format (0, "%s/lib/" CLIB_TARGET_TRIPLET "/vpp_plugins:"
-             "%s/lib/vpp_plugins", path, path);
+  s = format (0, "%s/" CLIB_LIB_DIR "/vpp_plugins", path, path);
   vec_add1 (s, 0);
   vlib_plugin_path = (char *) s;
 
-  s = format (0, "%s/lib/" CLIB_TARGET_TRIPLET "/vpp_api_test_plugins:"
-             "%s/lib/vpp_api_test_plugins", path, path);
+  s = format (0, "%s/" CLIB_LIB_DIR "/vpp_api_test_plugins", path, path);
   vec_add1 (s, 0);
   vat_plugin_path = (char *) s;
 }
index 7aad027..c2b804c 100644 (file)
@@ -20,7 +20,7 @@
 #define CLIB_LOG2_CACHE_LINE_BYTES @LOG2_CACHE_LINE_BYTES@
 #endif
 
-#define CLIB_TARGET_TRIPLET "@CMAKE_C_COMPILER_TARGET@"
+#define CLIB_LIB_DIR "@VPP_LIBRARY_DIR@"
 #define CLIB_VECTOR_GROW_BY_ONE @VECTOR_GROW_BY_ONE@
 
 #endif
index 731c5e1..aa533f7 100755 (executable)
@@ -415,18 +415,7 @@ class VppTestCase(CPUInterface, unittest.TestCase):
         c = os.getenv("CACHE_OUTPUT", "1")
         cls.cache_vpp_output = False if c.lower() in ("n", "no", "0") else True
         cls.vpp_bin = os.getenv('VPP_BIN', "vpp")
-        cls.plugin_path = os.getenv('VPP_PLUGIN_PATH')
-        cls.test_plugin_path = os.getenv('VPP_TEST_PLUGIN_PATH')
-        cls.extern_plugin_path = os.getenv('EXTERN_PLUGINS')
-        plugin_path = None
-        if cls.plugin_path is not None:
-            if cls.extern_plugin_path is not None:
-                plugin_path = "%s:%s" % (
-                    cls.plugin_path, cls.extern_plugin_path)
-            else:
-                plugin_path = cls.plugin_path
-        elif cls.extern_plugin_path is not None:
-            plugin_path = cls.extern_plugin_path
+        extern_plugin_path = os.getenv('EXTERN_PLUGINS')
         debug_cli = ""
         if cls.step or cls.debug_gdb or cls.debug_gdbserver:
             debug_cli = "cli-listen localhost:5002"
@@ -454,6 +443,9 @@ class VppTestCase(CPUInterface, unittest.TestCase):
             "api-trace", "{", "on", "}",
             "api-segment", "{", "prefix", cls.get_api_segment_prefix(), "}",
             "cpu", "{", "main-core", str(cls.cpus[0]), ]
+        if extern_plugin_path is not None:
+            cls.extra_vpp_plugin_config.append(
+                "add-path %s" % extern_plugin_path)
         if cls.get_vpp_worker_count():
             cls.vpp_cmdline.extend([
                 "corelist-workers", ",".join([str(x) for x in cls.cpus[1:]])])
@@ -473,10 +465,6 @@ class VppTestCase(CPUInterface, unittest.TestCase):
 
         if cls.extra_vpp_punt_config is not None:
             cls.vpp_cmdline.extend(cls.extra_vpp_punt_config)
-        if plugin_path is not None:
-            cls.vpp_cmdline.extend(["plugin_path", plugin_path])
-        if cls.test_plugin_path is not None:
-            cls.vpp_cmdline.extend(["test_plugin_path", cls.test_plugin_path])
 
         if not cls.debug_attach:
             cls.logger.info("vpp_cmdline args: %s" % cls.vpp_cmdline)
index 6832265..50d36d5 100755 (executable)
@@ -5,6 +5,7 @@ import unittest
 import os
 import subprocess
 import signal
+import glob
 from framework import VppTestCase, VppTestRunner, running_extended_tests, \
     Worker
 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath, FibPathProto
@@ -26,20 +27,33 @@ _have_iperf3 = have_app(iperf3)
 class VCLAppWorker(Worker):
     """ VCL Test Application Worker """
 
+    libname = "libvcl_ldpreload.so"
+
+    class LibraryNotFound(Exception):
+        pass
+
     def __init__(self, build_dir, appname, executable_args, logger, env=None,
                  role=None, *args, **kwargs):
         self.role = role
+        vpp_install_path = os.getenv('VPP_INSTALL_PATH')
+
+        vcl_ldpreload_glob = "{}/**/{}".format(vpp_install_path, self.libname)
+        vcl_ldpreload_so = glob.glob(vcl_ldpreload_glob, recursive=True)
+
+        if len(vcl_ldpreload_so) < 1:
+            raise LibraryNotFound("cannot locate library: {}".format(
+                self.libname))
+
+        vcl_ldpreload_so = vcl_ldpreload_so[0]
+
         if env is None:
             env = {}
-        vcl_lib_dir = "%s/vpp/lib" % build_dir
         if "iperf" in appname:
             app = appname
-            env.update({'LD_PRELOAD':
-                        "%s/libvcl_ldpreload.so" % vcl_lib_dir})
+            env.update({'LD_PRELOAD': vcl_ldpreload_so})
         elif "sock" in appname:
             app = "%s/vpp/bin/%s" % (build_dir, appname)
-            env.update({'LD_PRELOAD':
-                        "%s/libvcl_ldpreload.so" % vcl_lib_dir})
+            env.update({'LD_PRELOAD': vcl_ldpreload_so})
         else:
             app = "%s/vpp/bin/%s" % (build_dir, appname)
         self.args = [app] + executable_args