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

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

commit 88903d1ec82c7cf2c7d3eb2dc723ee3de4a0dff4
Author: Pepijn Noltes <[email protected]>
AuthorDate: Mon Dec 5 19:20:29 2022 +0100

    Add support for a COPY / NO_COPY option in the celix_container_bundles 
cmake function
---
 bundles/logging/README.md                          |  2 +-
 cmake/cmake_celix/ContainerPackaging.cmake         | 25 +++++++++++++--
 documents/cmake_commands/README.md                 | 16 +++++++---
 examples/celix-examples/CMakeLists.txt             |  2 +-
 .../bundles_copy_example/CMakeLists.txt            | 37 ++++++++++++++++++++++
 5 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/bundles/logging/README.md b/bundles/logging/README.md
index 2d4aed31..2dc02670 100644
--- a/bundles/logging/README.md
+++ b/bundles/logging/README.md
@@ -54,4 +54,4 @@ If the Celix Log Service is installed, 'find_package(Celix)' 
will set:
  
 Also the following deprecated bundle will be set:
  - The `Celix::log_service` bundle target. The log service bundle. Deprecated, 
use Celix::log_admin instead.
- - The `Celix::log_writer_stdout` bundle target. Deprecated bundle. Logging to 
stdout is now an integral part of the log admin.
\ No newline at end of file
+ - The `Celix::syslog_writer` bundle target. Deprecated bundle. Logging to 
stdout is now an integral part of the log admin.
\ No newline at end of file
diff --git a/cmake/cmake_celix/ContainerPackaging.cmake 
b/cmake/cmake_celix/ContainerPackaging.cmake
index 5ac41ef2..57cd7e56 100644
--- a/cmake/cmake_celix/ContainerPackaging.cmake
+++ b/cmake/cmake_celix/ContainerPackaging.cmake
@@ -238,6 +238,7 @@ function(add_celix_container)
             endif ()
         endif()
         set(STAGE1_LAUNCHER_SRC 
"${CMAKE_BINARY_DIR}/celix/gen/containers/${CONTAINER_TARGET}/main.stage1.c")
+        set(STAGE2_LAUNCHER_SRC 
"${CMAKE_BINARY_DIR}/celix/gen/containers/${CONTAINER_TARGET}/main.stage2.c")
 
         file(GENERATE
                 OUTPUT "${STAGE1_LAUNCHER_SRC}"
@@ -263,7 +264,15 @@ 
$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_EMBEDDED_PROPERTIES>,\\n\
 "
         )
 
-        file(GENERATE OUTPUT "${LAUNCHER_SRC}" INPUT "${STAGE1_LAUNCHER_SRC}")
+        #Rerun generate to do a second parsing of generator expression
+        file(GENERATE OUTPUT "${STAGE2_LAUNCHER_SRC}" INPUT 
"${STAGE1_LAUNCHER_SRC}")
+
+        #To prevent unnecessary build times a custom command is used to ensure 
that the copy to launcher src is only
+        #done if the stage2 file is different
+        add_custom_command(
+                OUTPUT "${LAUNCHER_SRC}"
+                COMMAND ${CMAKE_COMMAND} -E copy "${STAGE2_LAUNCHER_SRC}" 
"${LAUNCHER_SRC}"
+                DEPENDS "${STAGE2_LAUNCHER_SRC}")
     endif ()
 
     if (LAUNCHER_SRC) #compilation needed
