From 45ac3ecf6ade13dd796dea9f68e8211af9171e0f Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Fri, 5 May 2017 07:50:14 +0200 Subject: [PATCH] Set version we're building from snapcraft --- CMakeLists.txt | 11 +++++ snapcraft.yaml | 5 ++ src/CMakeLists.txt | 4 +- src/anbox/{version.cpp => build/version.h.in} | 25 +++++++--- src/anbox/cmds/system_info.cpp | 9 ++-- src/anbox/cmds/version.cpp | 7 ++- src/anbox/version.h | 46 ------------------- 7 files changed, 43 insertions(+), 64 deletions(-) rename src/anbox/{version.cpp => build/version.h.in} (55%) delete mode 100644 src/anbox/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 957664b..a3fe59e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,17 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC") 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 VERSION) + set(VERSION 2) + if ("${cmake_build_type_lower}" STREQUAL "release") + set(VERSION_SUFFIX "") + else() + set(VERSION_SUFFIX dev) + endif() +endif() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h) + add_subdirectory(external) add_subdirectory(src) add_subdirectory(tests) diff --git a/snapcraft.yaml b/snapcraft.yaml index 12cf904..a32e30e 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,4 +1,8 @@ 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: 2 summary: Android in a Box description: | @@ -84,6 +88,7 @@ parts: # FIXME: Anbox currently has some paths with hard coded prefixes. Once # that is fixed we can avoid using a prefix here. - -DCMAKE_INSTALL_PREFIX:PATH=/usr + - -DVERSION=$SNAPCRAFT_PROJECT_VERSION build-packages: - build-essential - cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0229795..42f07bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,11 +57,13 @@ set(SOURCES anbox/utils.cpp anbox/cli.cpp anbox/runtime.cpp - anbox/version.cpp anbox/daemon.cpp anbox/config.cpp anbox/not_reachable.cpp + anbox/build/version.cpp + anbox/build/version.h.in + anbox/android/intent.cpp anbox/common/fd.cpp diff --git a/src/anbox/version.cpp b/src/anbox/build/version.h.in similarity index 55% rename from src/anbox/version.cpp rename to src/anbox/build/version.h.in index 8759db7..da4a288 100644 --- a/src/anbox/version.cpp +++ b/src/anbox/build/version.h.in @@ -17,11 +17,22 @@ * */ -#include "anbox/version.h" +#ifndef ANBOX_VERSION_H_ +#define ANBOX_VERSION_H_ -void anbox::version(std::uint32_t& major, std::uint32_t& minor, - std::uint32_t& patch) { - major = anbox::build::version_major; - minor = anbox::build::version_minor; - patch = anbox::build::version_patch; -} +#include +#include + +namespace anbox { +namespace build { +/// @brief version_major marks the major version +static constexpr const std::uint32_t version_major{@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 const std::string version_suffix{"@VERSION_SUFFIX@"}; +/// @brief version queries the version of Anbox +std::string version(); +} // namespace build +} // namespace anbox + +#endif // ANBOX_VERSION_H_ diff --git a/src/anbox/cmds/system_info.cpp b/src/anbox/cmds/system_info.cpp index 421f11c..d503cc0 100644 --- a/src/anbox/cmds/system_info.cpp +++ b/src/anbox/cmds/system_info.cpp @@ -19,9 +19,9 @@ #include "anbox/graphics/emugl/RenderApi.h" #include "anbox/graphics/emugl/DispatchTables.h" #include "anbox/utils/environment_file.h" -#include "anbox/version.h" #include "anbox/logger.h" -#include "anbox/version.h" + +#include "anbox/build/version.h" #include #include @@ -50,10 +50,7 @@ class SystemInformation { std::stringstream s; s << "version: " - << anbox::utils::string_format("%d.%d.%d", - anbox::build::version_major, - anbox::build::version_minor, - anbox::build::version_patch) + << anbox::build::version() << std::endl; s << "os:" << std::endl diff --git a/src/anbox/cmds/version.cpp b/src/anbox/cmds/version.cpp index c405e48..3ce15e1 100644 --- a/src/anbox/cmds/version.cpp +++ b/src/anbox/cmds/version.cpp @@ -18,16 +18,15 @@ */ #include "anbox/cmds/version.h" -#include "anbox/version.h" +#include "anbox/build/version.h" +#include "anbox/utils.h" anbox::cmds::Version::Version() : CommandWithFlagsAndAction{ cli::Name{"version"}, cli::Usage{"version"}, cli::Description{"print the version of the daemon"}} { action([](const cli::Command::Context& ctxt) { - std::uint32_t major, minor, patch; - anbox::version(major, minor, patch); - ctxt.cout << "anbox " << major << "." << minor << "." << patch << std::endl; + ctxt.cout << "anbox " << build::version() << std::endl; return 0; }); } diff --git a/src/anbox/version.h b/src/anbox/version.h deleted file mode 100644 index 11617ae..0000000 --- a/src/anbox/version.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2016 Canonical, Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Authored by: Thomas Voß - * - */ - -#ifndef ANBOX_VERSION_H_ -#define ANBOX_VERSION_H_ - -#include - -namespace anbox { -namespace build { -/// @brief version_major marks the major version of the library. The constant is -/// meant to be used -/// by client code both at build and runtime, enabling version checks. -static constexpr const std::uint32_t version_major{0}; -/// @brief version_major marks the minor version of the library. The constant is -/// meant to be used -/// by client code both at build and runtime, enabling version checks. -static constexpr const std::uint32_t version_minor{1}; -/// @brief version_patch marks the major version of the library. The constant is -/// meant to be used -/// by client code both at build and runtime, enabling version checks. -static constexpr const std::uint32_t version_patch{0}; -} // namespace build - -/// @brief version queries the version of the library, placing the result in -/// major, minor and patch. -void version(std::uint32_t& major, std::uint32_t& minor, std::uint32_t& patch); -} // namespace build - -#endif // ANBOX_VERSION_H_