From bc28d14ebe5ab3196d03aeab5d7fea8ddf29589b Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Wed, 4 Dec 2024 16:18:32 +0100 Subject: [PATCH] add infrastructure for making releases Idea: a release will be a git tag, distributed as an autogenerated archive (eg. by GitLab release feature). This version string must therefore be stored in a revisioned file, so we use `.version` for this purpose. Before tagging a new release this file will have to be updated with the new version number. When building gray the revision (shown in the output headers and usage screen) will be set to either - the latest commit hash when building from a git checkout, - from the .version file when building from release archive. The implementation is based on whether the .git directory is present. --- .version | 1 + Makefile | 15 ++++++++++++--- default.nix | 9 ++++----- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .version diff --git a/.version b/.version new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/Makefile b/Makefile index 8f48c83..9649427 100644 --- a/Makefile +++ b/Makefile @@ -53,15 +53,24 @@ MANPAGES = $(addprefix $(SHAREDIR)/,gray.1 gray-convert.1 gray.ini.5 \ profiles.txt.5 beamdata.txt.5 magneticdata.txt.5) ## -## Git information (used in the version string) +## Version information ## +ifneq ($(wildcard .git/*),) +# We are building from a git checkout + # Short hash of the latest commit -GIT_REV ?= $(shell git rev-parse --short HEAD) +GIT_REV ?= $(shell git rev-parse --short HEAD) # Whether the worktree and the latest commit differs GIT_DIRTY ?= $(shell test -n "$$(git status --porcelain)" && echo "-dirty") +REVISION ?= $(GIT_REV)$(GIT_DIRTY) +else +# We are building from a release archive, use the version +REVISION ?= v$(file < .version) +endif + # Source date ifndef SOURCE_DATE_EPOCH # Use current date @@ -76,7 +85,7 @@ DATE=$(shell LC_TIME=C date -d @$(SOURCE_DATE_EPOCH) '+%B %Y') LD = $(FC) FFLAGS += -I$(INCDIR) -fpic LDFLAGS += -L$(LIBDIR) -CPPFLAGS += -DREVISION=\"$(GIT_REV)$(GIT_DIRTY)\" -DPREFIX=\"$(PREFIX)\" +CPPFLAGS += -DREVISION=\"$(REVISION)\" -DPREFIX=\"$(PREFIX)\" # Compiler-specific flags ifdef GNU diff --git a/default.nix b/default.nix index 98b8a01..cca5ff0 100644 --- a/default.nix +++ b/default.nix @@ -14,18 +14,19 @@ let sha256 = "007nv11r0z9fz593iwzn55nc0p0wj5lpgf0k2brhs1ynmikq9gjr"; }; - # Exclude this file and build artifacts + # Exclude this file, build artifacts and git source = builtins.filterSource (path: type: !builtins.elem path [ "configure.mk" "default.nix" "result" ] - && baseNameOf path != "build") ./.; + && baseNameOf path != "build" + && baseNameOf path != ".git") ./.; inherit (import nixpkgs {}) lib pkgs; in pkgs.stdenv.mkDerivation rec { pname = "gray"; - version = "0.1"; + version = builtins.readFile ./.version; src = source; doCheck = true; @@ -72,8 +73,6 @@ in (lib.enableFeature static "static") "--with-katex=${katex}" "--enable-deterministic" - "GIT_REV=${version}" - "GIT_DIRTY=" ]; meta = {