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 2024/07/22 10:23:29 UTC

(celix) 06/07: gh-685: Add cmake generated celix_framework_version.h

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

pnoltes pushed a commit to branch feature/685-refactor-manifest-format
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 4678197b9693fa6cbf11dfa421de7daa0ec18ed3
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Sun Jul 21 22:58:40 2024 +0200

    gh-685: Add cmake generated celix_framework_version.h
---
 cmake/celix_project/CelixProject.cmake             | 38 +++++++++++++++++
 cmake/cmake_celix/BundlePackaging.cmake            |  3 +-
 cmake/cmake_celix/ContainerPackaging.cmake         | 44 +++-----------------
 cmake/cmake_celix/templates/MANIFEST.json.in       |  4 +-
 libs/framework/CMakeLists.txt                      |  2 +
 libs/framework/gtest/CMakeLists.txt                |  3 +-
 .../gtest/src/CxxBundleContextTestSuite.cc         |  8 ++--
 .../gtest/src/DependencyManagerTestSuite.cc        |  2 +-
 .../gtest/src/MultipleFrameworkTestSuite.cc        | 29 -------------
 libs/framework/src/celix_bundle_manifest.c         | 17 ++++----
 libs/framework/src/celix_framework_version.h.in    | 48 ++++++++++++++++++++++
 11 files changed, 115 insertions(+), 83 deletions(-)

diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake
index 9812155e6..ddb7db240 100644
--- a/cmake/celix_project/CelixProject.cmake
+++ b/cmake/celix_project/CelixProject.cmake
@@ -85,6 +85,44 @@ MACRO(celix_subproject)
     ENDIF (${NAME})
 ENDMACRO(celix_subproject)
 
+#[[
+Internal function that converts a property string to a JSON field entry.
+The result is stored in the OUTPUT_VAR_NAME variable.
+
+In the key the char `=` is not allowed and should be escaped as `\=` (in CMake this is `\\=`, because \ is already an
+escape char in CMake).
+In the value the char `=` is allowed.
+
+To handle \= string sequences the \= entries are replaced with a placeholder (__<CELIX_ESCAPED_EQUAL>__) and after the
+split the placeholder is replaced with =.
+
+```CMake
+_celix_convert_keyval_to_json("prop1=val1" "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"val1\""
+_celix_convert_keyval_to_json("prop1=va=l1" "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"va=l1\""
+_celix_convert_keyval_to_json("prop\\=1=val1" "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop=1\":\"val1\""
+
+_celix_convert_keyval_to_json(" prop1 = val1 " "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\"":\"val1\""
+```
+]]
+function(_celix_convert_keyval_to_json INPUT_STR SEPERATOR_CHAR OUTPUT_VAR_NAME)
+    set(PLACEHOLDER "__<CELIX_ESCAPED_EQUAL>__")
+    string(REPLACE "\\${SEPERATOR_CHAR}" "${PLACEHOLDER}" TEMP_INPUT_STR "${INPUT_STR}")
+
+    string(REGEX MATCH "([^${SEPERATOR_CHAR}]+)${SEPERATOR_CHAR}(.*)" _ ${TEMP_INPUT_STR})
+    set(KEY ${CMAKE_MATCH_1})
+    set(VALUE ${CMAKE_MATCH_2})
+
+    #Replace replaced \= and \\ with = and \
+    string(REPLACE "${PLACEHOLDER}" "${SEPERATOR_CHAR}" KEY "${KEY}")
+    string(REPLACE "${PLACEHOLDER}" "${SEPERATOR_CHAR}" VALUE "${VALUE}")
+
+    #Strip leading and trailing spaces
+    string(STRIP "${KEY}" KEY)
+    string(STRIP "${VALUE}" VALUE)
+
+    set(${OUTPUT_VAR_NAME} "\"${KEY}\":\"${VALUE}\"" PARENT_SCOPE)
+endfunction()
+
 #[[
 Custom target which list the Celix CMake targets that are still using deprecated headers.
 ]]
diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake
index c2f6863cf..f5eec25af 100644
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@ -753,13 +753,14 @@ celix_bundle_headers(<bundle_target>
 ]]
 function(celix_bundle_headers)
     #0 is bundle TARGET
-    #1..n is header name / header value
+    #1..n is header "key: value" pairs
     list(GET ARGN 0 BUNDLE)
     list(REMOVE_AT ARGN 0)
 
     get_target_property(HEADERS ${BUNDLE} "BUNDLE_HEADERS")
 
     foreach (HEADER IN ITEMS ${ARGN})
