]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: version: move the remaining BUILD_* stuff from haproxy.c to version.c
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2025 16:49:55 +0000 (17:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2025 16:53:55 +0000 (17:53 +0100)
version.c tries to centralize all variables conveying version information,
but there's still an issue with the BUILD_* variables which are only
passed to haproxy.o and are only updated when that one is rebuilt. This
is not very logical given that we can end up with values there which
contradict info from version.c.

Better move all of these to version.c which is systematically rebuilt.
Most of these variables only end up as string concatenation at the
moment. Some of them are even duplicated. In version.c we now have one
variable (or constant) for each of them and haproxy.c references them
in messages. This is much more logical and easier to maintain in a
consistent state.

The patch looks a bit large but it really only moves the ifdefed string
assignment from one file to another, placing them into variables.

Makefile
include/haproxy/global.h
include/haproxy/version.h
src/cfgcond.c
src/haproxy.c
src/version.c

index 9bf63a280d44a78a32cf35ba9d45bc7aa86afc0a..d128251e16019ea1c850523c56e79af77c7efc20 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1080,7 +1080,7 @@ dev/udp/udp-perturb: dev/udp/udp-perturb.o
 src/calltrace.o: src/calltrace.c $(DEP)
        $(cmd_CC) $(TRACE_COPTS) -c -o $@ $<
 
-src/haproxy.o: src/haproxy.c $(DEP)
+src/version.o: src/version.c $(DEP)
        $(cmd_CC) $(COPTS) \
              -DBUILD_TARGET='"$(strip $(TARGET))"' \
              -DBUILD_CC='"$(strip $(CC))"' \
index ba0523cbf911d2ba7d54b7f3d689d411164a64df..26cba4ac4fd31c01009e54a30c01cc7caebdbb86 100644 (file)
@@ -25,7 +25,6 @@
 #include <haproxy/api-t.h>
 #include <haproxy/global-t.h>
 
-extern char *build_features;
 extern struct global global;
 extern int  pid;                /* current process id */
 extern int  actconn;            /* # of active sessions */
index cca4fc159370a83d446bf9013b31ed8619ee015f..59c62735e5229a8e0973c82c53835fcbabd15d8b 100644 (file)
 extern char haproxy_version[];
 extern char haproxy_date[];
 extern char stats_version_string[];
+extern char build_opts_string[];
+extern const char pm_target_opts[];
+extern const char pm_toolchain_opts[];
+extern char *build_features;
 
 #endif /* _HAPROXY_VERSION_H */
 
index 117cf6c2891ebfc8e92d0edcdcb029447dae6057..f01638df41a239eca32438e4fe3d4d58812fe8ee 100644 (file)
@@ -13,9 +13,9 @@
 #include <haproxy/api.h>
 #include <haproxy/arg.h>
 #include <haproxy/cfgcond.h>
-#include <haproxy/global.h>
 #include <haproxy/proto_tcp.h>
 #include <haproxy/tools.h>
+#include <haproxy/version.h>
 
 /* supported condition predicates */
 const struct cond_pred_kw cond_predicates[] = {
index 52d58e067d80936183c3875a441944a7cc0e89d6..7ee654b07de64a52ac7feeb8712a358fca9cd833 100644 (file)
@@ -142,12 +142,6 @@ DECLARE_INIT_STAGES;
  */
 empty_t __read_mostly_align HA_SECTION("read_mostly") ALIGNED(64);
 
-#ifdef BUILD_FEATURES
-char *build_features = BUILD_FEATURES;
-#else
-char *build_features = "";
-#endif
-
 /* list of config files */
 static struct list cfg_cfgfiles = LIST_HEAD_INIT(cfg_cfgfiles);
 int  pid;                      /* current process id */
@@ -561,26 +555,12 @@ static void display_build_opts()
 {
        const char **opt;
 
-       printf("Build options :"
-#ifdef BUILD_TARGET
-              "\n  TARGET  = " BUILD_TARGET
-#endif
-#ifdef BUILD_CC
-              "\n  CC      = " BUILD_CC
-#endif
-#ifdef BUILD_CFLAGS
-              "\n  CFLAGS  = " BUILD_CFLAGS
-#endif
-#ifdef BUILD_OPTIONS
-              "\n  OPTIONS = " BUILD_OPTIONS
-#endif
-#ifdef BUILD_DEBUG
-              "\n  DEBUG   = " BUILD_DEBUG
-#endif
+       printf("Build options : %s"
               "\n\nFeature list : %s"
               "\n\nDefault settings :"
               "\n  bufsize = %d, maxrewrite = %d, maxpollevents = %d"
               "\n\n",
+              build_opts_string,
               build_features, BUFSIZE, MAXREWRITE, MAX_POLL_EVENTS);
 
        for (opt = NULL; (opt = hap_get_next_build_opt(opt)); puts(*opt))
@@ -2287,23 +2267,11 @@ static void step_init_2(int argc, char** argv)
 #endif
        /* toolchain opts */
        cflags = chunk_newstr(&trash);
-#ifdef BUILD_CC
-       chunk_appendf(&trash, "%s", BUILD_CC);
-#endif
-#ifdef BUILD_CFLAGS
-       chunk_appendf(&trash, " %s", BUILD_CFLAGS);
-#endif
-#ifdef BUILD_DEBUG
-       chunk_appendf(&trash, " %s", BUILD_DEBUG);
-#endif
+       chunk_appendf(&trash, "%s", pm_toolchain_opts);
+
        /* settings */
        opts = chunk_newstr(&trash);
-#ifdef BUILD_TARGET
-       chunk_appendf(&trash, "TARGET='%s'", BUILD_TARGET);
-#endif
-#ifdef BUILD_OPTIONS
-       chunk_appendf(&trash, " %s", BUILD_OPTIONS);
-#endif
+       chunk_appendf(&trash, "TARGET='%s'", pm_target_opts);
 
        post_mortem_add_component("haproxy", haproxy_version, cc, cflags, opts, argv[0]);
 }
@@ -3081,23 +3049,8 @@ int main(int argc, char **argv)
                fprintf(stderr,
                        "FATAL ERROR: invalid code detected -- cannot go further, please recompile!\n"
                        "%s"
-                       "\nBuild options :"
-#ifdef BUILD_TARGET
-                       "\n  TARGET  = " BUILD_TARGET
-#endif
-#ifdef BUILD_CC
-                       "\n  CC      = " BUILD_CC
-#endif
-#ifdef BUILD_CFLAGS
-                       "\n  CFLAGS  = " BUILD_CFLAGS
-#endif
-#ifdef BUILD_OPTIONS
-                       "\n  OPTIONS = " BUILD_OPTIONS
-#endif
-#ifdef BUILD_DEBUG
-                       "\n  DEBUG   = " BUILD_DEBUG
-#endif
-                       "\n\n", msg);
+                       "\nBuild options :%s"
+                       "\n\n", msg, build_opts_string);
 
                return 1;
        }
index e7bb748f81e577ae46984a85c02c0e6792111e8b..03f26e82537cec07b1e045844eecbb97afe7bd8c 100644 (file)
@@ -15,6 +15,55 @@ char haproxy_version[]      = HAPROXY_VERSION;
 char haproxy_date[]         = HAPROXY_DATE;
 char stats_version_string[] = STATS_VERSION_STRING;
 
+/* the build options string depending on known settings */
+char build_opts_string[]    = ""
+#ifdef BUILD_TARGET
+              "\n  TARGET  = " BUILD_TARGET
+#endif
+#ifdef BUILD_CC
+              "\n  CC      = " BUILD_CC
+#endif
+#ifdef BUILD_CFLAGS
+              "\n  CFLAGS  = " BUILD_CFLAGS
+#endif
+#ifdef BUILD_OPTIONS
+              "\n  OPTIONS = " BUILD_OPTIONS
+#endif
+#ifdef BUILD_DEBUG
+              "\n  DEBUG   = " BUILD_DEBUG
+#endif
+       "";
+
+/* compact string of toolchain options for post-mortem */
+const char pm_toolchain_opts[] = ""
+#ifdef BUILD_CC
+       BUILD_CC
+#endif
+#ifdef BUILD_CFLAGS
+       " " BUILD_CFLAGS
+#endif
+#ifdef BUILD_DEBUG
+       " " BUILD_DEBUG
+#endif
+       "";
+
+/* compact string of target options for post-mortem */
+const char pm_target_opts[] = ""
+#ifdef BUILD_TARGET
+       "TARGET='" BUILD_TARGET "'"
+#endif
+#ifdef BUILD_OPTIONS
+       " " BUILD_OPTIONS
+#endif
+       "";
+
+/* Build features may be passed by the makefile */
+#ifdef BUILD_FEATURES
+char *build_features = BUILD_FEATURES;
+#else
+char *build_features = "";
+#endif
+
 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
 #define SANITIZE_STRING " with address sanitizer"
 #else