diff --git a/docs/BuildSystemLinux.md b/docs/BuildSystemLinux.md index af07c00a..d75b6ffd 100644 --- a/docs/BuildSystemLinux.md +++ b/docs/BuildSystemLinux.md @@ -17,7 +17,7 @@ This sections describes the build-time configuration honored by samples and test There are several components of the Ocre version that gets compiled in the project. -The file `src/ocre/version.h` includes the Ocre Library version string. +The file `src/common/version.h` includes the Ocre Library version string. While the file `commit_id.h` includes the commit ID of the Ocre Library. If this file is not present in the source tree, the file is generated during the build process and is stored in the build directory. If the file does not exist, and the source tree is not a valid git repository, the build will fail. diff --git a/docs/BuildSystemZephyr.md b/docs/BuildSystemZephyr.md index af992818..3367950c 100644 --- a/docs/BuildSystemZephyr.md +++ b/docs/BuildSystemZephyr.md @@ -81,7 +81,7 @@ This sections describes the build-time configuration required for Ocre to work. There are several components of the Ocre version that gets compiled in the project. -The file `src/ocre/version.h` includes the Ocre Library version string. +The file `src/common/version.h` includes the Ocre Library version string. While the file `commit_id.h` includes the commit ID of the Ocre Library. If this file is not present in the source tree, the file is generated during the build process and is stored in the build directory. If the file does not exist, and the source tree is not a valid git repository, the build will fail. diff --git a/docs/Versioning.md b/docs/Versioning.md index 4c7ded8f..1fe06463 100644 --- a/docs/Versioning.md +++ b/docs/Versioning.md @@ -4,7 +4,7 @@ There are several components of the Ocre version that gets compiled in the project. -The file `src/ocre/version.h` includes the Ocre Library version string. +The file `src/common/version.h` includes the Ocre Library version string. While the file `commit_id.h` includes the commit ID of the Ocre Library. If this file is not present in the source tree, the file is generated during the build process and is stored in the build directory. If the file does not exist, and the source tree is not a valid git repository, the build will fail. diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 70114ca8..a7690f1f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -17,10 +17,9 @@ if(GIT_DIR) # Generate commit ID header file in source dir if we are in a git repository add_custom_command( - OUTPUT include/ocre/commit_id.h - COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/ocre" - COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h" - COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h" + OUTPUT include/commit_id.h + COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" + COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM DEPENDS always_rebuild @@ -31,9 +30,9 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre) # Generate build info header file in binary dir for every build add_custom_command( - OUTPUT include/ocre/build_info.h - COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/ocre/build_info.h" - COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/ocre/build_info.h" + OUTPUT include/build_info.h + COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/build_info.h" + COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/build_info.h" VERBATIM DEPENDS always_rebuild ) @@ -50,12 +49,13 @@ add_library(OcreCommon) target_sources(OcreCommon PRIVATE common.c - include/ocre/build_info.h - include/ocre/commit_id.h + include/build_info.h + include/commit_id.h ) target_include_directories(OcreCommon + PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/include PUBLIC include - ${CMAKE_CURRENT_BINARY_DIR}/include ) diff --git a/src/common/common.c b/src/common/common.c index ec62c4e1..367117a5 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -2,6 +2,21 @@ #include #include +#include + +#include "version.h" +#include "build_info.h" +#include "commit_id.h" + +/* Constant build information */ + +const struct ocre_config ocre_build_configuration = { + .build_info = OCRE_BUILD_HOST_INFO, + .version = OCRE_VERSION_STRING, + .commit_id = GIT_COMMIT_ID, + .build_date = OCRE_BUILD_DATE, +}; + int ocre_is_valid_name(const char *id) { /* Cannot be NULL */ diff --git a/src/common/include/ocre/common.h b/src/common/include/ocre/common.h index 741c7b5e..ea139dc3 100644 --- a/src/common/include/ocre/common.h +++ b/src/common/include/ocre/common.h @@ -8,6 +8,25 @@ #ifndef OCRE_COMMON_H #define OCRE_COMMON_H +/** + * @brief Build configuration of the Ocre Library + * @headerfile ocre.h + * + * There should only be only one instance of this structure in the program. And it must be in constant read-only memory. + * It is set at build-time and should only be read-only to the user. + */ +struct ocre_config { + const char *version; /**< Version of the Ocre Library */ + const char *commit_id; /**< Commit ID of the build tree */ + const char *build_info; /**< Host build information */ + const char *build_date; /**< Build date */ +}; + +/** + * @brief The instance of configuration of the Ocre Library is constant and compiled-in. + */ +extern const struct ocre_config ocre_build_configuration; + /** * @brief Check if a container or image names is valid * @memberof ocre_context diff --git a/src/ocre/version.h b/src/common/version.h similarity index 100% rename from src/ocre/version.h rename to src/common/version.h diff --git a/src/ocre/CMakeLists.txt b/src/ocre/CMakeLists.txt index 00ea4e12..2427b362 100644 --- a/src/ocre/CMakeLists.txt +++ b/src/ocre/CMakeLists.txt @@ -16,11 +16,12 @@ target_sources(OcreCore ) target_link_libraries(OcreCore - PUBLIC + PRIVATE uthash OcrePlatform - OcreRuntime OcreRuntimeWamr + PUBLIC + OcreRuntime OcreCommon ) diff --git a/src/ocre/container.c b/src/ocre/container.c index 5228ad39..748fedcd 100644 --- a/src/ocre/container.c +++ b/src/ocre/container.c @@ -710,3 +710,13 @@ const char *ocre_container_get_image(const struct ocre_container *container) return container->image; } + +bool ocre_container_is_detached(struct ocre_container *container) +{ + if (!container) { + LOG_ERR("Invalid container"); + return false; + } + + return container->detached; +} diff --git a/src/ocre/include/ocre/container.h b/src/ocre/include/ocre/container.h index 72540293..8f14b0cf 100644 --- a/src/ocre/include/ocre/container.h +++ b/src/ocre/include/ocre/container.h @@ -8,6 +8,8 @@ #ifndef OCRE_CONTAINER_H #define OCRE_CONTAINER_H +#include + /** * @brief The possible status of a container * @@ -165,4 +167,16 @@ int ocre_container_kill(struct ocre_container *container); */ int ocre_container_wait(struct ocre_container *container, int *status); +/** + * @brief Get detached mode + * @memberof ocre_container + * + * Detached containers run on background. + * + * @param container A pointer to the container to terminate + * + * @return true if container is detached, false otherwise + */ +bool ocre_container_is_detached(struct ocre_container *container); + #endif /* OCRE_CONTAINER_H */ diff --git a/src/ocre/include/ocre/library.h b/src/ocre/include/ocre/library.h index e792a244..b11ea8c5 100644 --- a/src/ocre/include/ocre/library.h +++ b/src/ocre/include/ocre/library.h @@ -10,25 +10,6 @@ #include -/** - * @brief Build configuration of the Ocre Library - * @headerfile ocre.h - * - * There should only be only one instance of this structure in the program. And it must be in constant read-only memory. - * It is set at build-time and should only be read-only to the user. - */ -struct ocre_config { - const char *version; /**< Version of the Ocre Library */ - const char *commit_id; /**< Commit ID of the build tree */ - const char *build_info; /**< Host build information */ - const char *build_date; /**< Build date */ -}; - -/** - * @brief The instance of configuration of the Ocre Library is constant and compiled-in. - */ -extern const struct ocre_config ocre_build_configuration; - /** * @class ocre_context * @headerfile ocre.h diff --git a/src/ocre/ocre.c b/src/ocre/ocre.c index e134a31e..b0240048 100644 --- a/src/ocre/ocre.c +++ b/src/ocre/ocre.c @@ -17,26 +17,13 @@ #include #include -#include #include -#include #include "context.h" #include "util/rm_rf.h" -#include "version.h" - LOG_MODULE_REGISTER(ocre, CONFIG_OCRE_LOG_LEVEL); -/* Constant build information */ - -const struct ocre_config ocre_build_configuration = { - .build_info = OCRE_BUILD_HOST_INFO, - .version = OCRE_VERSION_STRING, - .commit_id = GIT_COMMIT_ID, - .build_date = OCRE_BUILD_DATE, -}; - /* List of runtimes */ struct runtime_node { diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt new file mode 100644 index 00000000..d4c96065 --- /dev/null +++ b/src/platform/CMakeLists.txt @@ -0,0 +1,11 @@ +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 + +add_library(OcrePlatformBase INTERFACE) + +target_include_directories(OcrePlatform + PUBLIC + include +) diff --git a/src/platform/posix/CMakeLists.txt b/src/platform/posix/CMakeLists.txt index 565c47c9..77612f46 100644 --- a/src/platform/posix/CMakeLists.txt +++ b/src/platform/posix/CMakeLists.txt @@ -14,8 +14,14 @@ target_sources(OcrePlatform lstat.c ) +add_subdirectory(.. OcrePlatformBase) + target_include_directories(OcrePlatform PUBLIC include - ../include +) + +target_link_libraries(OcrePlatform + PRIVATE + OcrePlatformBase ) diff --git a/src/platform/zephyr/CMakeLists.txt b/src/platform/zephyr/CMakeLists.txt index 943530aa..7e253296 100644 --- a/src/platform/zephyr/CMakeLists.txt +++ b/src/platform/zephyr/CMakeLists.txt @@ -12,13 +12,15 @@ target_sources(OcrePlatform lstat.c ) +add_subdirectory(.. OcrePlatformBase) + target_include_directories(OcrePlatform PUBLIC include - ../include ) target_link_libraries(OcrePlatform - PUBLIC + PRIVATE zephyr_interface + OcrePlatformBase ) diff --git a/src/runtime/wamr-wasip1/CMakeLists.txt b/src/runtime/wamr-wasip1/CMakeLists.txt index 25286ba4..85106bb0 100644 --- a/src/runtime/wamr-wasip1/CMakeLists.txt +++ b/src/runtime/wamr-wasip1/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(OcreRuntimeWamr ) target_link_libraries(OcreRuntimeWamr - PUBLIC + PRIVATE OcreRuntime OcrePlatform OcreRuntimeAPI diff --git a/src/samples/static_checks/posix/CMakeLists.txt b/src/samples/static_checks/posix/CMakeLists.txt index a0f08a5f..715f60a3 100644 --- a/src/samples/static_checks/posix/CMakeLists.txt +++ b/src/samples/static_checks/posix/CMakeLists.txt @@ -18,11 +18,6 @@ target_link_libraries(ocre_cmd OcreShell ) -target_link_libraries(OcreShell - PUBLIC - OcreCore -) - set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) target_link_libraries(ocre_cmd PRIVATE Threads::Threads) diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index a073075c..d6feb577 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -29,6 +29,10 @@ target_sources(OcreShell ) target_include_directories(OcreShell + PRIVATE + ../common/include + ../ocre/include + ../runtime/include PUBLIC include ) diff --git a/src/shell/container/create.c b/src/shell/container/create.c index 0a2af1fc..b1bc1b6e 100644 --- a/src/shell/container/create.c +++ b/src/shell/container/create.c @@ -230,7 +230,7 @@ int cmd_container_create_run(struct ocre_context *ctx, const char *argv0, int ar } } - if (detached) { + if (detached || !strcmp(argv[0], "create")) { const char *cid = ocre_container_get_id(container); fprintf(stdout, "%s\n", cid); diff --git a/tests/system/context.c b/tests/system/context.c index cc3f1c7a..1b4e3722 100644 --- a/tests/system/context.c +++ b/tests/system/context.c @@ -508,6 +508,38 @@ void test_ocre_context_get_containers_ok(void) TEST_ASSERT_EQUAL_INT(0, ocre_context_get_containers(context, containers, 2)); } +void test_ocre_context_create_container_detached_mode(void) +{ + /* Create a valid detached container*/ + + struct ocre_container *detached_container = + ocre_context_create_container(context, "hello-world.wasm", "wamr/wasip1", NULL, true, NULL); + TEST_ASSERT_NOT_NULL(detached_container); + + /* Create a valid non-detached container*/ + + struct ocre_container *non_detached_container = + ocre_context_create_container(context, "hello-world.wasm", "wamr/wasip1", NULL, false, NULL); + TEST_ASSERT_NOT_NULL(non_detached_container); + + /* Check detached status */ + + TEST_ASSERT_TRUE(ocre_container_is_detached(detached_container)); + + /* Check non-detached status */ + + TEST_ASSERT_FALSE(ocre_container_is_detached(non_detached_container)); + + /* Check detached status from NULL should be false */ + + TEST_ASSERT_FALSE(ocre_container_is_detached(NULL)); + + /* Remove the containers */ + + TEST_ASSERT_EQUAL_INT(0, ocre_context_remove_container(context, detached_container)); + TEST_ASSERT_EQUAL_INT(0, ocre_context_remove_container(context, non_detached_container)); +} + int main(void) { UNITY_BEGIN(); @@ -523,6 +555,7 @@ int main(void) RUN_TEST(test_ocre_context_create_container_ok); RUN_TEST(test_ocre_context_create_container_null_runtime_ok); RUN_TEST(test_ocre_context_create_container_with_id_ok); + RUN_TEST(test_ocre_context_create_container_detached_mode); RUN_TEST(test_ocre_context_create_container_with_id_twice); RUN_TEST(test_ocre_context_create_container_and_forget); RUN_TEST(test_ocre_context_create_wait_remove); diff --git a/tests/system/posix/CMakeLists.txt b/tests/system/posix/CMakeLists.txt index 9fceee0f..051540b0 100644 --- a/tests/system/posix/CMakeLists.txt +++ b/tests/system/posix/CMakeLists.txt @@ -51,6 +51,7 @@ foreach(test ${OCRE_TESTS}) ) target_link_libraries(test_${test} + OcreCommon OcreCore Unity )