+        _celix_convert_keyval_to_json(${HEADER} ":" HEADER)
         list(APPEND HEADERS "${HEADER}")
     endforeach ()
 
diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake
index 77044884c..501c7ca56 100644
--- a/cmake/cmake_celix/ContainerPackaging.cmake
+++ b/cmake/cmake_celix/ContainerPackaging.cmake
@@ -595,38 +595,6 @@ function(_celix_container_check_duplicate_bundles)
     endforeach()
 endfunction()
 
-#[[
-Internal function that converts a property string to a JSON field entry.
-The result is stored in the OUTPUT_VAR_NAME variable.
-
-In the key the char `=` is not allowed and should be escaped as `\=` (in CMake this is `\\=`, because \ is already an
-escape char in CMake).
-In the value the char `=` is allowed.
-
-To handle \= string sequences the \= entries are replaced with a placeholder (__<CELIX_ESCAPED_EQUAL>__) and after the
-split the placeholder is replaced with =.
-
-```CMake
-_celix_convert_property_to_json("prop1=val1" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"val1\""
-_celix_convert_property_to_json("prop1=va=l1" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"va=l1\""
-_celix_convert_property_to_json("prop\\=1=val1" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop=1\":\"val1\""
-```
-]]
-function(_celix_convert_property_to_json INPUT_STR OUTPUT_VAR_NAME)
-    set(PLACEHOLDER "__<CELIX_ESCAPED_EQUAL>__")
-    string(REPLACE "\\=" "${PLACEHOLDER}" TEMP_INPUT_STR "${INPUT_STR}")
-
-    string(REGEX MATCH "([^=]+)=(.*)" _ ${TEMP_INPUT_STR})
-    set(KEY ${CMAKE_MATCH_1})
-    set(VALUE ${CMAKE_MATCH_2})
-
-    #Replace replaced \= and \\ with = and \
-    string(REPLACE "${PLACEHOLDER}" "=" KEY "${KEY}")
-    string(REPLACE "${PLACEHOLDER}" "=" VALUE "${VALUE}")
-
-    set(${OUTPUT_VAR_NAME} "\"${KEY}\":\"${VALUE}\"" PARENT_SCOPE)
-endfunction()
-
 #[[
 Add the provided properties to the target Celix container config properties.
 These properties will be added to the config.properties in the container build dir.
@@ -641,14 +609,14 @@ celix_container_runtime_properties(<celix_container_target_name>
 ]]
 function(celix_container_runtime_properties)
     #0 is container TARGET
-    #1..n is bundles
+    #1..n is property "key=val" pairs
     list(GET ARGN 0 CONTAINER_TARGET)
     list(REMOVE_AT ARGN 0)
 
     get_target_property(PROPS ${CONTAINER_TARGET} "CONTAINER_RUNTIME_PROPERTIES")
 
-    foreach(PROP IN ITEMS ${ARGN})
-        _celix_convert_property_to_json(${PROP} PROP)
+    foreach (PROP IN ITEMS ${ARGN})
+        _celix_convert_keyval_to_json(${PROP} "=" PROP)
         list(APPEND PROPS ${PROP})
     endforeach()
 
@@ -669,14 +637,14 @@ celix_container_embedded_properties(<celix_container_target_name>
 ]]
 function(celix_container_embedded_properties)
     #0 is container TARGET
-    #1..n is bundles
+    #1..n is property "key=val" pairs
     list(GET ARGN 0 CONTAINER_TARGET)
     list(REMOVE_AT ARGN 0)
 
     get_target_property(PROPS ${CONTAINER_TARGET} "CONTAINER_EMBEDDED_PROPERTIES")
 
-    foreach(PROP IN ITEMS ${ARGN})
-        _celix_convert_property_to_json(${PROP} PROP)
+    foreach (PROP IN ITEMS ${ARGN})
+        _celix_convert_keyval_to_json(${PROP} "=" PROP)
         list(APPEND PROPS ${PROP})
     endforeach()
 
