You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2023/08/03 21:49:31 UTC

[celix] branch feature/allow_duplicate_bundles_in_container created (now debb0748)

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a change to branch feature/allow_duplicate_bundles_in_container
in repository https://gitbox.apache.org/repos/asf/celix.git


      at debb0748 Update ContainerPackaging to allow and warn for duplicate bundles

This branch includes the following new commits:

     new 972be34e Remove cmake IN_LIST usage, not broadly supported yet.
     new debb0748 Update ContainerPackaging to allow and warn for duplicate bundles

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[celix] 01/02: Remove cmake IN_LIST usage, not broadly supported yet.

Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/allow_duplicate_bundles_in_container
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 972be34e122096857de5b2a6579b46f5dfe41387
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Thu Aug 3 20:26:38 2023 +0200

    Remove cmake IN_LIST usage, not broadly supported yet.
---
 cmake/cmake_celix/ContainerPackaging.cmake | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake
index b86ef710..5d74a1f4 100644
--- a/cmake/cmake_celix/ContainerPackaging.cmake
+++ b/cmake/cmake_celix/ContainerPackaging.cmake
@@ -437,10 +437,9 @@ function(celix_container_bundles_dir)
 
     set(DEST_DIR "${CONTAINER_LOC}/${BD_DIR_NAME}")
     get_target_property(CLEAN_FILES ${CONTAINER_TARGET} "ADDITIONAL_CLEAN_FILES")
-    if (NOT ${DEST_DIR} IN_LIST CLEAN_FILES)
-        list(APPEND CLEAN_FILES ${DEST_DIR})
-        set_target_properties(${CONTAINER_TARGET} PROPERTIES "ADDITIONAL_CLEAN_FILES" "${CLEAN_FILES}")
-    endif()
+    list(APPEND CLEAN_FILES ${DEST_DIR})
+    list(REMOVE_DUPLICATES CLEAN_FILES)
+    set_target_properties(${CONTAINER_TARGET} PROPERTIES "ADDITIONAL_CLEAN_FILES" "${CLEAN_FILES}")
 
     foreach(BUNDLE IN ITEMS ${BD_BUNDLES})
         if (IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE})


[celix] 02/02: Update ContainerPackaging to allow and warn for duplicate bundles

Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/allow_duplicate_bundles_in_container
in repository https://gitbox.apache.org/repos/asf/celix.git

commit debb07481fda15a7aa7ce26f0d18bb0731676867
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Thu Aug 3 23:49:14 2023 +0200

    Update ContainerPackaging to allow and warn for duplicate bundles
---
 .github/workflows/macos.yml                |  1 +
 .github/workflows/ubuntu.yml               |  5 +--
 CMakeLists.txt                             |  5 ++-
 cmake/celix_project/WarningTests.cmake     | 33 +++++++++++++++++++
 cmake/cmake_celix/ContainerPackaging.cmake | 51 ++++++++++++++++++++++++------
 conanfile.py                               |  3 ++
 6 files changed, 86 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index b1ca4bd1..d211b044 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -30,6 +30,7 @@ jobs:
             -o celix:build_all=True
             -o celix:enable_testing_for_cxx14=True
             -o celix:enable_testing_dependency_manager_for_cxx11=True
+            -o celix:enable_cmake_warning_tests=True
             -o celix:enable_testing_on_ci=True
         run: |
           #force require libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml
index cd0505b5..fef433b5 100644
--- a/.github/workflows/ubuntu.yml
+++ b/.github/workflows/ubuntu.yml
@@ -31,13 +31,13 @@ jobs:
           # build profile
           conan profile new release --detect
           conan profile update settings.build_type=Release release
-          #Note no backwards compatiblity for gcc5 needed, setting libcxx to c++11.
+          #Note no backwards compatibility for gcc5 needed, setting libcxx to c++11.
           conan profile update settings.compiler.libcxx=libstdc++11 release
           conan profile show release
           # host profile
           conan profile new default --detect
           conan profile update settings.build_type=${{ matrix.type }} default
-          #Note no backwards compatiblity for gcc5 needed, setting libcxx to c++11.
+          #Note no backwards compatibility for gcc5 needed, setting libcxx to c++11.
           conan profile update settings.compiler.libcxx=libstdc++11 default
           conan profile show default
       - name: Configure and install dependencies
