Skip to content

Commit 9867964

Browse files
committed
Add make dist target using CMake
- Fixes #413 - Generates release source tarball from `git archive` - Generates SHA-256 checksum file - Creates detatched PGP signature for the SHA256 checksum file, IFF - GPG is installed on the system and found - User has configured a private signing key
1 parent b2e42e8 commit 9867964

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ if((NOT (OpenCoarraysVersion MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")) AND (EXISTS "$
4747
if(NOT (git_status STREQUAL "0"))
4848
set(full_git_describe NOTFOUND)
4949
endif()
50+
# Create a source distribution target using git archive
51+
# e.g., `make dist` will package a release using current git state
52+
add_custom_target(dist # OUTPUT "${CMAKE_BINARY_DIR}/${_OC_stem_name}.tar.gz"
53+
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/makeDist.cmake" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}"
54+
COMMENT "Creating source release asset, ${_OC_stem_name}.tar.gz, from ${git_full_describe} using the `git archive` command."
55+
VERBATIM)
5056
else()
5157
message( WARNING "Could not find git executable!")
5258
endif()

cmake/makeDist.cmake

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# CMake file to be called in script mode (${CMAKE_COMMAND} -P <file>) to
2+
# Generate a source archive release asset from add_custom_command
3+
#
4+
# See SourceDistTarget.cmake
5+
6+
if(NOT CMAKE_ARGV3)
7+
message(FATAL_ERROR "Must pass the top level src dir to ${CMAKE_ARGV2} as the first argument")
8+
endif()
9+
10+
if(NOT CMAKE_ARGV4)
11+
message(FATAL_ERROR "Must pass the top level src dir to ${CMAKE_ARGV2} as the second argument")
12+
endif()
13+
14+
find_package(Git)
15+
if(NOT GIT_FOUND)
16+
message( FATAL_ERROR "You can't create a source archive release asset without git!")
17+
endif()
18+
19+
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --always
20+
RESULT_VARIABLE git_status
21+
OUTPUT_VARIABLE git_version
22+
WORKING_DIRECTORY "${CMAKE_ARGV3}"
23+
OUTPUT_STRIP_TRAILING_WHITESPACE)
24+
if(NOT (git_status STREQUAL "0"))
25+
message( FATAL_ERROR "git describe --always failed with exit status: ${git_status} and message:
26+
${git_version}")
27+
endif()
28+
29+
set(archive "OpenCoarrays-${git_version}")
30+
set(l_archive "opencoarrays-${git_version}")
31+
set(release_asset "${CMAKE_ARGV4}/${archive}.tar.gz")
32+
execute_process(
33+
COMMAND "${GIT_EXECUTABLE}" archive "--prefix=${archive}/" -o "${release_asset}" "${git_version}"
34+
RESULT_VARIABLE git_status
35+
OUTPUT_VARIABLE git_output
36+
WORKING_DIRECTORY "${CMAKE_ARGV3}"
37+
OUTPUT_STRIP_TRAILING_WHITESPACE)
38+
39+
if(NOT (git_status STREQUAL "0"))
40+
message( FATAL_ERROR "git archive ... failed with exit status: ${git_status} and message:
41+
${git_output}")
42+
else()
43+
message( STATUS "Source code release asset created from `git archive`: ${release_asset}")
44+
endif()
45+
46+
file(SHA256 "${release_asset}" tarball_sha256)
47+
set(sha256_checksum "${tarball_sha256} ${archive}.tar.gz")
48+
configure_file("${CMAKE_ARGV3}/cmake/opencoarrays-VER-SHA256.txt.in"
49+
"${CMAKE_ARGV4}/${l_archive}-SHA256.txt"
50+
@ONLY)
51+
message( STATUS
52+
"SHA 256 checksum of release tarball written out as: ${CMAKE_ARGV4}/${l_archive}-SHA256.txt" )
53+
54+
find_program(GPG_EXECUTABLE
55+
gpg
56+
DOC "Location of GnuPG (gpg) executable")
57+
58+
if(GPG_EXECUTABLE)
59+
execute_process(
60+
COMMAND "${GPG_EXECUTABLE}" --armor --detach-sign --comment "@gpg_comment@" "${CMAKE_ARGV4}/${l_archive}-SHA256.txt"
61+
RESULT_VARIABLE gpg_status
62+
OUTPUT_VARIABLE gpg_output
63+
WORKING_DIRECTORY "${CMAKE_ARGV4}")
64+
if(NOT (gpg_status STREQUAL "0"))
65+
message( WARNING "GPG signing of ${CMAKE_ARGV4}/${l_archive}-SHA256.txt appears to have failed
66+
with status: ${gpg_status} and output: ${gpg_output}")
67+
else()
68+
configure_file("${CMAKE_ARGV3}/cmake/opencoarrays-VER-SHA256.txt.asc.in"
69+
"${CMAKE_ARGV4}/${l_archive}-GPG.comment"
70+
@ONLY)
71+
file(READ "${CMAKE_ARGV4}/${l_archive}-GPG.comment" gpg_comment)
72+
configure_file("${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc"
73+
"${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc.out"
74+
@ONLY)
75+
file(RENAME "${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc.out"
76+
"${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc")
77+
message(STATUS "GPG signed SHA256 checksum created: ${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc")
78+
endif()
79+
endif()
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
-----BEGIN PGP SIGNATURE-----
2-
Comment: Mac users can use GPGTools - https://gpgtools.org
1+
Mac users can use GPGTools - https://gpgtools.org
32
Comment: Download Izaak Beekman's GPG public key from your
43
Comment: trusted key server or from
54
Comment: https://izaakbeekman.com/izaak.pubkey.txt
65
Comment: Next add it to your GPG keyring, e.g.,
76
Comment: `curl https://izaakbeekman.com/izaak.pubkey.txt | gpg --import`
87
Comment: Make sure you have verified that the release archive's
98
Comment: SHA256 checksum matches the provided
10-
Comment: opencoarrays-@full_git_describe@-SHA256.txt and ensure that this file
9+
Comment: opencoarrays-@git_version@-SHA256.txt and ensure that this file
1110
Comment: and it's signature are in the same directory. Then
1211
Comment: verify with:
13-
Comment: `gpg --verify opencoarrays-@full_git_describe@-SHA256.txt.asc`
12+
Comment: `gpg --verify opencoarrays-@git_version@-SHA256.txt.asc`

cmake/opencoarrays-VER-SHA256.txt.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# To verify cryptographic checksums `shasum -c opencoarrays-@[email protected]` on Mac OS X, or
2-
# `sha256sum -c opencoarrays-@[email protected]` on Linux.
1+
# To verify cryptographic checksums `shasum -c opencoarrays-@[email protected]` on Mac OS X, or
2+
# `sha256sum -c opencoarrays-@[email protected]` on Linux.
3+
@sha256_checksum@

0 commit comments

Comments
 (0)