From 3ea4888484f9670c9a818a6dd15321d9006d2a36 Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Wed, 26 May 2021 15:03:53 +0100 Subject: [PATCH 1/2] Remove public version macro With this macro, and version, checked into the repo, it also makes it hard to acheive the ideal of "tag to release" (because the contents of the repo would have to change at the same time as tagging). Mbed OS didn't use this macro. Given the macro is likely unused, and we only use it internally to share with the host what client version is running, remove the version macro from the public API. --- include/greentea-client/test_env.h | 1 - source/greentea_test_env.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/greentea-client/test_env.h b/include/greentea-client/test_env.h index a5e0aea..26b7ee1 100644 --- a/include/greentea-client/test_env.h +++ b/include/greentea-client/test_env.h @@ -22,7 +22,6 @@ #include "greentea-client/test_io.h" #ifdef __cplusplus -#define GREENTEA_CLIENT_VERSION_STRING "1.3.0" /** * Auxilary macros diff --git a/source/greentea_test_env.cpp b/source/greentea_test_env.cpp index 83e269a..19344e8 100644 --- a/source/greentea_test_env.cpp +++ b/source/greentea_test_env.cpp @@ -476,7 +476,7 @@ static void greentea_notify_completion(const int result) */ static void greentea_notify_version() { - greentea_send_kv(GREENTEA_TEST_ENV_HOST_TEST_VERSION, GREENTEA_CLIENT_VERSION_STRING); + greentea_send_kv(GREENTEA_TEST_ENV_HOST_TEST_VERSION, "1.3.0"); } /** From 6f4f8106dd4027a006af752094ee6453d7644e0b Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Wed, 26 May 2021 15:35:37 +0100 Subject: [PATCH 2/2] Obtain a version automatically Attempt to determine a version automatically using git. Fallback to v0.0.0 if the version can't be determined (e.g. due to git error, or if the library is not from a git repo). This makes it easier to tag-to-release as we don't have to edit a file at the same time we make a tag: no repository contents need change when making a release. --- CMakeLists.txt | 14 +++++++++++++- cmake/GitVersion.cmake | 16 ++++++++++++++++ source/greentea_test_env.cpp | 6 +++++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 cmake/GitVersion.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c4aec17..dc351a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,15 @@ cmake_minimum_required(VERSION 3.10) +include(cmake/GitVersion.cmake) + +message("version ${GIT_VERSION}") +message("major ${GIT_VERSION_MAJOR}") +message("minor ${GIT_VERSION_MINOR}") +message("patch ${GIT_VERSION_PATCH}") + project(greentea-client - VERSION 0.1 + VERSION ${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCH} DESCRIPTION "Greentea client" LANGUAGES C CXX ) @@ -21,6 +28,11 @@ target_sources(greentea-client source/greentea_test_env.cpp ) +target_compile_definitions(greentea-client + PUBLIC + GIT_VERSION=${GIT_VERSION} +) + # Default IO SET(GREENTEA_CLIENT_STDIO ON CACHE BOOL "Use stdio for IO") diff --git a/cmake/GitVersion.cmake b/cmake/GitVersion.cmake new file mode 100644 index 0000000..4814a81 --- /dev/null +++ b/cmake/GitVersion.cmake @@ -0,0 +1,16 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +execute_process(COMMAND git describe --tags --abbrev=12 --dirty --always + OUTPUT_VARIABLE GIT_VERSION + ERROR_QUIET) + +if (GIT_VERSION MATCHES "^v([0-9]+)\.([0-9]+)\.([0-9]+)") + set(GIT_VERSION_MAJOR ${CMAKE_MATCH_1}) + set(GIT_VERSION_MINOR ${CMAKE_MATCH_2}) + set(GIT_VERSION_PATCH ${CMAKE_MATCH_3}) +else() + set(GIT_VERSION_MAJOR 0) + set(GIT_VERSION_MINOR 0) + set(GIT_VERSION_PATCH 0) +endif() diff --git a/source/greentea_test_env.cpp b/source/greentea_test_env.cpp index 19344e8..32fce7c 100644 --- a/source/greentea_test_env.cpp +++ b/source/greentea_test_env.cpp @@ -20,6 +20,10 @@ #include #include "greentea-client/test_env.h" +#define str(s) #s +#define xstr(s) str(s) +#define GIT_VERSION_STRING xstr(GIT_VERSION) + /** * Generic test suite transport protocol keys */ @@ -476,7 +480,7 @@ static void greentea_notify_completion(const int result) */ static void greentea_notify_version() { - greentea_send_kv(GREENTEA_TEST_ENV_HOST_TEST_VERSION, "1.3.0"); + greentea_send_kv(GREENTEA_TEST_ENV_HOST_TEST_VERSION, GIT_VERSION_STRING); } /**