Skip to content
Merged
2 changes: 1 addition & 1 deletion docs/BuildSystemLinux.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/BuildSystemZephyr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/Versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand All @@ -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
)
15 changes: 15 additions & 0 deletions src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
#include <ctype.h>
#include <string.h>

#include <ocre/common.h>

#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 */
Expand Down
19 changes: 19 additions & 0 deletions src/common/include/ocre/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
#ifndef OCRE_COMMON_H
#define OCRE_COMMON_H

/**
* @brief Build configuration of the Ocre Library
* @headerfile ocre.h <ocre/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
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions src/ocre/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ target_sources(OcreCore
)

target_link_libraries(OcreCore
PUBLIC
PRIVATE
uthash
OcrePlatform
OcreRuntime
OcreRuntimeWamr
PUBLIC
OcreRuntime
OcreCommon
)

Expand Down
10 changes: 10 additions & 0 deletions src/ocre/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 14 additions & 0 deletions src/ocre/include/ocre/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef OCRE_CONTAINER_H
#define OCRE_CONTAINER_H

#include <stdbool.h>

/**
* @brief The possible status of a container
*
Expand Down Expand Up @@ -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 */
19 changes: 0 additions & 19 deletions src/ocre/include/ocre/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@

#include <ocre/runtime/vtable.h>

/**
* @brief Build configuration of the Ocre Library
* @headerfile ocre.h <ocre/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 <ocre/ocre.h>
Expand Down
13 changes: 0 additions & 13 deletions src/ocre/ocre.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,13 @@

#include <ocre/ocre.h>
#include <ocre/platform/log.h>
#include <ocre/build_info.h>
#include <ocre/runtime/wamr/wasip1.h>
#include <ocre/commit_id.h>

#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 {
Expand Down
11 changes: 11 additions & 0 deletions src/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 7 additions & 1 deletion src/platform/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 4 additions & 2 deletions src/platform/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion src/runtime/wamr-wasip1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ target_include_directories(OcreRuntimeWamr
)

target_link_libraries(OcreRuntimeWamr
PUBLIC
PRIVATE
OcreRuntime
OcrePlatform
OcreRuntimeAPI
Expand Down
5 changes: 0 additions & 5 deletions src/samples/static_checks/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ target_sources(OcreShell
)

target_include_directories(OcreShell
PRIVATE
../common/include
../ocre/include
../runtime/include
PUBLIC
include
)
2 changes: 1 addition & 1 deletion src/shell/container/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions tests/system/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/system/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ foreach(test ${OCRE_TESTS})
)

target_link_libraries(test_${test}
OcreCommon
OcreCore
Unity
)
Expand Down
Loading