diff --git a/CMakeLists.txt b/CMakeLists.txt index a863d861..da9dbdc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,13 @@ include(FetchContent) include(ExternalProject) include(GNUInstallDirs) -set(GIT_DESC "" CACHE STRING "Version to show in UI (from git if empty)") -set(GIT_COMMIT "" CACHE STRING "Git SHA used to fetch client APK (from git if empty)") +set(GIT_TAG "" CACHE STRING "Build for a tag (from git if empty)") +set(GIT_DESC "" CACHE STRING "Version to show in UI (from git if empty, exclusive with GIT_TAG)") +set(GIT_COMMIT "" CACHE STRING "Git SHA used to fetch client APK (from git if empty, exclusive with GIT_TAG)") + +if (GIT_TAG AND (GIT_DESC OR GIT_COMMIT)) + message(FATAL_ERROR "cannot use GIT_DESC or GIT_COMMIT when using GIT_TAG") +endif() option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON) option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON) @@ -288,6 +293,7 @@ add_custom_target(wivrn-version ALL -D OUTPUT_FILE=${CMAKE_BINARY_DIR}/version.cpp -D INPUT_FILE_1=${CMAKE_CURRENT_SOURCE_DIR}/server/u_git_tag.cpp.in -D OUTPUT_FILE_1=${CMAKE_BINARY_DIR}/u_git_tag.cpp + -D GIT_TAG="${GIT_TAG}" -D GIT_DESC="${GIT_DESC}" -D GIT_COMMIT="${GIT_COMMIT}" -P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake diff --git a/client/libcurl.cpp b/client/libcurl.cpp index 642d99e8..3f1e75cf 100644 --- a/client/libcurl.cpp +++ b/client/libcurl.cpp @@ -95,7 +95,7 @@ void libcurl::curl_thread_fn() }; #endif - std::string user_agent = std::string("WiVRn/") + wivrn::git_version; + std::string user_agent = std::string("WiVRn/") + wivrn::display_version(); // We can't use auto here because of curl_easy_setopt size_t (*write_callback)(void *, size_t, size_t, void *) = [](void * buffer, size_t size, size_t nmemb, void * userp) -> size_t { diff --git a/cmake/GitVersion.cmake b/cmake/GitVersion.cmake index 30e28d2f..9c86e15c 100644 --- a/cmake/GitVersion.cmake +++ b/cmake/GitVersion.cmake @@ -1,32 +1,54 @@ -if (NOT GIT_DESC) +if (GIT_TAG AND (GIT_DESC OR GIT_COMMIT)) + message(FATAL_ERROR "cannot use GIT_DESC or GIT_COMMIT when using GIT_TAG") +endif() + +if (NOT (GIT_TAG OR GIT_DESC OR GIT_COMMIT)) execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --always - OUTPUT_VARIABLE GIT_DESC + COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags + OUTPUT_VARIABLE GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - string(STRIP "${GIT_DESC}" GIT_DESC) - message(STATUS "Setting version to ${GIT_DESC} from git") +endif() + +if (GIT_TAG) + set(GIT_DESC "${GIT_TAG}") + set(GIT_COMMIT "${GIT_TAG}") + set(GIT_TAG true) + + message(STATUS "Building for git tag ${GIT_DESC}") else() - message(STATUS "Setting version to ${GIT_DESC} from parameters") -endif() + if (NOT GIT_DESC) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --always + OUTPUT_VARIABLE GIT_DESC + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + message(STATUS "Setting version to ${GIT_DESC} from git") + else() + message(STATUS "Setting version to ${GIT_DESC} from parameters") + endif() -if (NOT GIT_COMMIT) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse HEAD - OUTPUT_VARIABLE GIT_COMMIT - ERROR_QUIET - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - string(STRIP "${GIT_COMMIT}" GIT_COMMIT) -endif() + if (NOT GIT_COMMIT) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + OUTPUT_VARIABLE GIT_COMMIT + ERROR_QUIET + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + string(STRIP "${GIT_COMMIT}" GIT_COMMIT) + endif() -if (NOT GIT_DESC) - message(FATAL_ERROR "GIT_DESC cannot be inferred from .git and was not provided at build time") -endif() + if (NOT GIT_DESC) + message(FATAL_ERROR "GIT_DESC cannot be inferred from .git and was not provided at build time") + endif() -if (GIT_COMMIT) - message(STATUS "Setting commit to ${GIT_COMMIT}") -else() - message(FATAL_ERROR "GIT_COMMIT cannot be inferred from .git and was not provided at build time") + if (GIT_COMMIT) + message(STATUS "Setting commit to ${GIT_COMMIT}") + else() + message(FATAL_ERROR "GIT_COMMIT cannot be inferred from .git and was not provided at build time") + endif() + set(GIT_TAG false) endif() configure_file(${INPUT_FILE} ${OUTPUT_FILE}) diff --git a/common/version.cpp.in b/common/version.cpp.in index 06b78254..e9a9bcf4 100644 --- a/common/version.cpp.in +++ b/common/version.cpp.in @@ -20,19 +20,22 @@ #include #include +static const char git_desc[] = "@GIT_DESC@"; + namespace wivrn { - extern const char git_version[]; - const char git_version[] = "@GIT_DESC@"; - extern const char git_commit[]; - const char git_commit[] = "@GIT_COMMIT@"; +extern const char git_commit[]; +const char git_commit[] = "@GIT_COMMIT@"; -const char* display_version() +extern const bool is_tag; +const bool is_tag = @GIT_TAG@; + +const char * display_version() { - if (std::size(git_version) > 2 and git_version[0] == 'v' and isdigit(git_version[1])) - return git_version + 1; + if (std::size(git_desc) > 2 and git_desc[0] == 'v' and isdigit(git_desc[1])) + return git_desc + 1; else - return git_version; -} + return git_desc; } +} // namespace wivrn diff --git a/common/version.h b/common/version.h index 77c60887..b6d8610a 100644 --- a/common/version.h +++ b/common/version.h @@ -2,8 +2,8 @@ namespace wivrn { -extern const char git_version[]; extern const char git_commit[]; +extern const bool is_tag; const char * display_version(); } // namespace wivrn diff --git a/dashboard/apk_installer.cpp b/dashboard/apk_installer.cpp index d44ca86b..8a1d7436 100644 --- a/dashboard/apk_installer.cpp +++ b/dashboard/apk_installer.cpp @@ -23,21 +23,17 @@ #include #include #include -#include using namespace std::chrono_literals; apk_installer::apk_installer() { - if (isTagged()) - m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_version) + ".apk"); - else - m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_commit) + ".apk"); + m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_commit) + ".apk"); } bool apk_installer::isTagged() const { - return not std::regex_match(wivrn::git_version, std::regex(".*-g[0-9a-f]+")); + return wivrn::is_tag; } QString apk_installer::currentVersion() const @@ -74,7 +70,7 @@ QCoro::Task<> apk_installer::doRefreshLatestVersion() QUrl metadata_url; if (isTagged()) - metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn/releases/tags/"} + wivrn::git_version; + metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn/releases/tags/"} + wivrn::git_commit; else metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn-APK/releases/tags/apk-"} + wivrn::git_commit; diff --git a/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in index ababa44f..48ada9bc 100644 --- a/flatpak/io.github.wivrn.wivrn.yml.in +++ b/flatpak/io.github.wivrn.wivrn.yml.in @@ -349,6 +349,7 @@ modules: - -DWIVRN_WERROR=ON - -DFETCHCONTENT_FULLY_DISCONNECTED=ON - -DFETCHCONTENT_BASE_DIR=deps + - -DGIT_TAG=WIVRN_GIT_TAG - -DGIT_DESC=WIVRN_GIT_DESC - -DGIT_COMMIT=WIVRN_GIT_COMMIT - -Wno-dev @@ -385,6 +386,7 @@ modules: - -DWIVRN_FEATURE_STEAMVR_LIGHTHOUSE=OFF - -DFETCHCONTENT_FULLY_DISCONNECTED=ON - -DFETCHCONTENT_BASE_DIR=deps + - -DGIT_TAG=WIVRN_GIT_TAG - -DGIT_DESC=WIVRN_GIT_DESC - -DGIT_COMMIT=WIVRN_GIT_COMMIT - -Wno-dev diff --git a/tools/gen_flatpak_manifest.py b/tools/gen_flatpak_manifest.py index 3c1f941f..54058799 100755 --- a/tools/gen_flatpak_manifest.py +++ b/tools/gen_flatpak_manifest.py @@ -63,20 +63,23 @@ if __name__ == "__main__": boost_sha256 = cmake.get("boost", "URL_HASH").split("=")[-1] try: - git_commit = subprocess.check_output( + git_tag = subprocess.check_output( ["git", "describe", "--exact-match", "--tags"], cwd=root, stderr=subprocess.DEVNULL ).decode().strip() + git_commit = "" + git_desc = "" except subprocess.CalledProcessError: + git_tag = "" git_commit = subprocess.check_output( ["git", "rev-parse", "HEAD"], cwd=root ).decode().strip() - git_desc = subprocess.check_output( - ["git", "describe", "--tags", "--always"], - cwd=root - ).decode().strip() + git_desc = subprocess.check_output( + ["git", "describe", "--tags", "--always"], + cwd=root + ).decode().strip() if args.git or args.gitlocal: template = template.replace("WIVRN_SRC1", "type: git") @@ -90,6 +93,7 @@ if __name__ == "__main__": template = template.replace("WIVRN_SRC2", f"path: {root}") template = template.replace("WIVRN_SRC3", "") + template = template.replace("WIVRN_GIT_TAG", git_tag) template = template.replace("WIVRN_GIT_DESC", git_desc) template = template.replace("WIVRN_GIT_COMMIT", git_commit)