Skip to content

Commit

Permalink
[api] add API for getting commissioner version (#199)
Browse files Browse the repository at this point in the history
This commit adds a new commissioner API that returns the commissioner
version.  Also add git revision to the version string.
  • Loading branch information
wgtdkp authored May 21, 2021
1 parent 6c23a85 commit ae90be0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#

cmake_minimum_required(VERSION 3.10.1)
project(ot-commissioner VERSION 0.1.0)
project(ot-commissioner VERSION 0.2.0)

option(OT_COMM_ANDROID "Build with Android NDK" OFF)
option(OT_COMM_APP "Build the CLI App" ON)
Expand All @@ -50,6 +50,25 @@ endif()

set(CMAKE_CXX_EXTENSIONS OFF)

execute_process(
COMMAND git describe --dirty --always 2>/dev/null
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE OT_COMM_GIT_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(OT_COMM_GIT_REVISION)
set(OT_COMM_VERSION "${PROJECT_VERSION}+${OT_COMM_GIT_REVISION}")
else()
set(OT_COMM_VERSION "${PROJECT_VERSION}")
endif()

message(STATUS "Version: ${OT_COMM_VERSION}")

add_library(commissioner-config INTERFACE)
target_compile_definitions(commissioner-config
INTERFACE OT_COMM_VERSION="${OT_COMM_VERSION}"
)

add_subdirectory(src)
add_subdirectory(tools)
add_subdirectory(third_party EXCLUDE_FROM_ALL)
9 changes: 9 additions & 0 deletions include/commissioner/commissioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,15 @@ class Commissioner
* @param[in] aJoinerId A Joiner ID.
*/
static void AddJoiner(ByteArray &aSteeringData, const ByteArray &aJoinerId);

/**
* @brief Return the commissioner version.
*
* @return A version string in format of <MAJOR>.<MINOR>.<PATCH>[+<GIT_REVISION>].
* The GIT_REVISION is included only when the commissioner is built in a
* git repository.
*/
static std::string GetVersion(void);
};

} // namespace commissioner
Expand Down
5 changes: 0 additions & 5 deletions src/app/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ target_link_libraries(commissioner-cli
readline
)

target_compile_definitions(commissioner-cli
PUBLIC
OT_COMM_VERSION="${PROJECT_VERSION}"
)

install(TARGETS commissioner-cli
RUNTIME DESTINATION bin
)
6 changes: 1 addition & 5 deletions src/app/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#include "app/cli/interpreter.hpp"
#include "common/utils.hpp"

#ifndef OT_COMM_VERSION
#error "OT_COMM_VERSION not defined"
#endif

using namespace ot::commissioner;

/**
Expand Down Expand Up @@ -74,7 +70,7 @@ static void PrintUsage(const std::string &aProgram)

static void PrintVersion()
{
Console::Write(OT_COMM_VERSION, Console::Color::kWhite);
Console::Write(Commissioner::GetVersion(), Console::Color::kWhite);
}

static Interpreter gInterpreter;
Expand Down
1 change: 1 addition & 0 deletions src/library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ target_link_libraries(commissioner
event_pthreads
$<$<NOT:$<BOOL:${OT_COMM_ANDROID}>>:pthread>
commissioner-common
commissioner-config
)

target_compile_definitions(commissioner
Expand Down
5 changes: 5 additions & 0 deletions src/library/commissioner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ void Commissioner::AddJoiner(ByteArray &aSteeringData, const ByteArray &aJoinerI
ComputeBloomFilter(aSteeringData, aJoinerId);
}

std::string Commissioner::GetVersion(void)
{
return OT_COMM_VERSION;
}

CommissionerImpl::CommissionerImpl(CommissionerHandler &aHandler, struct event_base *aEventBase)
: mState(State::kDisabled)
, mSessionId(0)
Expand Down

0 comments on commit ae90be0

Please sign in to comment.