@@ -490,6 +499,8 @@ Add a selection of bundles to the Celix container.
 
 ```CMake
 celix_container_bundles(<celix_container_target_name>
+    [COPY]
+    [NO_COPY]
     [LEVEL (0..6)]
     [INSTALL]
     bundle1
@@ -515,13 +526,17 @@ Optional Arguments:
 - LEVEL: The run level for the added bundles. Default is 3.
 - INSTALL: If this option is present, the bundles will only be installed 
instead of the default install and start.
            The bundles will be installed after all bundle in LEVEL 0..6 are 
installed and started.
+- COPY: If this option is present, the bundles will be copied to the container 
build dir. This option overrides the
+        NO_COPY option used in the add_celix_container call.
+- NO_COPY: If this option is present, the install/start bundles will be 
configured using a absolute path to the
+           bundle. This option overrides optional NO_COPY option used in the 
add_celix_container call.
 ]]
 function(celix_container_bundles)
     #0 is container TARGET
     list(GET ARGN 0 CONTAINER_TARGET)
     list(REMOVE_AT ARGN 0)
 
-    set(OPTIONS INSTALL)
+    set(OPTIONS INSTALL COPY NO_COPY)
     set(ONE_VAL_ARGS LEVEL)
     set(MULTI_VAL_ARGS )
     cmake_parse_arguments(BUNDLES "${OPTIONS}" "${ONE_VAL_ARGS}" 
"${MULTI_VAL_ARGS}" ${ARGN})
@@ -539,6 +554,12 @@ function(celix_container_bundles)
     get_target_property(COPY ${CONTAINER_TARGET} "CONTAINER_COPY_BUNDLES")
     get_target_property(IS_FAT ${CONTAINER_TARGET} "CONTAINER_IS_FAT")
 
+    if (BUNDLES_COPY)
+        set(COPY TRUE)
+    elseif (BUNDLES_NO_COPY)
+        set(COPY FALSE)
+    endif ()
+
     foreach(BUNDLE IN ITEMS ${BUNDLES_LIST})
         if (IS_FAT)
             message(FATAL_ERROR "Cannot add bundle ${BUNDLE} to Celix 
container ${CONTAINER_TARGET}. ${CONTAINER_TARGET} is configured as a fat 
container, so only embedded bundles are allowed. Use EMBEDDED_BUNDLES instead 
of BUNDLES in the add_celix_container CMake command.")
diff --git a/documents/cmake_commands/README.md 
b/documents/cmake_commands/README.md
index 0fd28705..c13da906 100644
--- a/documents/cmake_commands/README.md
+++ b/documents/cmake_commands/README.md
@@ -474,11 +474,13 @@ Add a selection of bundles to the Celix container.
 
 ```CMake
 celix_container_bundles(<celix_container_target_name>
-    [LEVEL (0..6)]
-    [INSTALL]
-    bundle1
-    bundle2
-    ...
+      [COPY]
+      [NO_COPY]
+      [LEVEL (0..6)]
+      [INSTALL]
+      bundle1
+      bundle2
+      ...
 )
 ```
 
@@ -499,6 +501,10 @@ Optional Arguments:
 - LEVEL: The run level for the added bundles. Default is 3.
 - INSTALL: If this option is present, the bundles will only be installed 
instead of the default install and start.
   The bundles will be installed after all bundle in LEVEL 0..6 are installed 
and started.
+- COPY: If this option is present, the bundles will be copied to the container 
build dir. This option overrides the
+  NO_COPY option used in the add_celix_container call.
+- NO_COPY: If this option is present, the install/start bundles will be 
configured using a absolute path to the
+  bundle. This option overrides optional NO_COPY option used in the 
add_celix_container call.
 
 ## celix_container_embedded_bundles
 Embed a selection of bundles to the Celix container.
diff --git a/examples/celix-examples/CMakeLists.txt 
b/examples/celix-examples/CMakeLists.txt
index 2a5052cd..f19a3cec 100644
--- a/examples/celix-examples/CMakeLists.txt
+++ b/examples/celix-examples/CMakeLists.txt
@@ -44,7 +44,7 @@ if (EXAMPLES)
     add_subdirectory(embedding)
     add_subdirectory(track_tracker_example)
     add_subdirectory(log_service_example)
-
     add_subdirectory(bundle_with_private_lib)
+    add_subdirectory(bundles_copy_example)
 
 endif(EXAMPLES)
diff --git a/examples/celix-examples/bundles_copy_example/CMakeLists.txt 
b/examples/celix-examples/bundles_copy_example/CMakeLists.txt
new file mode 100644
index 00000000..ad4452de
--- /dev/null
+++ b/examples/celix-examples/bundles_copy_example/CMakeLists.txt
@@ -0,0 +1,37 @@
+# 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.
+
+######################## Examples for the COPY / NO_COPY option in 
celix_container_bundles work #######################
+
+#By default bundles in a container will be copied to the bundles dir in the 
container dir
+add_celix_container(copy_bundles_example1 BUNDLES Celix::log_admin)
+#The shell bundle will also be copied, because of the container copy config
+celix_container_bundles(copy_bundles_example1 LEVEL 1 Celix::shell)
+#The shell_tui bundle will not be copied, because of the NO_COPY option
+celix_container_bundles(copy_bundles_example1 NO_COPY LEVEL 1 Celix::shell_tui)
+#The log_writer_syslog bundle will be copied, because of the COPY option
+celix_container_bundles(copy_bundles_example1 LEVEL 2 COPY 
Celix::syslog_writer)
+
+
+#Bundles in this container will not be copied to the bundles dir in the 
container dir, because of the NO_COPY option
+add_celix_container(copy_bundles_example2 NO_COPY BUNDLES Celix::log_admin)
+#The shell bundle will also mpt be copied, because of the container copy config
+celix_container_bundles(copy_bundles_example2 LEVEL 1 Celix::shell)
+#The shell_tui bundle will not be copied, because of the NO_COPY option
+celix_container_bundles(copy_bundles_example2 LEVEL 1 NO_COPY Celix::shell_tui)
+#The log_writer_syslog bundle will be copied, because of the COPY option
+celix_container_bundles(copy_bundles_example2 COPY LEVEL 2 
Celix::syslog_writer)

Reply via email to