@@ -50,6 +50,7 @@ jobs:
             -o celix:build_all=True
             -o celix:enable_testing_for_cxx14=True
             -o celix:enable_testing_dependency_manager_for_cxx11=True
+            -o celix:enable_cmake_warning_tests=True
             -o celix:enable_testing_on_ci=True
         run: |
           #force require libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41948e8f..5aee5206 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -158,7 +158,7 @@ endif ()
 
 option(ENABLE_TESTING_DEPENDENCY_MANAGER_FOR_CXX11 "Test the Dependency Manager for C++11 support" OFF)
 option(ENABLE_TESTING_FOR_CXX14 "Test celix utils and framework C++ header for C++14 support" OFF)
-
+option(ENABLE_CMAKE_WARNING_TESTS "Enable cmake warning tests to test warning prints" OFF)
 option(ENABLE_TESTING_ON_CI "Whether to enable testing on CI. This influence allowed timing errors during unit tests" OFF)
 
 if (CELIX_INSTALL_DEPRECATED_API)
@@ -195,6 +195,9 @@ add_subdirectory(misc/experimental)
 #Example as last, because some example will check if underlining options are enabled
 add_subdirectory(examples/celix-examples)
 
+#include CMake warning tests
+include(cmake/celix_project/WarningTests.cmake)
+
 #export targets
 install(EXPORT celix NAMESPACE Celix:: DESTINATION share/celix/cmake FILE Targets.cmake COMPONENT cmake)
 install_celix_targets(celix NAMESPACE Celix:: DESTINATION share/celix/cmake FILE CelixTargets COMPONENT cmake)
diff --git a/cmake/celix_project/WarningTests.cmake b/cmake/celix_project/WarningTests.cmake
new file mode 100644
index 00000000..6125ec8c
--- /dev/null
+++ b/cmake/celix_project/WarningTests.cmake
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#[[
+Misc usage of Apache Celix CMake functions to check if they work as expected.
+Including some constructions that will generate warnings.
+]]
+
+if (ENABLE_CMAKE_WARNING_TESTS AND TARGET Celix::shell AND TARGET Celix::shell_tui)
+    add_celix_container(examples-with-duplicate-installed-bundles
+            BUNDLES Celix::shell Celix::shell_tui #add bundles with run level 3
+    )
+
+    #Adding a bundle twice on the same run level is fine and the last entry should be ignored
+    celix_container_bundles(examples-with-duplicate-installed-bundles LEVEL 3 Celix::shell)
+
+    #Adding a bundle twice on different run levels should result in an warning
+    celix_container_bundles(examples-with-duplicate-installed-bundles LEVEL 4 Celix::shell_tui)
+endif ()
diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake
index 5d74a1f4..0c188468 100644
--- a/cmake/cmake_celix/ContainerPackaging.cmake
+++ b/cmake/cmake_celix/ContainerPackaging.cmake
@@ -475,14 +475,13 @@ function(celix_container_bundles_dir)
             message(FATAL_ERROR "Cannot add bundle in container ${CONTAINER_TARGET}. Provided bundle is not a abs path to an existing file nor a cmake target (${BUNDLE}).")
         endif ()
 
-        if (BUNDLE_ID AND DEST AND BUNDLE_FILE)
+        if (BUNDLE_ID AND DEST AND BUNDLE_FILE AND NOT TARGET ${CONTAINER_TARGET}_copy_bundle_${BUNDLE_ID})
             add_custom_target(${CONTAINER_TARGET}_copy_bundle_${BUNDLE_ID}
                 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_FILE} ${DEST}
                 BYPRODUCTS ${DEST}
                 DEPENDS ${DEPS}
             )
             add_dependencies(${CONTAINER_TARGET} ${CONTAINER_TARGET}_copy_bundle_${BUNDLE_ID})
-
             get_target_property(CLEAN_FILES ${CONTAINER_TARGET} "ADDITIONAL_CLEAN_FILES")
             list(APPEND CLEAN_FILES ${DEST})
             set_target_properties(${CONTAINER_TARGET} PROPERTIES "ADDITIONAL_CLEAN_FILES" "${CLEAN_FILES}")
@@ -554,6 +553,7 @@ function(celix_container_bundles)
 
     if (BUNDLES_INSTALL)
         get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_INSTALL")
