]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: add a new file "version.c" to carry version updates
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Jan 2019 17:20:32 +0000 (18:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 4 Jan 2019 17:20:32 +0000 (18:20 +0100)
While testing fixes, it's sometimes confusing to rebuild only one C file
(e.g. a mux) and not to have the correct commit ID reported in "haproxy -v"
nor on the stats page.

This patch adds a new "version.c" file which is always rebuilt. It's
very small and contains only 3 variables derived from the various
version strings. These variables are used instead of the macros at the
few places showing the version. This way the output version of the
running code is always correct for the parts that were rebuilt.

Makefile
include/common/version.h
src/haproxy.c
src/stats.c
src/version.c [new file with mode: 0644]

index 450622edb262ccd8351b813e4237bcac559e3dd0..934c85bdf61c4debb724edd5cb2e662dd940c30a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -947,7 +947,7 @@ OBJS = src/proto_http.o src/cfgparse-listen.o src/proto_htx.o src/stream.o    \
        src/http.o src/hpack-dec.o src/action.o src/proto_udp.o src/http_acl.o \
        src/xxhash.o src/hpack-enc.o src/h2.o src/freq_ctr.o src/lru.o         \
        src/protocol.o src/arg.o src/hpack-huff.o src/hdr_idx.o src/base64.o   \
-       src/hash.o src/mailers.o src/activity.o src/http_msg.o
+       src/hash.o src/mailers.o src/activity.o src/http_msg.o src/version.o
 
 EBTREE_OBJS = $(EBTREE_DIR)/ebtree.o $(EBTREE_DIR)/eb32sctree.o \
               $(EBTREE_DIR)/eb32tree.o $(EBTREE_DIR)/eb64tree.o \
@@ -984,6 +984,9 @@ objsize: haproxy
 %.o:   %.c $(DEP)
        $(cmd_CC) $(COPTS) -c -o $@ $<
 
+# rebuild it every time
+.PHONY: src/version.c
+
 src/trace.o: src/trace.c $(DEP)
        $(cmd_CC) $(TRACE_COPTS) -c -o $@ $<
 
index 61f95a30d2c1947812ed7f9198fe93019987572d..305087db1227fad69d3801e6bf2b0edf66ee47f0 100644 (file)
@@ -66,5 +66,9 @@
 #error "Must define CONFIG_HAPROXY_DATE"
 #endif
 
+extern const char *haproxy_version;
+extern const char *haproxy_date;
+extern const char *stats_version_string;
+
 #endif /* _COMMON_VERSION_H */
 
index 0b99a13255e1dfd99967855013f9417256a40163..d47dff3e3785879caf0c84eb15f4fcd4e07a8c72 100644 (file)
@@ -370,7 +370,7 @@ void hap_register_per_thread_deinit(void (*fct)())
 
 static void display_version()
 {
-       printf("HA-Proxy version " HAPROXY_VERSION " " HAPROXY_DATE" - https://haproxy.org/\n");
+       printf("HA-Proxy version %s %s - https://haproxy.org/\n", haproxy_version, haproxy_date);
 }
 
 static void display_build_opts()
index bb6fa47f05ee6f47493e3eb9b0bb7d1a225481d1..5e54dd5b2d8c2342b6a373de5e19ec5de81d7be6 100644 (file)
@@ -2386,7 +2386,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
                      "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
                      "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
                      "",
-                     (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING),
+                     (uri->flags & ST_HIDEVER) ? "" : (stats_version_string),
                      pid, (uri->flags & ST_SHNODE) ? " on " : "",
                      (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
                      (uri->flags & ST_SHDESC) ? ": " : "",
@@ -3558,8 +3558,8 @@ int stats_fill_info(struct field *info, int len)
        memset(info, 0, sizeof(*info) * len);
 
        info[INF_NAME]                           = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME);
-       info[INF_VERSION]                        = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION);
-       info[INF_RELEASE_DATE]                   = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE);
+       info[INF_VERSION]                        = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version);
+       info[INF_RELEASE_DATE]                   = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_date);
 
        info[INF_NBTHREAD]                       = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
        info[INF_NBPROC]                         = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
diff --git a/src/version.c b/src/version.c
new file mode 100644 (file)
index 0000000..f50f24b
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Version reporting : all user-visible version information should come from
+ * this file so that rebuilding only this one is enough to report the latest
+ * code version.
+ */
+
+#include <common/version.h>
+
+const char *haproxy_version      = HAPROXY_VERSION;
+const char *haproxy_date         = HAPROXY_DATE;
+const char *stats_version_string = STATS_VERSION_STRING;