Skip to content

Commit

Permalink
Store the version string in a single place
Browse files Browse the repository at this point in the history
Instead of having the ttyplot version string in ttyplot.c (as three
separate variables) and recordings/expected.txt, store it only in
Makefile. This should make version bumping easier.

This string is given by `make` to the compiler as a -D option. The CI
workflow and get_back_in_sync.sh extract this string from the Makefile
using `grep`.
  • Loading branch information
edgar-bonet committed May 13, 2024
1 parent 9bbca81 commit 7657067
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linux_and_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ jobs:
################################################################
EOF
eval `grep ^VERSION Makefile | tr -d ' '`
sed "s/@VERSION@/$VERSION/" recordings/template.txt > recordings/expected.txt
diff -u recordings/{expected,actual}.txt
rm -f recordings/actual.txt
rm -f recordings/{expected,actual}.txt
- name: 'Clean'
env:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
VERSION = 1.6.4
DESTDIR ?=
PREFIX ?= /usr/local
MANPREFIX ?= $(PREFIX)/man
CPPFLAGS += -DVERSION_STR='"$(VERSION)"'
CFLAGS += -Wall -Wextra
CFLAGS += `pkg-config --cflags ncursesw`
LDLIBS += `pkg-config --libs ncursesw` -lm
Expand All @@ -22,6 +24,6 @@ clean:

.c:
@pkg-config --version > /dev/null
$(CC) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@

.PHONY: all clean install uninstall
7 changes: 4 additions & 3 deletions recordings/get_back_in_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ fi

./record.sh

cp actual.txt expected.txt
eval `grep ^VERSION ../Makefile | tr -d ' '` # get the version number
sed "s/$VERSION/@VERSION@/" actual.txt > template.txt

git add expected.txt
git add template.txt

if git diff --cached --exit-code >/dev/null ; then
echo 'Already in sync, good.'
else
EDITOR=true git commit -m 'recordings: Sync expected.txt'
EDITOR=true git commit -m 'recordings: Sync template.txt'
fi
6 changes: 3 additions & 3 deletions recordings/expected.txt → recordings/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
| │ |
| └─────────────────────────────────────────────────────────────────────────────────────> |
| X Thu Jan 1 00:00:00 1970 |
|   https://github.com/tenox7/ttyplot 1.6.2 |
|   https://github.com/tenox7/ttyplot @VERSION@ |
+------------------------------------------------------------------------------------------+

[90x20] Frame 2:
Expand All @@ -43,7 +43,7 @@
| │ XX |
| └─────────────────────────────────────────────────────────────────────────────────────> |
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.2 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot @VERSION@ |
+------------------------------------------------------------------------------------------+

[90x20] Frame 3:
Expand All @@ -67,6 +67,6 @@
| │ XX |
| └─────────────────────────────────────────────────────────────────────────────────────> |
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.2 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot @VERSION@ |
+------------------------------------------------------------------------------------------+

7 changes: 0 additions & 7 deletions ttyplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
#include <err.h>
#endif

#define STR_(x) #x
#define STR(x) STR_(x)
#define VERSION_MAJOR 1
#define VERSION_MINOR 6
#define VERSION_PATCH 4
#define VERSION_STR STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_PATCH)

#define T_RARR '>'
#define T_UARR '^'
#ifdef NOACS
Expand Down

0 comments on commit 7657067

Please sign in to comment.