Skip to content

Commit 03b0b0c

Browse files
committed
refactor: move version to ocre/common and make it private
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent 69971ad commit 03b0b0c

6 files changed

Lines changed: 44 additions & 42 deletions

File tree

src/common/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ if(GIT_DIR)
1717

1818
# Generate commit ID header file in source dir if we are in a git repository
1919
add_custom_command(
20-
OUTPUT include/ocre/commit_id.h
21-
COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/ocre"
22-
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h"
23-
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h"
20+
OUTPUT include/commit_id.h
21+
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h"
22+
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h"
2423
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2524
VERBATIM
2625
DEPENDS always_rebuild
@@ -31,9 +30,9 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre)
3130

3231
# Generate build info header file in binary dir for every build
3332
add_custom_command(
34-
OUTPUT include/ocre/build_info.h
35-
COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/ocre/build_info.h"
36-
COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/ocre/build_info.h"
33+
OUTPUT include/build_info.h
34+
COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/build_info.h"
35+
COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/build_info.h"
3736
VERBATIM
3837
DEPENDS always_rebuild
3938
)
@@ -50,12 +49,13 @@ add_library(OcreCommon)
5049
target_sources(OcreCommon
5150
PRIVATE
5251
common.c
53-
include/ocre/build_info.h
54-
include/ocre/commit_id.h
52+
include/build_info.h
53+
include/commit_id.h
5554
)
5655

5756
target_include_directories(OcreCommon
57+
PRIVATE
58+
${CMAKE_CURRENT_BINARY_DIR}/include
5859
PUBLIC
5960
include
60-
${CMAKE_CURRENT_BINARY_DIR}/include
6161
)

src/common/common.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
#include <ctype.h>
33
#include <string.h>
44

5+
#include <ocre/common.h>
6+
7+
#include "version.h"
8+
#include "build_info.h"
9+
#include "commit_id.h"
10+
11+
/* Constant build information */
12+
13+
const struct ocre_config ocre_build_configuration = {
14+
.build_info = OCRE_BUILD_HOST_INFO,
15+
.version = OCRE_VERSION_STRING,
16+
.commit_id = GIT_COMMIT_ID,
17+
.build_date = OCRE_BUILD_DATE,
18+
};
19+
520
int ocre_is_valid_name(const char *id)
621
{
722
/* Cannot be NULL */

src/common/include/ocre/common.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88
#ifndef OCRE_COMMON_H
99
#define OCRE_COMMON_H
1010

11+
/**
12+
* @brief Build configuration of the Ocre Library
13+
* @headerfile ocre.h <ocre/ocre.h>
14+
*
15+
* There should only be only one instance of this structure in the program. And it must be in constant read-only memory.
16+
* It is set at build-time and should only be read-only to the user.
17+
*/
18+
struct ocre_config {
19+
const char *version; /**< Version of the Ocre Library */
20+
const char *commit_id; /**< Commit ID of the build tree */
21+
const char *build_info; /**< Host build information */
22+
const char *build_date; /**< Build date */
23+
};
24+
25+
/**
26+
* @brief The instance of configuration of the Ocre Library is constant and compiled-in.
27+
*/
28+
extern const struct ocre_config ocre_build_configuration;
29+
1130
/**
1231
* @brief Check if a container or image names is valid
1332
* @memberof ocre_context

src/ocre/include/ocre/library.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@
1010

1111
#include <ocre/runtime/vtable.h>
1212

13-
/**
14-
* @brief Build configuration of the Ocre Library
15-
* @headerfile ocre.h <ocre/ocre.h>
16-
*
17-
* There should only be only one instance of this structure in the program. And it must be in constant read-only memory.
18-
* It is set at build-time and should only be read-only to the user.
19-
*/
20-
struct ocre_config {
21-
const char *version; /**< Version of the Ocre Library */
22-
const char *commit_id; /**< Commit ID of the build tree */
23-
const char *build_info; /**< Host build information */
24-
const char *build_date; /**< Build date */
25-
};
26-
27-
/**
28-
* @brief The instance of configuration of the Ocre Library is constant and compiled-in.
29-
*/
30-
extern const struct ocre_config ocre_build_configuration;
31-
3213
/**
3314
* @class ocre_context
3415
* @headerfile ocre.h <ocre/ocre.h>

src/ocre/ocre.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,13 @@
1717

1818
#include <ocre/ocre.h>
1919
#include <ocre/platform/log.h>
20-
#include <ocre/build_info.h>
2120
#include <ocre/runtime/wamr/wasip1.h>
22-
#include <ocre/commit_id.h>
2321

2422
#include "context.h"
2523
#include "util/rm_rf.h"
2624

27-
#include <ocre/version.h>
28-
2925
LOG_MODULE_REGISTER(ocre, CONFIG_OCRE_LOG_LEVEL);
3026

31-
/* Constant build information */
32-
33-
const struct ocre_config ocre_build_configuration = {
34-
.build_info = OCRE_BUILD_HOST_INFO,
35-
.version = OCRE_VERSION_STRING,
36-
.commit_id = GIT_COMMIT_ID,
37-
.build_date = OCRE_BUILD_DATE,
38-
};
39-
4027
/* List of runtimes */
4128

4229
struct runtime_node {

0 commit comments

Comments
 (0)