forked from ashinkarov/sac-devcamp-2013
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-tag-versioning.patch
156 lines (140 loc) · 6.32 KB
/
git-tag-versioning.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From 02e01eb95713c25265d00d18edf40eaab679ea86 Mon Sep 17 00:00:00 2001
From: Artem Shinkarov <[email protected]>
Date: Wed, 15 May 2013 17:34:47 +0100
Subject: [PATCH] Introduce versioning based on git tags.
The basic version is a standard three digit tuple separated with '.':
<major>.<minor>.<patch>
The version is taken from the last tag in the git repository. If the
tag is not found the triplet is set to 0.0.0. In order to increase the
version of sac, one has to mark a commit with according tag:
git tag -a 1.2.0
and push the tag into the origin (won't happen automatically):
git push --tags
Please *note* that the new version should be greater than the previous
one, it is your responsibility to check that your new version x.y.z
is greater than existing version a.b.c which means that:
x > a || (x == a && y > b || (y == b && z > c)).
Normally if you change minor version, then the patch part should become
zero, and if you change major version then minor and patch parts should
become zeroes accordingly.
The long description (which would be printed by -V command) contains
some more info. The pattern is:
<major>.<minor>.<patch>-<commits-form-tag>-<last-coommit-hash>(-dirty?)
For example:
1.1.0-0-g8fb52ee-dirty
means that there were 0 commits since the tag 1.1.0, hash of the last
commit is 8fb52ee and "-dirty" means that there were local changes in
the source tree.
---
src/libsac2c/global/globals.mac | 7 +++++--
src/libsac2c/global/usage.c | 2 +-
src/makefiles/check.mkf | 36 +-----------------------------------
src/makefiles/config.mkf.in | 17 ++++++++++++++++-
4 files changed, 23 insertions(+), 39 deletions(-)
diff --git a/src/libsac2c/global/globals.mac b/src/libsac2c/global/globals.mac
index c9b8e3d..6c9e59b 100644
--- a/src/libsac2c/global/globals.mac
+++ b/src/libsac2c/global/globals.mac
@@ -61,8 +61,11 @@ GLOBAL (int, start_token, 0, xfree_dummy, )
/*
* Version control
*/
-
-GLOBAL (const char *, version_id, "v1.00-beta (Haggis And Apple)", xfree_dummy, )
+#define _STRINGIFY(x) #x
+#define STRINGIFY(x) _STRINGIFY (x)
+GLOBAL (const char *, version_id, STRINGIFY (SAC_VERSION), xfree_dummy, )
+#undef _STRINGIFY
+#undef STRINGIFY
/*
* version string
*/
diff --git a/src/libsac2c/global/usage.c b/src/libsac2c/global/usage.c
index ae6ec80..ba8e429 100644
--- a/src/libsac2c/global/usage.c
+++ b/src/libsac2c/global/usage.c
@@ -1169,7 +1169,7 @@ void USGprintVersion()
{
DBUG_ENTER ();
- printf("%s %s\n %s rev %s %s\n (%s by %s)\n",
+ printf("%s %s [%s] (%s)\nbuilt on %s at %s by %s\n",
global.toolname,
(global.version_id[0] == '\0') ? "???" : global.version_id,
(build_style[0] == '\0') ? "" : build_style,
diff --git a/src/makefiles/check.mkf b/src/makefiles/check.mkf
index 4d26a60..2698e9f 100644
--- a/src/makefiles/check.mkf
+++ b/src/makefiles/check.mkf
@@ -79,39 +79,5 @@ $(PROJECT_ROOT)/.revision.txt.PHONY:
# Use indirect phony and non mod time changing rule ( when version unchanged)
# to prevent needless rebuilds of the compiler.
$(PROJECT_ROOT)/.revision.txt: $(PROJECT_ROOT)/.revision.txt.PHONY
- @ if [ ! -f $@ ]; \
- then \
- echo "?????" >$@; \
- fi
- @ if which svnversion > /dev/null; then \
- svnversion $(PROJECT_ROOT) \
- | sed -e 's/[ \t\n]/_/g' \
- | sed -e 's/M/:MODIFIED/g' \
- | sed -e 's/S/:SWITCHED/g' > [email protected]; \
- if which diff >/dev/null; then \
- if diff $@ [email protected] >/dev/null; then \
- rm [email protected]; \
- else \
- mv [email protected] $@; \
- fi \
- else \
- rm [email protected]; \
- fi \
- fi
-# This code merely counts the number of GIT commits, and
-# used that to fake a revision number.
-# #
- @ if which git > /dev/null; then \
- git rev-list --abbrev-commit HEAD $(PROJECT_ROOT) \
- | wc -l | sed -e 's/[ ]*//g' > [email protected]; \
- if which diff >/dev/null; then \
- if diff $@ [email protected] >/dev/null; then \
- rm [email protected]; \
- else \
- mv [email protected] $@; \
- fi \
- else \
- rm [email protected]; \
- fi \
- fi
+ @$(ECHO) $(SAC_VERSION) > $@
diff --git a/src/makefiles/config.mkf.in b/src/makefiles/config.mkf.in
index cf460e7..114c9ee 100644
--- a/src/makefiles/config.mkf.in
+++ b/src/makefiles/config.mkf.in
@@ -7,6 +7,21 @@ OS := @OS@
ARCH := @ARCH@
+# Version based on git tags
+UNKNOWN_VERSION := unknown-version
+SAC_VERSION := $(shell git describe --tags --dirty --long 2>/dev/null || echo "$(UNKNOWN_VERSION)")
+SAC_SHORT_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "$(UNKNOWN_VERSION)")
+ifeq ($(SAC_VERSION),$(UNKNOWN_VERSION))
+ SAC_MAJOR_VERSION := 0
+ SAC_MINOR_VERSION := 0
+ SAC_PATCH_VERSION := 0
+else
+ SAC_MAJOR_VERSION := $(shell echo $(SAC_SHORT_VERSION) | cut -d '.' -f 1)
+ SAC_MINOR_VERSION := $(shell echo $(SAC_SHORT_VERSION) | cut -d '.' -f 2)
+ SAC_PATCH_VERSION := $(shell echo $(SAC_SHORT_VERSION) | cut -d '.' -f 3)
+endif
+
+
################################################################################
#
# compiler and linker setup:
@@ -15,7 +30,7 @@ ARCH := @ARCH@
CC_DEVEL := @SAC2C_CC@
CC_PROD := @SAC2C_CC@
-CC_FLAGS := @OSFLAGS@ -D_POSIX_C_SOURCE=200809L
+CC_FLAGS := @OSFLAGS@ -D_POSIX_C_SOURCE=200809L -DSAC_VERSION="$(SAC_SHORT_VERSION)"
CC_FLAGS_DEVEL := @SAC2C_MKCCFLAGS@ $(CC_FLAGS)
CC_FLAGS_PROD := @SAC2C_PDCCFLAGS@ $(CC_FLAGS)
--
1.8.3.2