+        sET(BUNDLES_LEVEL "install")
     else () #bundle level 0,1,2,3,4,5 or 6
         get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_LEVEL_${BUNDLES_LEVEL}")
     endif ()
@@ -591,12 +591,18 @@ function(celix_container_bundles)
             message(FATAL_ERROR "Cannot add bundle `${BUNDLE}` to container target ${CONTAINER_TARGET}. Argument is not a path or cmake target")
         endif ()
 
-       if(COPY)
-            list(APPEND BUNDLES ${COPY_LOC})
-       else()
-            list(APPEND BUNDLES ${ABS_LOC})
-       endif()
-   endforeach()
+       if (COPY)
+           set(BUNDLE_TO_ADD ${COPY_LOC})
+       else ()
+           set(BUNDLE_TO_ADD ${ABS_LOC})
+       endif ()
+
+       list(FIND BUNDLES ${BUNDLE_TO_ADD} INDEX)
+       if (INDEX EQUAL -1) #Note this ignores the same bundle for the same level
+           _celix_container_check_duplicate_bundles(${CONTAINER_TARGET} ${BUNDLE_TO_ADD} ${TARGET_LEVEL})
+           list(APPEND BUNDLES ${BUNDLE_TO_ADD})
+       endif ()
+    endforeach()
 
     if (BUNDLES_INSTALL)
         set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES_INSTALL" "${BUNDLES}")
@@ -604,11 +610,38 @@ function(celix_container_bundles)
         set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES_LEVEL_${BUNDLES_LEVEL}" "${BUNDLES}")
     endif ()
 
-   if(COPY) 
+   if (COPY)
        celix_container_bundles_dir(${CONTAINER_TARGET} DIR_NAME bundles BUNDLES ${BUNDLES_LIST})
    endif()
 endfunction()
 
+#[[
+Private function to check if there are duplicate bundles in the container and print a warning if so.
+Arg CONTAINER_TARGET ADDED_BUNDLES_LIST
+]]
+function(_celix_container_check_duplicate_bundles)
+    list(GET ARGN 0 CONTAINER_TARGET)
+    list(GET ARGN 1 TO_ADD_BUNDLE)
+    list(GET ASRN 2 BUNDLE_LEVEL)
+
+    set(MSG "Bundle `${TO_ADD_BUNDLE}` is added to the container multiple times. This can lead to errors during \
+        bundle installation. Bundle `${TO_ADD_BUNDLE}` already added to container '${CONTAINER_TARGET}` \
+        at level ${BUNDLE_LEVEL}.")
+
+    get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_INSTALL")
+    list(FIND BUNDLES ${TO_ADD_BUNDLE} INDEX)
+    if (INDEX GREATER -1)
+        message(WARNING "${MSG}")
+    endif()
+    foreach(BUNDLE_LEVEL RANGE 0 6)
+        get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_LEVEL_${BUNDLE_LEVEL}")
+        list(FIND BUNDLES ${TO_ADD_BUNDLE} INDEX)
+        if (INDEX GREATER -1)
+            message(WARNING "${MSG}")
+        endif()
+    endforeach()
+endfunction()
+
 #[[
 Embed a selection of bundles to the Celix container.
 
diff --git a/conanfile.py b/conanfile.py
index aa8444ee..151286da 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -98,6 +98,7 @@ class CelixConan(ConanFile):
         "celix_install_deprecated_api": [True, False],
         "celix_use_compression_for_bundle_zips": [True, False],
         "celix_err_buffer_size": "ANY",
+        "enable_cmake_warning_tests": [True, False],
         "enable_testing_on_ci": [True, False],
     }
     default_options = {
@@ -161,6 +162,7 @@ class CelixConan(ConanFile):
         "celix_install_deprecated_api": False,
         "celix_use_compression_for_bundle_zips": True,
         "celix_err_buffer_size": 512,
+        "enable_cmake_warning_tests": False,
         "enable_testing_on_ci": False,
     }
     _cmake = None
@@ -195,6 +197,7 @@ class CelixConan(ConanFile):
         del self.info.options.build_shell_bonjour
         del self.info.options.enable_testing_dependency_manager_for_cxx11
         del self.info.options.enable_testing_for_cxx14
+        del self.info.options.enable_cmake_warning_tests
         del self.info.options.enable_testing_on_ci
 
     def build_requirements(self):