diff --git a/cmake/cmake_celix/templates/MANIFEST.json.in b/cmake/cmake_celix/templates/MANIFEST.json.in
index 0770d4765..8abe223a1 100644
--- a/cmake/cmake_celix/templates/MANIFEST.json.in
+++ b/cmake/cmake_celix/templates/MANIFEST.json.in
@@ -1,6 +1,6 @@
 {
-$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>,
->
+    $<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>,$<COMMA>
+    >$<$<BOOL:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>>:$<COMMA>>
     "CELIX_BUNDLE_MANIFEST_VERSION" : "2.0.0",
     "CELIX_BUNDLE_SYMBOLIC_NAME" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_SYMBOLIC_NAME>",
     "CELIX_BUNDLE_VERSION" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_VERSION>",
diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt
index 94e031c78..421fa20e6 100644
--- a/libs/framework/CMakeLists.txt
+++ b/libs/framework/CMakeLists.txt
@@ -70,6 +70,8 @@ if (FRAMEWORK)
     generate_export_header(framework
             BASE_NAME "CELIX_FRAMEWORK"
             EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/celix/gen/includes/framework/celix_framework_export.h")
+    configure_file("${CMAKE_CURRENT_LIST_DIR}/src/celix_framework_version.h.in"
+            "${CMAKE_BINARY_DIR}/celix/gen/includes/framework/celix_framework_version.h")
     target_include_directories(framework PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/celix/gen/includes/framework>)
     celix_deprecated_utils_headers(framework)
 
diff --git a/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt
index af3f60c0a..bd0c62c86 100644
--- a/libs/framework/gtest/CMakeLists.txt
+++ b/libs/framework/gtest/CMakeLists.txt
@@ -19,6 +19,8 @@ add_celix_bundle(simple_test_bundle1 NO_ACTIVATOR VERSION 1.0.0)
 celix_bundle_name(simple_test_bundle1 "Simple Test Bundle")
 celix_bundle_group(simple_test_bundle1 "test/group")
 celix_bundle_description(simple_test_bundle1 "Test Description")
+celix_bundle_headers(simple_test_bundle1 "Extra-Header1: value1" "Extra-Header2: value2")
+celix_bundle_headers(simple_test_bundle1 "Extra-Header3: value3")
 
 add_celix_bundle(simple_test_bundle2 NO_ACTIVATOR VERSION 1.0.0)
 add_celix_bundle(simple_test_bundle3 NO_ACTIVATOR VERSION 1.0.0)
@@ -46,7 +48,6 @@ add_dependencies(unresolvable_bundle sublib)
 set(CELIX_FRAMEWORK_TEST_SOURCES
     src/CelixFrameworkTestSuite.cc
     src/CelixFrameworkUtilsTestSuite.cc
-    src/MultipleFrameworkTestSuite.cc
     src/CelixBundleContextBundlesTestSuite.cc
     src/CelixBundleContextServicesTestSuite.cc
     src/DependencyManagerTestSuite.cc
diff --git a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc
index b987d28b8..0598d5f4b 100644
--- a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc
+++ b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc
@@ -696,10 +696,10 @@ TEST_F(CxxBundleContextTestSuite, CheckStandardServiceProperties) {
 
 TEST_F(CxxBundleContextTestSuite, GetBundleInformation) {
 
-    EXPECT_EQ(ctx->getBundle().getSymbolicName(), std::string{"celix_framework"});
-    EXPECT_EQ(ctx->getBundle().getName(), std::string{"Celix Framework"});
+    EXPECT_EQ(ctx->getBundle().getSymbolicName(), std::string{"apache_celix_framework"});
+    EXPECT_EQ(ctx->getBundle().getName(), std::string{"Apache Celix Framework"});
     EXPECT_EQ(ctx->getBundle().getGroup(), std::string{"Celix/Framework"});
-    EXPECT_EQ(ctx->getBundle().getDescription(), std::string{"The Celix Framework System Bundle"});
+    EXPECT_EQ(ctx->getBundle().getDescription(), std::string{"The Apache Celix Framework System Bundle"});
     EXPECT_EQ(ctx->getBundle().getLocation(), std::string{""});
 
     std::atomic<bool> startCalled{false};
@@ -713,7 +713,7 @@ TEST_F(CxxBundleContextTestSuite, GetBundleInformation) {
             EXPECT_TRUE(!bnd.getEntry("META-INF/MANIFEST.MF").empty());
             EXPECT_EQ(bnd.getEntry("/META-INF/MANIFEST.MF"), bnd.getEntry("META-INF/MANIFEST.MF"));
             EXPECT_EQ(bnd.getEntry("does-not-exist"), std::string{});
-            EXPECT_EQ(bnd.getManifestValue("Bundle-SymbolicName"), std::string{"simple_test_bundle1"});
+            EXPECT_EQ(bnd.getManifestValue("Extra-Header1"), std::string{"value1"});
             EXPECT_EQ(bnd.getManifestValue("non-existing"), std::string{});
             startCalled = true;
         })
diff --git a/libs/framework/gtest/src/DependencyManagerTestSuite.cc b/libs/framework/gtest/src/DependencyManagerTestSuite.cc
index 7c9ac5dc2..726464c78 100644
--- a/libs/framework/gtest/src/DependencyManagerTestSuite.cc
+++ b/libs/framework/gtest/src/DependencyManagerTestSuite.cc
@@ -261,7 +261,7 @@ TEST_F(DependencyManagerTestSuite, CxxDmGetInfo) {
 
     auto info = mng.getInfo();
     EXPECT_EQ(info.bndId, 0);
-    EXPECT_EQ(info.bndSymbolicName, "celix_framework");
+    EXPECT_EQ(info.bndSymbolicName, "apache_celix_framework");
     EXPECT_EQ(info.components.size(), 0); //not build yet
 
     mng.build();
diff --git a/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc b/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc
deleted file mode 100644
index 393ce42cc..000000000
--- a/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.
- */
-
-#include <gtest/gtest.h>
-
-#include "celix_launcher.h"
-
-
-class MultipleFrameworkTestSuite : public ::testing::Test {
-public:
-    MultipleFrameworkTestSuite() = default;
-    ~MultipleFrameworkTestSuite() noexcept override  = default;
-};
diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c
index f07e8f310..38330e578 100644
--- a/libs/framework/src/celix_bundle_manifest.c
+++ b/libs/framework/src/celix_bundle_manifest.c
@@ -26,6 +26,7 @@
 #include "celix_stdlib_cleanup.h"
 #include "celix_utils.h"
 #include "celix_version.h"
+#include "celix_framework_version.h"
 
 // Mandatory manifest attributes
 #define CELIX_BUNDLE_MANIFEST_VERSION "CELIX_BUNDLE_MANIFEST_VERSION"
@@ -40,6 +41,7 @@
 #define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP"
 
 #define CELIX_BUNDLE_SYMBOLIC_NAME_ALLOWED_SPECIAL_CHARS "-_:."
+#define CELIX_FRAMEWORK_MANIFEST_VERSION "2.0.0"
 
 struct celix_bundle_manifest {
     celix_properties_t* attributes;
@@ -101,13 +103,14 @@ celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifes
         return ENOMEM;
     }
 
-    celix_status_t status = celix_properties_set(properties, CELIX_BUNDLE_MANIFEST_VERSION, "2.0.0");
-    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "celix.framework"));
-    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_NAME, "Celix Framework"));
-    //status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, CELIX_FRAMEWORK_VERSION));
-    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, "3.0.0")); //TODO
-    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_GROUP, "Celix"));
-    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_DESCRIPTION, "Celix Framework"));
+    celix_status_t status =
+        celix_properties_set(properties, CELIX_BUNDLE_MANIFEST_VERSION, CELIX_FRAMEWORK_MANIFEST_VERSION);
+    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "apache_celix_framework"));
+    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_NAME, "Apache Celix Framework"));
+    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, CELIX_FRAMEWORK_VERSION));
+    status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_GROUP, "Celix/Framework"));
+    status = CELIX_DO_IF(
+        status, celix_properties_set(properties, CELIX_BUNDLE_DESCRIPTION, "The Apache Celix Framework System Bundle"));
 
     if (status != CELIX_SUCCESS) {
         celix_err_push("Failed to set properties for framework manifest");
diff --git a/libs/framework/src/celix_framework_version.h.in b/libs/framework/src/celix_framework_version.h.in
new file mode 100644
index 000000000..cffd8a236
--- /dev/null
+++ b/libs/framework/src/celix_framework_version.h.in
@@ -0,0 +1,48 @@
+/*
+* 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.
+*/
+
+#ifndef CELIX_CELIX_FRAMEWORK_VERSION_H
+#define CELIX_CELIX_FRAMEWORK_VERSION_H
+
+/**
+ * @file celix_framework_version.h
+ * @brief Celix framework version macros
+ */
+
+/*!
+ * The Celix framework version.
+ */
+#define CELIX_FRAMEWORK_VERSION "${CELIX_MAJOR}.${CELIX_MINOR}.${CELIX_MICRO}"
+
+/*!
+ * The major part of the Celix framework version.
+ */
+#define CELIX_FRAMEWORK_VERSION_MAJOR ${CELIX_MAJOR}
+
+/*!
+ * The minor part of the Celix framework version.
+ */
+#define CELIX_FRAMEWORK_VERSION_MINOR ${CELIX_MINOR}
+
+/*!
+ * The micro part of the Celix framework version.
+ */
+#define CELIX_FRAMEWORK_VERSION_MICRO ${CELIX_MICRO}
+
+#endif // CELIX_CELIX_FRAMEWORK_VERSION_H