From 756ea5b70410c533fdd6f4877fcb3d3edc011b89 Mon Sep 17 00:00:00 2001 From: jcm <6864788+jcm93@users.noreply.github.com> Date: Thu, 8 May 2025 16:21:39 -0500 Subject: [PATCH] build: Do not require tags, add unofficial versioning scheme --- .gitattributes | 2 +- .github/workflows/build.yml | 7 +++ .github/workflows/pr.yml | 2 + .github/workflows/push.yml | 1 + CMakePresets.json | 3 +- cmake/common/.archive-version | 1 - cmake/common/.archive-version.json | 6 ++ cmake/common/helpers_common.cmake | 4 +- cmake/common/versionconfig.cmake | 99 +++++++++++++++++++++--------- 9 files changed, 90 insertions(+), 35 deletions(-) delete mode 100644 cmake/common/.archive-version create mode 100644 cmake/common/.archive-version.json diff --git a/.gitattributes b/.gitattributes index 7d734bfdc..fb91f35ab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ # When archiving, export a version file containing tag/commit information -cmake/common/.archive-version export-subst +cmake/common/.archive-version.json export-subst diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f944908f6..c6341cf90 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,11 @@ on: required: false default: false type: boolean + official: + description: Use official version strings + required: true + default: true + type: boolean jobs: build: strategy: @@ -77,6 +82,7 @@ jobs: if: runner.os != 'macOS' && runner.os != 'Linux' run: .github/scripts/build_windows.sh env: + ARES_BUILD_OFFICIAL: ${{ inputs.official }} ARES_PLATFORM_NAME: ${{ matrix.platform.name }} CROSS_COMPILE: ${{ matrix.platform.native-cmake-preset != '' }} NATIVE_PRESET: ${{ matrix.platform.native-cmake-preset }} @@ -95,6 +101,7 @@ jobs: if: runner.os == 'macOS' run: .github/scripts/build_macos.sh env: + ARES_BUILD_OFFICIAL: ${{ inputs.official }} TARGET_PRESET: ${{ matrix.platform.target-cmake-preset }} MACOS_CERTIFICATE_NAME: ${{ secrets.MACOS_CERTIFICATE_NAME }} MACOS_NOTARIZATION_TEAMID: ${{ secrets.MACOS_NOTARIZATION_TEAMID }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 5602b94de..c9fe33c35 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -15,6 +15,8 @@ jobs: uses: ./.github/workflows/build.yml permissions: contents: read + with: + official: false build-aux: name: Build ares (auxiliary) uses: ./.github/workflows/build-aux.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 96cc3be34..2a6fbffa1 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -13,6 +13,7 @@ jobs: secrets: inherit with: codesign: true + official: ${{ github.ref_name == 'master' || github.ref_type == 'tag' }} build-aux: name: Build ares (auxiliary) uses: ./.github/workflows/build-aux.yml diff --git a/CMakePresets.json b/CMakePresets.json index 1083d1263..58dfa3594 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -12,7 +12,8 @@ "cacheVariables": { "ARES_PROFILE_ACCURACY": false, "ARES_BUILD_LOCAL": true, - "ENABLE_CCACHE": true + "ENABLE_CCACHE": true, + "ARES_BUILD_OFFICIAL": {"type": "BOOL", "value": "$penv{ARES_BUILD_OFFICIAL}"} } }, { diff --git a/cmake/common/.archive-version b/cmake/common/.archive-version deleted file mode 100644 index fffea7027..000000000 --- a/cmake/common/.archive-version +++ /dev/null @@ -1 +0,0 @@ -$Format:%(describe:tags,exclude=nightly)$ diff --git a/cmake/common/.archive-version.json b/cmake/common/.archive-version.json new file mode 100644 index 000000000..5c80c1609 --- /dev/null +++ b/cmake/common/.archive-version.json @@ -0,0 +1,6 @@ +{ + "describe": "$Format:%(describe:tags,exclude=nightly)$", + "hash": "$Format:%h$", + "ref-name": "$Format:%D$", + "commit-date": "$Format:%cs$" +} diff --git a/cmake/common/helpers_common.cmake b/cmake/common/helpers_common.cmake index 2d4b92ca1..e325b1c39 100644 --- a/cmake/common/helpers_common.cmake +++ b/cmake/common/helpers_common.cmake @@ -33,8 +33,8 @@ function(message_configuration) " .. .:::. / __ `/ ___/ _ \\/ ___/\n" " .-:::::::: / /_/ / / / __(__ )\n" " .::::. \\__,_/_/ \\___/____/\n" - "\n ares version: ${ARES_VERSION}\n" - "==================================================================================\n\n" + "\n ares version: ${ARES_VERSION} (${ARES_VERSION_CANONICAL})\n" + "==================================================================================" ) get_property(ARES_FEATURES_ENABLED GLOBAL PROPERTY ARES_FEATURES_ENABLED) diff --git a/cmake/common/versionconfig.cmake b/cmake/common/versionconfig.cmake index 8b1750974..f34da5e76 100644 --- a/cmake/common/versionconfig.cmake +++ b/cmake/common/versionconfig.cmake @@ -1,55 +1,94 @@ include_guard(GLOBAL) -function(populate_ares_version_info) +option(ARES_BUILD_OFFICIAL "Use official project versioning" OFF) + +function(ares_populate_version_info) if(DEFINED ARES_VERSION_OVERRIDE) set(ARES_VERSION ${ARES_VERSION_OVERRIDE}) elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") execute_process( - COMMAND git describe --always --tags --exclude=nightly --dirty=-modified + COMMAND git describe --always --tags --exclude=nightly --dirty=-modified --match "v[0-9]*" OUTPUT_VARIABLE ARES_VERSION - ERROR_VARIABLE git_describe_err WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE ares_version_result OUTPUT_STRIP_TRAILING_WHITESPACE ) - - if(git_describe_err) - message(FATAL_ERROR "Could not fetch ares version tag from git.\n" ${git_describe_err}) + if(ARES_VERSION MATCHES "^.*modified") + set(modified YES) endif() else() - file(READ cmake/common/.archive-version ares_tarball_version) - string(STRIP "${ares_tarball_version}" ares_tarball_version) - set(ARES_VERSION "${ares_tarball_version}") + file(READ cmake/common/.archive-version.json archive_version_json) + string(JSON archive_version_describe GET ${archive_version_json} describe) + string(JSON ares_git_ref GET ${archive_version_json} ref-name) + string(JSON ares_git_shorthash GET ${archive_version_json} hash) + string(JSON ares_git_commit_date GET ${archive_version_json} commit-date) + if(archive_version_describe) + set(ARES_VERSION "${archive_version_describe}") + else() + set(ARES_VERSION "${ares_git_shorthash}") + endif() + string(STRIP "${ARES_VERSION}" ARES_VERSION) endif() - + string(REGEX REPLACE "^v([0-9]+(\\.[0-9]+)*)-.*" "\\1" ares_version_stripped "${ARES_VERSION}") string(REPLACE "." ";" ares_version_parts "${ares_version_stripped}") list(LENGTH ares_version_parts ares_version_parts_length) - list(GET ares_version_parts 0 major) + list(GET ares_version_parts 0 minor) if(ares_version_parts_length GREATER 1) - list(GET ares_version_parts 1 minor) - else() - set(minor 0) - endif() - if(ares_version_parts_length GREATER 2) - list(GET ares_version_parts 2 patch) + list(GET ares_version_parts 1 patch) else() set(patch 0) endif() - set(ARES_VERSION_CANONICAL "${major}.${minor}.${patch}") + set(ARES_VERSION_CANONICAL "0.${minor}.${patch}") message(DEBUG "Canonical version set to ${ARES_VERSION_CANONICAL}") + + set( + ares_version_not_found_string + "Could not derive a canonical version string from available version information ('${ARES_VERSION}')." + ) + + if(NOT ARES_VERSION_CANONICAL MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$") + if(ARES_BUILD_OFFICIAL) + message(FATAL_ERROR "${ares_version_not_found_string}") + else() + message(STATUS "${ares_version_not_found_string} - using fallback version 0.0.0") + endif() + set(ARES_VERSION_CANONICAL 0.0.0) + endif() + + if(NOT ARES_BUILD_OFFICIAL) + # Disambiguate unofficial builds + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") + execute_process( + COMMAND git rev-parse --short HEAD + OUTPUT_VARIABLE ares_git_shorthash + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + COMMAND git symbolic-ref -q --short HEAD + OUTPUT_VARIABLE ares_git_ref + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + COMMAND git show -s --format=%cs + OUTPUT_VARIABLE ares_git_commit_date + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + if(modified) + set(ares_git_shorthash "${ares_git_shorthash}-modified") + endif() + if(NOT ares_git_ref) + set(ARES_VERSION "${ares_git_shorthash} - ${ares_git_commit_date}") + else() + set(ARES_VERSION "${ares_git_ref} - (${ares_git_shorthash} - ${ares_git_commit_date})") + endif() + endif() + return(PROPAGATE ARES_VERSION ARES_VERSION_CANONICAL) endfunction() -populate_ares_version_info() - -if(NOT ARES_VERSION_CANONICAL MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$") - message( - FATAL_ERROR - "Available ares version information ('${ARES_VERSION}') could not be converted to a valid CMake version string.\n" - "Make sure the repository you have cloned or archived from contains ares version tags ('git fetch --tags').\n" - "If tags are unavailable, you may specify a custom version with ARES_VERSION_OVERRIDE, using an ares-formatted " - "version string, e.g. 'v123'.\n" - ) -endif() - +ares_populate_version_info()