diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2020-09-30 22:18:09 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2020-10-01 09:46:03 +0200 |
commit | a5a5804abb2b9b2c15039403fbbab80b6883f275 (patch) | |
tree | f6bf704fe46b0c45c72221699a00344e0ba8200f | |
parent | 3c33c79548874e97a3553bf6943c89638326e6f2 (diff) | |
download | ccache-a5a5804abb2b9b2c15039403fbbab80b6883f275.tar.gz |
Simplify source package generation
Since it now works to build from “git archive” archives, use such an
archive as the official source code release archive instead of using
CPack with a custom install script for modifying the source code. We can
revisit this in the future when and if we want a source code release
archive that is not simply an export of the version-controlled source
code.
-rw-r--r-- | .github/workflows/build.yaml | 6 | ||||
-rwxr-xr-x | ci/build-and-verify-source-package (renamed from ci/build-and-verify-package-source) | 16 | ||||
-rw-r--r-- | cmake/CcachePackConfig.cmake | 21 | ||||
-rw-r--r-- | cmake/CcacheVersion.cmake | 33 | ||||
-rw-r--r-- | cmake/GenerateVersionFile.cmake | 11 | ||||
-rw-r--r-- | cmake/PreparePackage.cmake.in | 1 |
6 files changed, 27 insertions, 61 deletions
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a6c89e31..74859b06 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -136,8 +136,8 @@ jobs: os: ubuntu-20.04 CC: gcc CXX: g++ - SPECIAL: build-and-verify-package-source - apt_get: elfutils libzstd-dev ninja-build + SPECIAL: build-and-verify-source-package + apt_get: elfutils libzstd-dev ninja-build asciidoc xsltproc - name: HTML documentation os: ubuntu-18.04 @@ -199,7 +199,7 @@ jobs: - name: Collect testdir from failed tests if: failure() run: ci/collect-testdir - # TODO: in case of build-and-verify-package* the BUILDDIR is set within those scripts. + # TODO: in case of build-and-verify-*package the BUILDDIR is set within those scripts. - name: Upload testdir from failed tests if: failure() diff --git a/ci/build-and-verify-package-source b/ci/build-and-verify-source-package index d7f5f0ce..5a212c2f 100755 --- a/ci/build-and-verify-package-source +++ b/ci/build-and-verify-source-package @@ -1,4 +1,7 @@ #!/bin/sh +# +# Test that it works to build from a source archive exported by "git archive" +# outside a Git repository. set -eu @@ -6,18 +9,13 @@ set -eu # without resorting to setting base_dir. export CMAKE_GENERATOR=Ninja -rm -rf build_package_source_dir_test -mkdir -p build_package_source_dir_test -cd build_package_source_dir_test -cmake .. -ninja -v package_source - tmp_dir=$(mktemp -d) trap "rm -rf $tmp_dir" EXIT -tar -xf ccache-*.tar.xz -C $tmp_dir -cd $tmp_dir/ccache-* - +git archive --prefix=ccache/ -o $tmp_dir/ccache.tar.gz HEAD +cd $tmp_dir +tar xf ccache.tar.gz +cd ccache mkdir build cd build cmake .. diff --git a/cmake/CcachePackConfig.cmake b/cmake/CcachePackConfig.cmake index 71b3d7bb..daaca306 100644 --- a/cmake/CcachePackConfig.cmake +++ b/cmake/CcachePackConfig.cmake @@ -5,7 +5,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.9") set(CPACK_PACKAGE_DESCRIPTION "${CMAKE_PROJECT_DESCRIPTION}") endif() -# From GenerateVersionFile.cmake. +# From CcacheVersion.cmake. set(CPACK_PACKAGE_VERSION ${VERSION}) set(CPACK_VERBATIM_VARIABLES ON) @@ -16,28 +16,9 @@ else() set(CPACK_GENERATOR "TXZ") endif() -set(CPACK_SOURCE_GENERATOR "TGZ;TXZ") - -list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/\\.git") -list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/build") -list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_BINARY_DIR}") - set( CPACK_PACKAGE_FILE_NAME "ccache-${VERSION}-${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}" ) -set(CPACK_SOURCE_PACKAGE_FILE_NAME "ccache-${VERSION}") - -configure_file( - ${CMAKE_SOURCE_DIR}/cmake/PreparePackage.cmake.in - ${CMAKE_BINARY_DIR}/PreparePackage.cmake - @ONLY -) - -if(${CMAKE_VERSION} VERSION_LESS "3.16") - set(CPACK_INSTALL_SCRIPT ${CMAKE_BINARY_DIR}/PreparePackage.cmake) -else() - set(CPACK_INSTALL_SCRIPTS ${CMAKE_BINARY_DIR}/PreparePackage.cmake) -endif() include(CPack) diff --git a/cmake/CcacheVersion.cmake b/cmake/CcacheVersion.cmake index ee338168..eb7d7314 100644 --- a/cmake/CcacheVersion.cmake +++ b/cmake/CcacheVersion.cmake @@ -1,25 +1,22 @@ -# There are four main scenarios: +# There are three main scenarios: # -# 1. Building from an official source code release archive. In this case the -# version is unconditionally read from the file VERSION in the top level -# directory and the code below won't be executed. -# 2. Building from an unofficial source code archive generated by "git -# archive", e.g. from a GitHub "archive download" -# (https://github.com/ccache/ccache/archive/$VERSION.tar.gz). In this case -# the version_info info string below will be substituted because of -# export-subst in the .gitattributes file. The version will then be correct -# if $VERSION refers to a tagged commit. If the commit is not tagged the -# version will be set to the commit hash instead. -# 3. Building from an unofficial source code archive not generated by "git -# archive" (i.e., version_info has not been substituted). In this case we -# fail the configuration. -# 4. Building from a Git repository. In this case the version will be a proper +# 1. Building from a source code archive generated by "git archive", e.g. the +# official source code archive or one downloaded directly from GitHub via +# <https://github.com/ccache/ccache/archive/VERSION.tar.gz>. In this case the +# version_info info string below will be substituted because of export-subst +# in the .gitattributes file. The version will then be correct if VERSION +# refers to a tagged commit. If the commit is not tagged the version will be +# set to the commit hash instead. +# 2. Building from a source code archive not generated by "git archive" (i.e., +# version_info has not been substituted). In this case we fail the +# configuration. +# 3. Building from a Git repository. In this case the version will be a proper # version if building a tagged commit, otherwise "branch.hash(+dirty)". set(version_info "$Format:%H %D$") if(version_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])[0-9a-f]* (.*)") - # Scenario 2. + # Scenario 1. set(hash "${CMAKE_MATCH_1}") set(ref_names "${CMAKE_MATCH_2}") if(ref_names MATCHES "tag: v([^,]+)") @@ -30,7 +27,7 @@ if(version_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a set(VERSION "${hash}") endif() elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git") - # Scenario 4. + # Scenario 3. find_package(Git QUIET) if(NOT GIT_FOUND) message(SEND_ERROR "Could not find git") @@ -61,6 +58,6 @@ elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git") endif() if(VERSION STREQUAL "") - # Scenario 3 or unexpected error. + # Scenario 2 or unexpected error. message(SEND_ERROR "Cannot determine Ccache version") endif() diff --git a/cmake/GenerateVersionFile.cmake b/cmake/GenerateVersionFile.cmake index 66a86b37..1517d440 100644 --- a/cmake/GenerateVersionFile.cmake +++ b/cmake/GenerateVersionFile.cmake @@ -1,15 +1,6 @@ -set(version_file ${CMAKE_SOURCE_DIR}/VERSION) - -if(EXISTS ${version_file}) - file(READ ${version_file} VERSION) - string(STRIP ${VERSION} VERSION) -else() - include(CcacheVersion) -endif() - +include(CcacheVersion) configure_file( ${CMAKE_SOURCE_DIR}/cmake/version.cpp.in ${CMAKE_BINARY_DIR}/src/version.cpp @ONLY) - message(STATUS "Ccache version: ${VERSION}") diff --git a/cmake/PreparePackage.cmake.in b/cmake/PreparePackage.cmake.in deleted file mode 100644 index c2adfbc8..00000000 --- a/cmake/PreparePackage.cmake.in +++ /dev/null @@ -1 +0,0 @@ -file(WRITE "${CMAKE_INSTALL_PREFIX}/VERSION" "@VERSION@\n") |