add fallback for embedded commit string for source archives

This commit is contained in:
tobtoht 2022-02-10 23:16:43 +01:00
parent 9521185520
commit 8a2e92b6f9
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
4 changed files with 19 additions and 31 deletions

View file

@ -1,39 +1,27 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2020, The Monero Project. # SPDX-FileCopyrightText: 2020-2022 The Monero Project
find_package(Git QUIET) find_package(Git QUIET)
# Check what commit we're on # Sets FEATHER_COMMIT to the first 9 chars of the current commit hash.
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short=9 HEAD RESULT_VARIABLE RET OUTPUT_VARIABLE COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
if(RET) if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/githash.txt")
# Something went wrong, set the version tag to -unknown # This file added in source archives where the .git folder has been removed to optimize for space.
file(READ "githash.txt" COMMIT)
message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.")
set(FEATHER_BRANCH "unknown")
configure_file("cmake/config-feather.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/src/config-feather.h")
else()
string(SUBSTRING ${COMMIT} 0 9 COMMIT) string(SUBSTRING ${COMMIT} 0 9 COMMIT)
message(STATUS "You are currently on commit ${COMMIT}") message(STATUS "You are currently on commit ${COMMIT}")
set(FEATHER_COMMIT "${COMMIT}")
else()
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short=9 HEAD RESULT_VARIABLE RET OUTPUT_VARIABLE COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
# Get all the tags if(RET)
execute_process(COMMAND "${GIT}" rev-list --tags --max-count=1 --abbrev-commit RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMIT OUTPUT_STRIP_TRAILING_WHITESPACE) message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.")
set(FEATHER_COMMIT "unknown")
if(NOT TAGGEDCOMMIT)
message(STATUS "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.")
set(FEATHER_BRANCH "${COMMIT}")
else() else()
message(STATUS "The most recent tag was at ${TAGGEDCOMMIT}") string(SUBSTRING ${COMMIT} 0 9 COMMIT)
message(STATUS "You are currently on commit ${COMMIT}")
# Check if we're building that tagged commit or a different one set(FEATHER_COMMIT "${COMMIT}")
if(COMMIT STREQUAL TAGGEDCOMMIT)
message(STATUS "You are building a tagged release")
set(FEATHER_BRANCH "release")
else()
message(STATUS "You are ahead of or behind a tagged release")
set(FEATHER_BRANCH "${COMMIT}")
endif()
endif() endif()
configure_file("cmake/config-feather.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/src/config-feather.h")
endif() endif()
configure_file("cmake/config-feather.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/src/config-feather.h")

View file

@ -2,7 +2,7 @@
#define FEATHER_VERSION_H #define FEATHER_VERSION_H
#define FEATHER_VERSION "@VERSION@" #define FEATHER_VERSION "@VERSION@"
#define FEATHER_BRANCH "@FEATHER_BRANCH@" #define FEATHER_COMMIT "@FEATHER_COMMIT@"
#define TOR_VERSION "@TOR_VERSION@" #define TOR_VERSION "@TOR_VERSION@"

View file

@ -19,7 +19,7 @@ AboutDialog::AboutDialog(QWidget *parent)
auto about = Utils::fileOpenQRC(":assets/about.txt"); auto about = Utils::fileOpenQRC(":assets/about.txt");
auto about_text = Utils::barrayToString(about); auto about_text = Utils::barrayToString(about);
about_text = about_text.replace("<feather_version>", FEATHER_VERSION); about_text = about_text.replace("<feather_version>", FEATHER_VERSION);
about_text = about_text.replace("<feather_git_head>", FEATHER_BRANCH); about_text = about_text.replace("<feather_git_head>", FEATHER_COMMIT);
about_text = about_text.replace("<current_year>", QString::number(QDate::currentDate().year())); about_text = about_text.replace("<current_year>", QString::number(QDate::currentDate().year()));
ui->copyrightText->setPlainText(about_text); ui->copyrightText->setPlainText(about_text);

View file

@ -45,7 +45,7 @@ void DebugInfoDialog::updateInfo() {
else else
torStatus = "Unknown"; torStatus = "Unknown";
ui->label_featherVersion->setText(QString("%1-%2").arg(FEATHER_VERSION, FEATHER_BRANCH)); ui->label_featherVersion->setText(QString("%1-%2").arg(FEATHER_VERSION, FEATHER_COMMIT));
ui->label_walletHeight->setText(QString::number(m_ctx->wallet->blockChainHeight())); ui->label_walletHeight->setText(QString::number(m_ctx->wallet->blockChainHeight()));
ui->label_daemonHeight->setText(QString::number(m_ctx->wallet->daemonBlockChainHeight())); ui->label_daemonHeight->setText(QString::number(m_ctx->wallet->daemonBlockChainHeight()));