REORG: version: move the remaining BUILD_* stuff from haproxy.c to version.c

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.
This commit is contained in:
Willy Tarreau 2025-01-20 17:49:55 +01:00
parent 9e61cf6790
commit b066c0affb
6 changed files with 62 additions and 57 deletions

View File

@ -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))"' \

View 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 */

View File

@ -81,6 +81,10 @@
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 */

View 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[] = {

View 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;
}

View 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