Put version info into a compiled file

This rewrites the version info using lokid's approach of compiling it
into a .cpp file that gets generated as part of the build (*not* during
the configure stage).

Among other things, this means that changing the version no longer
invalidates ccache or cmake dependencies, and because it depends on
`.git/index` git commits will cause the version to be regenerated,
making the commit tag more reliable (currently if you rebuild without
running cmake your git commit tag doesn't update).
pull/965/head
Jason Rhinelander 5 years ago
parent 99d27a4886
commit 638fb25b47

@ -208,15 +208,6 @@ if(SHADOW)
include(cmake/shadow.cmake)
endif(SHADOW)
if(NOT GIT_VERSION)
exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_VERSION_UNSTRIP)
string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION)
endif(NOT GIT_VERSION)
string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}")
add_definitions("-DGIT_REV=\"${GIT_VERSION_REAL}\"")
# HeapAlloc(2) on Windows was significantly revamped in 2009
# but the old algorithm isn't too bad either

@ -0,0 +1,61 @@
# Copyright (c) 2014-2019, The Monero Project
# Copyright (c) 2019, The Loki Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
# Check what commit we're on
execute_process(COMMAND "${GIT}" rev-parse --short=9 HEAD RESULT_VARIABLE RET OUTPUT_VARIABLE COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
if(RET)
# Something went wrong, set the version tag to -unknown
message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.")
set(VERSIONTAG "unknown")
else()
string(SUBSTRING ${COMMIT} 0 9 COMMIT)
message(STATUS "You are currently on commit ${COMMIT}")
# Get all the tags
execute_process(COMMAND "${GIT}" rev-list --tags --max-count=1 --abbrev-commit RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT TAGGEDCOMMIT)
message(WARNING "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.")
set(VERSIONTAG "${COMMIT}")
else()
# Check if we're building that tagged commit or a different one
if(COMMIT STREQUAL TAGGEDCOMMIT)
message(STATUS "${COMMIT} is a tagged release; setting version tag to 'release'")
set(VERSIONTAG "release")
else()
message(STATUS "You are not building a tagged release; setting version tag to '${COMMIT}'")
set(VERSIONTAG "${COMMIT}")
endif()
endif()
endif()
configure_file("${SRC}" "${DEST}")

@ -0,0 +1,21 @@
find_package(Git QUIET)
if(GIT_FOUND OR Git_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp"
COMMAND "${CMAKE_COMMAND}"
"-D" "GIT=${GIT_EXECUTABLE}"
"-D" "SRC=${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in"
"-D" "DEST=${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp"
"-P" "${CMAKE_CURRENT_LIST_DIR}/GenVersion.cmake"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/../.git/index")
else()
message(WARNING "Git was not found! Setting version to to nogit")
set(VERSIONTAG "nogit")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp")
endif()
add_custom_target(genversion DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp")

@ -22,6 +22,9 @@ else()
add_executable(${EXE} ${EXE_SRC})
add_executable(${CTL} ${CTL_SRC})
target_compile_definitions(${EXE} PRIVATE -DVERSIONTAG=${VERSIONTAG})
target_compile_definitions(${CTL} PRIVATE -DVERSIONTAG=${VERSIONTAG})
add_log_tag(${EXE})
add_log_tag(${CTL})

@ -1,3 +1,5 @@
include(Version)
set(LIB_UTIL_SRC
config/config.cpp
config/ini.cpp
@ -7,7 +9,7 @@ set(LIB_UTIL_SRC
constants/link_layer.cpp
constants/path.cpp
constants/proto.cpp
constants/version.cpp
${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp
util/aligned.cpp
util/bencode.cpp
util/bits.cpp
@ -58,6 +60,9 @@ set(LIB_UTIL_SRC
)
add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC})
add_dependencies(${UTIL_LIB} genversion)
target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include)
if(ANDROID)
set(LOG_LIB log)

@ -1,6 +0,0 @@
#include <constants/version.hpp>
#ifndef LLARP_DEFAULT_NETID
#define LLARP_DEFAULT_NETID "gamma"
#endif
const char Version::LLARP_NET_ID[] = LLARP_DEFAULT_NETID;

@ -0,0 +1,19 @@
#include <constants/version.hpp>
#include <constants/version.h>
#define LLARP_STRINGIFY2(val) #val
#define LLARP_STRINGIFY(val) LLARP_STRINGIFY2(val)
#define LLARP_VERSION_STR LLARP_STRINGIFY(LLARP_VERSION_MAJ) "." LLARP_STRINGIFY(LLARP_VERSION_MIN) "." LLARP_STRINGIFY(LLARP_VERSION_PATCH)
#define LLARP_VERSION_FULL LLARP_VERSION_STR "-@VERSIONTAG@"
namespace llarp
{
const std::array<uint16_t, 3> VERSION{{LLARP_VERSION_MAJ, LLARP_VERSION_MIN, LLARP_VERSION_PATCH}};
const char* const VERSION_STR = LLARP_VERSION_STR;
const char* const VERSION_TAG = "@VERSIONTAG@";
const char* const VERSION_FULL = LLARP_NAME "-" LLARP_VERSION_STR "-@VERSIONTAG@";
const char* const RELEASE_MOTTO = LLARP_RELEASE_MOTTO;
const char* const DEFAULT_NETID = LLARP_DEFAULT_NETID;
}

@ -0,0 +1,27 @@
#pragma once
// Don't include this file directly but rather go through version.hpp instead. This is only here so
// version.cpp.in and the weird archaic windows build recipies can use the version.
#define LLARP_NAME "lokinet"
#define LLARP_VERSION_MAJ 0
#define LLARP_VERSION_MIN 6
#define LLARP_VERSION_PATCH 0
#define LLARP_DEFAULT_NETID "gamma"
#ifndef LLARP_RELEASE_MOTTO
#define LLARP_RELEASE_MOTTO "(dev build)"
#endif
#if defined(_WIN32) && defined(RC_INVOKED)
#define LLARP_VERSION \
LLARP_VERSION_MAJ, LLARP_VERSION_MIN, LLARP_VERSION_PATCH, 0
#define MAKE_TRIPLET(X,Y,Z) TRIPLET_CAT(X,.,Y,.,Z)
#define TRIPLET_CAT(X,D1,Y,D2,Z) X##D1##Y##D2##Z
#define LLARP_VERSION_TRIPLET MAKE_TRIPLET(LLARP_VERSION_MAJ, LLARP_VERSION_MIN, LLARP_VERSION_PATCH)
#endif

@ -1,42 +1,16 @@
#ifndef LLARP_VERSION_HPP
#define LLARP_VERSION_HPP
#pragma once
#ifndef LLARP_VERSION_MAJ
#define LLARP_VERSION_MAJ 0
#endif
#include <cstdint>
#include <array>
#ifndef LLARP_VERSION_MIN
#define LLARP_VERSION_MIN 6
#endif
#ifndef LLARP_VERSION_PATCH
#define LLARP_VERSION_PATCH 0
#endif
#ifndef LLARP_VERSION_NUM
#ifdef GIT_REV
#define LLARP_VERSION_NUM \
"-LLARP_VERSION_MAJ.LLARP_VERSION_MIN.LLARP_VERSION_PATCH" \
"-" GIT_REV
#else
#define LLARP_VERSION_NUM \
"-LLARP_VERSION_MAJ.LLARP_VERSION_MIN.LLARP_VERSION_PATCH"
#endif
#endif
#if defined(_WIN32) && defined(RC_INVOKED)
#define LLARP_VERSION \
LLARP_VERSION_MAJ, LLARP_VERSION_MIN, LLARP_VERSION_PATCH, 0
#else
#define LLARP_VERSION "lokinet" LLARP_VERSION_NUM
#endif
#ifndef LLARP_RELEASE_MOTTO
#define LLARP_RELEASE_MOTTO "(dev build)"
#endif
struct Version
namespace llarp
{
static const char LLARP_NET_ID[];
};
#endif
// Given a full lokinet version of: lokinet-1.2.3-abc these are:
extern const std::array<uint16_t, 3> VERSION; // [1, 2, 3]
extern const char* const VERSION_STR; // "1.2.3"
extern const char* const VERSION_TAG; // "abc"
extern const char* const VERSION_FULL; // "lokinet-1.2.3-abc"
extern const char* const RELEASE_MOTTO;
extern const char* const DEFAULT_NETID;
}

@ -200,7 +200,7 @@ __ ___ ____ _ _ ___ _ _ ____
int
Context::Setup()
{
llarp::LogInfo(LLARP_VERSION, " ", LLARP_RELEASE_MOTTO);
llarp::LogInfo(llarp::VERSION_FULL, " ", llarp::RELEASE_MOTTO);
llarp::LogInfo("starting up");
mainloop = llarp_make_ev_loop();
@ -513,7 +513,7 @@ extern "C"
const char *
llarp_version()
{
return LLARP_VERSION;
return llarp::VERSION_FULL;
}
ssize_t

@ -357,11 +357,11 @@ namespace llarp
{
// Set netid before anything else
if(!conf->router.netId().empty()
&& strcmp(conf->router.netId().c_str(), Version::LLARP_NET_ID))
&& strcmp(conf->router.netId().c_str(), llarp::DEFAULT_NETID))
{
const auto &netid = conf->router.netId();
llarp::LogWarn("!!!! you have manually set netid to be '", netid,
"' which does not equal '", Version::LLARP_NET_ID,
"' which does not equal '", llarp::DEFAULT_NETID,
"' you will run as a different network, good luck "
"and don't forget: something something MUH traffic "
"shape correlation !!!!");

@ -19,7 +19,7 @@ namespace llarp
NetID::DefaultValue()
{
static NetID defaultID(
reinterpret_cast< const byte_t * >(Version::LLARP_NET_ID));
reinterpret_cast< const byte_t * >(llarp::DEFAULT_NETID));
return defaultID;
}

@ -200,8 +200,7 @@ namespace llarp
AsyncLokiPing()
{
LogInfo("Pinging Lokid");
nlohmann::json version(
{LLARP_VERSION_MAJ, LLARP_VERSION_MIN, LLARP_VERSION_PATCH});
nlohmann::json version(llarp::VERSION);
nlohmann::json params({{"version", version}});
QueueRPC("lokinet_ping", std::move(params),
util::memFn(&CallerImpl::NewLokinetPingConn, this));
@ -371,7 +370,7 @@ namespace llarp
Response
DumpVersion() const
{
const Response resp{{"version", LLARP_VERSION}};
const Response resp{{"version", llarp::VERSION_FULL}};
return resp;
}

@ -1,126 +0,0 @@
// WARNING: for the love of all that is good and holy
// please DO NOT convert this file to UTF-8, much less
// UTF-16 - the UNIX cross-rc does not understand UTF-16,
// and UTF-8 chews up the copyright symbols.
// -rick
//
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#include <constants/version.hpp>
#ifdef __GNUC__
#include <winresrc.h>
#endif
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#define STRINGIZER(version) #version
#ifdef LLARP_RELEASE_MOTTO
#define VERSION_STRING(version, codename, revision) \
STRINGIZER(version) "-release [" STRINGIZER(codename) "] (rev-" STRINGIZER(revision) ")"
#else
#define VERSION_STRING(version, revision) \
STRINGIZER(version) STRINGIZER(revision)
#endif
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 1033,1
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION LLARP_VERSION
PRODUCTVERSION LLARP_VERSION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x3L
#else
FILEFLAGS 0x2L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "libabyss JSON-RPC daemon demo"
VALUE "CompanyName", "Loki Foundation"
VALUE "FileDescription", "LokiNET for Microsoft® Windows® NT™"
#ifdef LLARP_RELEASE_MOTTO
VALUE "FileVersion", VERSION_STRING(0.5.2, RELEASE_MOTTO, GIT_REV)
#else
VALUE "FileVersion", VERSION_STRING(0.5.2-dev-, GIT_REV)
#endif
VALUE "InternalName", "llarpd"
VALUE "LegalCopyright", "Copyright ©2018-2019 Jeff Becker, Rick V for the Loki Foundation. All rights reserved. This software is provided under the terms of the zlib-libpng licence; see the file LICENSE for details."
VALUE "OriginalFilename", "abyss-main.exe"
VALUE "ProductName", "LokiNET for Windows"
#ifdef LLARP_RELEASE_MOTTO
VALUE "ProductVersion", VERSION_STRING(0.5.2, RELEASE_MOTTO, GIT_REV)
#else
VALUE "ProductVersion", VERSION_STRING(0.5.2-dev-, GIT_REV)
#endif
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// RT_MANIFEST
//
2 RT_MANIFEST "app.xml"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

@ -7,7 +7,7 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#include <constants/version.hpp>
#include <constants/version.h>
#ifdef __GNUC__ // make windows rc accept this
#include <winresrc.h>
#endif
@ -16,13 +16,8 @@
#define STRINGIZER(version) #version
#ifdef LLARP_RELEASE_MOTTO
#define VERSION_STRING(version, codename, revision) \
STRINGIZER(version) "-release [" STRINGIZER(codename) "] (rev-" STRINGIZER(revision) ")"
#else
#define VERSION_STRING(version, revision) \
STRINGIZER(version) STRINGIZER(revision)
#endif
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
@ -80,20 +75,12 @@ BEGIN
VALUE "Comments", "includes relay/exit functionality, such code is highly experimental on non-Linux targets"
VALUE "CompanyName", "Loki Foundation"
VALUE "FileDescription", "LokiNET daemon for Microsoft® Windows® NT™"
#ifdef LLARP_RELEASE_MOTTO
VALUE "FileVersion", VERSION_STRING(0.5.2, RELEASE_MOTTO, GIT_REV)
#else
VALUE "FileVersion", VERSION_STRING(0.5.2-dev-, GIT_REV)
#endif
VALUE "FileVersion", VERSION_STRING(LLARP_VERSION_TRIPLET, LLARP_RELEASE_MOTTO, VERSIONTAG)
VALUE "InternalName", "llarpd"
VALUE "LegalCopyright", "Copyright ©2018-2019 Jeff Becker, Rick V for the Loki Foundation. All rights reserved. This software is provided under the terms of the zlib-libpng licence; see the file LICENSE for details."
VALUE "OriginalFilename", "llarpd.exe"
VALUE "ProductName", "LokiNET for Windows"
#ifdef LLARP_RELEASE_MOTTO
VALUE "ProductVersion", VERSION_STRING(0.5.2, RELEASE_MOTTO, GIT_REV)
#else
VALUE "ProductVersion", VERSION_STRING(0.5.2-dev-, GIT_REV)
#endif
VALUE "ProductVersion", VERSION_STRING(LLARP_VERSION_TRIPLET, LLARP_RELEASE_MOTTO, VERSIONTAG)
END
END
BLOCK "VarFileInfo"

Loading…
Cancel
Save