]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Simplify source package generation
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 30 Sep 2020 20:18:09 +0000 (22:18 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 1 Oct 2020 07:46:03 +0000 (09:46 +0200)
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.

.github/workflows/build.yaml
ci/build-and-verify-source-package [moved from ci/build-and-verify-package-source with 62% similarity]
cmake/CcachePackConfig.cmake
cmake/CcacheVersion.cmake
cmake/GenerateVersionFile.cmake
cmake/PreparePackage.cmake.in [deleted file]

index a6c89e3190ac261d6b4033f3e09b01b429bf0170..74859b06aa06c280f1e1cbc2c63d8b59205288ba 100644 (file)
@@ -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()
similarity index 62%
rename from ci/build-and-verify-package-source
rename to ci/build-and-verify-source-package
index d7f5f0ce89a0a4775191f4bf697d3bba1b114935..5a212c2f46501398a0a30ad6a71f9f6a11b948b4 100755 (executable)
@@ -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 ..
index 71b3d7bb759e614925d35fbd685069af2d4f0ef1..daaca306d5f26a27019a139c7176a5f6f3116455 100644 (file)
@@ -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)
index ee33816839dcd8cd28ebfd85914d72d9504a3692..eb7d7314f912cbb6a05d490b6cb9c6065168208b 100644 (file)
@@ -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()
index 66a86b37dc5a82c1452fd3b43ac1d4eab0dd6af8..1517d440b5f64cf9716e52afb3c803c6fd6dadd1 100644 (file)
@@ -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 (file)
index c2adfbc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-file(WRITE "${CMAKE_INSTALL_PREFIX}/VERSION" "@VERSION@\n")