diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d1dcf35ea755bece4c729fa57c41ad7e338f38a..c6432a1cac503488893e7b99bc174059124cb11b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,12 +97,11 @@ set(ANBOX_TRANSLATOR_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/anbox/translators) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRANSLATOR_INSTALL_DIR=\\\"${CMAKE_INSTALL_PREFIX}/${ANBOX_TRANSLATOR_INSTALL_DIR}\\\"") if (NOT ANBOX_VERSION) - set(ANBOX_VERSION 2) - if ("${cmake_build_type_lower}" STREQUAL "release") - set(ANBOX_VERSION_SUFFIX "") - else() - set(ANBOX_VERSION_SUFFIX dev) - endif() + exec_program("git" ${CMAKE_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_COMMIT_HASH) + set(ANBOX_VERSION "local-${GIT_COMMIT_HASH}") +endif() +if (ANBOX_VERSION_SUFFIX) + set(ANBOX_VERSION "${ANBOX_VERSION}-${ANBOX_VERSION_SUFFIX}") endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h) diff --git a/snapcraft.yaml b/snapcraft.yaml index 76abb6e11cacb90b2807daba0d043653a69eb473..2e238503fda067b3f6f434e549acaae2f9272127 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,9 +1,11 @@ name: anbox -# NOTE: Always only use increasing numeric values here. This is -# passed down into cmake and assigned to an integer variable which -# can be used for version number comparision inside the code base -# to accomondate for any breaking changes. version: 3 +version-script: | + if [ "$SNAPCRAFT_GRADE" = "stable" ]; then + echo $SNAPCRAFT_PROJECT_VERSION + else + echo $SNAPCRAFT_PROJECT_VERSION-$(git rev-parse --short HEAD) + fi summary: Android in a Box description: | Runtime for Android applications which runs a full Android system diff --git a/src/anbox/build/version.cpp b/src/anbox/build/version.cpp index 07576e980ee18e47aa0e7aeb17184c879d538c60..b63b804322090e90c72a923b023ffb9231171def 100644 --- a/src/anbox/build/version.cpp +++ b/src/anbox/build/version.cpp @@ -25,9 +25,9 @@ namespace build { static std::string init_version_string() { std::string v; if (!version_suffix || std::strlen(version_suffix) == 0) - v = utils::string_format("%d", version_major); + v = utils::string_format("%s", version); else - v = utils::string_format("%d-%s", version_major, version_suffix); + v = utils::string_format("%s-%s", version, version_suffix); return v; } diff --git a/src/anbox/build/version.h.in b/src/anbox/build/version.h.in index e6dcbbd796dfbfa25081a2a7fb3636a0908deaf8..fb7983a36f84c8a8f8fa7288a3ab4806ace1ff76 100644 --- a/src/anbox/build/version.h.in +++ b/src/anbox/build/version.h.in @@ -25,8 +25,8 @@ namespace anbox { namespace build { -/// @brief version_major marks the major version -static constexpr const std::uint32_t version_major{@ANBOX_VERSION@}; +/// @brief version marks the version +static constexpr const char *version{"@ANBOX_VERSION@"}; /// @brief version_suffix is an additional suffix which can be amended to /// the major version number to indicate a dev build for example. static constexpr const char *version_suffix{"@ANBOX_VERSION_SUFFIX@"};