From 51a4266d6fdeded9f9cdf9fbd15242963e510470 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Sat, 19 Oct 2019 14:44:28 +0200 Subject: [PATCH] Include version in released source files I realised that determining which Monocypher version was used in a project was not trivial. We could look at Monocypher's code and deduce the release, but that's tedious and error prone. So I've made those versions more explicit: - Source and header files begin by a comment describing the version. - The pkg-config file created by `make install` include that version. - The version number of unreleased code (under git) is "__git__" - The version number of released code is whatever `git describe --tags` tells us. - the "tarball" target in the makefile was changed to the more standard "dist". To release a new version, we just add a tag, then call `makefile dist`. The version of the released source file will appear at a glance, right there on the first line. Note: the release process blindly replaces all instances of "__git__" by the suitable version number. This could be used to version things other than comments, like string constants. --- .gitignore | 10 +++++++++- README.md | 6 +++--- VERSION.md | 1 - makefile | 13 ++++--------- release.sh | 14 ++++++++++++++ src/monocypher.c | 2 ++ src/monocypher.h | 2 ++ src/optional/sha512.c | 2 ++ src/optional/sha512.h | 2 ++ tarball_ignore | 10 +++++++++- 10 files changed, 47 insertions(+), 15 deletions(-) delete mode 100644 VERSION.md create mode 100755 release.sh diff --git a/.gitignore b/.gitignore index b4b330a..8ee886e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,10 +9,18 @@ *.sav *.profraw *.profdata +*.creator +*.creator.* +*.config +*.cflags +*.cxxflags +*.files +*.includes +*.su +*.su.* tests/formal-analysis/* tests/formal-analysis *.tar.gz monocypher-* -monocypher.* doc/html/*.html tests/vectors.h diff --git a/README.md b/README.md index 3d41396..ce2e603 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,6 @@ that ship with the tarball releases: - The html version of the manual, generated by the `doc/man2html.sh` script. You will need mandoc. -To generate a tarball, simply type `make tarball`. It will make a -tarball with a name that matches the current version (as written in -VERSION.md), in the current directory. +To generate a tarball, simply type `make dist`. It will make a tarball +with a name that matches the current version (using `git describe`), in +the current directory. diff --git a/VERSION.md b/VERSION.md deleted file mode 100644 index e010258..0000000 --- a/VERSION.md +++ /dev/null @@ -1 +0,0 @@ -2.0.5 diff --git a/makefile b/makefile index 24d74a6..344f3e2 100644 --- a/makefile +++ b/makefile @@ -5,8 +5,7 @@ PREFIX=usr/local PKGCONFIG=$(DESTDIR)/$(PREFIX)/lib/pkgconfig MAN_DIR=$(DESTDIR)/$(PREFIX)/share/man/man3 -TARBALL_VERSION=`cat VERSION.md` -TARBALL_DIR=. +VERSION=__git__ ifeq ($(findstring -DED25519_SHA512, $(CFLAGS)),) LINK_SHA512= @@ -34,7 +33,7 @@ install: library src/monocypher.h install-doc @echo 'includedir=$${prefix}/include' >> $(PKGCONFIG)/monocypher.pc @echo '' >> $(PKGCONFIG)/monocypher.pc @echo 'Name: monocypher' >> $(PKGCONFIG)/monocypher.pc - @echo 'Version:' `cat VERSION.md` >> $(PKGCONFIG)/monocypher.pc + @echo 'Version: ' $(VERSION) >> $(PKGCONFIG)/monocypher.pc @echo 'Description: Easy to use, easy to deploy crypto library' \ >> $(PKGCONFIG)/monocypher.pc @echo '' >> $(PKGCONFIG)/monocypher.pc @@ -131,9 +130,5 @@ tests/vectors.h: @echo "" return 1 -tarball: tests/vectors.h - doc/man2html.sh - touch $(TARBALL_DIR)/monocypher-$(TARBALL_VERSION).tar.gz - tar -czvf $(TARBALL_DIR)/monocypher-$(TARBALL_VERSION).tar.gz \ - -X tarball_ignore \ - --transform='flags=r;s|^.|monocypher-'$(TARBALL_VERSION)'|' . +dist: tests/vectors.h + ./release.sh diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..bbaa145 --- /dev/null +++ b/release.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +set -e + +VERSION=`git describe --tags` + +doc/man2html.sh +rsync -avd --exclude-from=tarball_ignore ./ monocypher-$VERSION +for file in `find monocypher-$VERSION -type f ` +do + sed -i "s/__git__/$VERSION/" $file +done +tar -czf monocypher-$VERSION.tar.gz monocypher-$VERSION +rm -rf monocypher-$VERSION diff --git a/src/monocypher.c b/src/monocypher.c index 7241ec5..6a4b10f 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -1,3 +1,5 @@ +// Monocypher version __git__ + #include "monocypher.h" ///////////////// diff --git a/src/monocypher.h b/src/monocypher.h index 97d4854..c99561d 100644 --- a/src/monocypher.h +++ b/src/monocypher.h @@ -1,3 +1,5 @@ +// Monocypher version __git__ + #ifndef MONOCYPHER_H #define MONOCYPHER_H diff --git a/src/optional/sha512.c b/src/optional/sha512.c index a83d188..9afaeb9 100644 --- a/src/optional/sha512.c +++ b/src/optional/sha512.c @@ -1,3 +1,5 @@ +// Monocypher version __git__ + #include "sha512.h" #define FOR(i, min, max) for (size_t i = min; i < max; i++) diff --git a/src/optional/sha512.h b/src/optional/sha512.h index 1354079..78f850f 100644 --- a/src/optional/sha512.h +++ b/src/optional/sha512.h @@ -1,3 +1,5 @@ +// Monocypher version __git__ + #ifndef SHA512_H #define SHA512_H diff --git a/tarball_ignore b/tarball_ignore index 047b6a7..361426e 100644 --- a/tarball_ignore +++ b/tarball_ignore @@ -9,10 +9,18 @@ *.sav *.profraw *.profdata +*.creator +*.creator.* +*.config +*.cflags +*.cxxflags +*.files +*.includes +*.su +*.su.* tests/formal-analysis/* tests/formal-analysis *.tar.gz monocypher-* -monocypher.* lib* .git* -- 2.47.3