Skip to content

Commit 03c886f

Browse files
committed
Store the version string in a single place
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`.
1 parent c966f47 commit 03c886f

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

.github/workflows/linux_and_macos.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ jobs:
212212
################################################################
213213
EOF
214214
215+
eval `grep ^VERSION Makefile | tr -d ' '`
216+
sed "s/@VERSION@/$VERSION/" recordings/template.txt > recordings/expected.txt
215217
diff -u recordings/{expected,actual}.txt
216-
rm -f recordings/actual.txt
218+
rm -f recordings/{expected,actual}.txt
217219
218220
- name: 'Clean'
219221
env:

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
VERSION = 1.6.5
12
DESTDIR ?=
23
PREFIX ?= /usr/local
34
MANPREFIX ?= $(PREFIX)/man
5+
CPPFLAGS += -DVERSION_STR='"$(VERSION)"'
46
CFLAGS += -Wall -Wextra
57
CFLAGS += `pkg-config --cflags ncursesw`
68
LDLIBS += `pkg-config --libs ncursesw` -lm
@@ -22,6 +24,6 @@ clean:
2224

2325
.c:
2426
@pkg-config --version > /dev/null
25-
$(CC) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@
27+
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@
2628

2729
.PHONY: all clean install uninstall

recordings/get_back_in_sync.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ fi
2222

2323
./record.sh
2424

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

27-
git add expected.txt
28+
git add template.txt
2829

2930
if git diff --cached --exit-code >/dev/null ; then
3031
echo 'Already in sync, good.'
3132
else
32-
EDITOR=true git commit -m 'recordings: Sync expected.txt'
33+
EDITOR=true git commit -m 'recordings: Sync template.txt'
3334
fi

recordings/expected.txt renamed to recordings/template.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| │ |
2020
| └─────────────────────────────────────────────────────────────────────────────────────> |
2121
| X Thu Jan 1 00:00:00 1970 |
22-
|   https://github.com/tenox7/ttyplot 1.6.5 |
22+
|   https://github.com/tenox7/ttyplot @VERSION@ |
2323
+------------------------------------------------------------------------------------------+
2424

2525
[90x20] Frame 2:
@@ -43,7 +43,7 @@
4343
| │ XX |
4444
| └─────────────────────────────────────────────────────────────────────────────────────> |
4545
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
46-
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.5 |
46+
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot @VERSION@ |
4747
+------------------------------------------------------------------------------------------+
4848

4949
[90x20] Frame 3:
@@ -67,6 +67,6 @@
6767
| │ XX |
6868
| └─────────────────────────────────────────────────────────────────────────────────────> |
6969
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
70-
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.5 |
70+
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot @VERSION@ |
7171
+------------------------------------------------------------------------------------------+
7272

ttyplot.c

-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@
4242
#include <err.h>
4343
#endif
4444

45-
#define STR_(x) #x
46-
#define STR(x) STR_(x)
47-
#define VERSION_MAJOR 1
48-
#define VERSION_MINOR 6
49-
#define VERSION_PATCH 5
50-
#define VERSION_STR STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_PATCH)
51-
5245
#define T_RARR '>'
5346
#define T_UARR '^'
5447
#ifdef NOACS

0 commit comments

Comments
 (0)