feat(build-time-versioning): controller/scheduler --version and startup log

Migrates argp_program_version in controller/main.c, scheduler/main.c,
and xce_test's test.c from the compile-time MK_VERSION/STR construction
to xce_compose_version(), computed into a static buffer and assigned
before argp_parse() runs (argp_program_version is a file-scope pointer,
not a constant expression it can be initialized from at compile time).

Each daemon's startup log now carries the identical version string
(never recomputed) on its first INFO line -- scheduler's BOTH
mutually-exclusive branches (--peers and no-peers), not just the one
literally named in the task text, since "when the daemon starts" is
unconditional.

Live-verified: --version and startup-log output are byte-identical for
both daemons across all branches. No remaining MK_VERSION callers
repo-wide.

Task 3.2/13 of build-time-versioning.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-08-20 11:02:56 +00:00
parent 854f776733
commit 88649a0462
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
4 changed files with 65 additions and 15 deletions

View file

@ -19,8 +19,13 @@ int validate_cert_files(const char *cert_path, const char *key_path,
static char doc[] = "xce_controller";
static char args_doc[] = "";
const char* argp_program_version
= MK_VERSION("xce v0.0.1-", STR(VERSION_COMMIT_ID));
/* build-time-versioning task 3.2: no longer a compile-time initializer --
* argp reads this by pointer when --version/-V is processed, and
* xce_compose_version() (utils.h) is a runtime function, not a constant
* expression, so it cannot initialize a file-scope global. main() assigns
* this to a static buffer, computed via xce_compose_version(), before
* argp_parse() runs. See utils.h's NOTE FOR TASK 3.2 above MK_VERSION. */
const char* argp_program_version = NULL;
const char* argp_program_bug_address = BUG_EMAIL;
/* Long-option key (above ASCII to avoid collisions with short opts) */
@ -311,11 +316,23 @@ int main(int argc, char* argv[])
char key_file[XCE_MAXPATH_LEN + 1];
char cert_file[XCE_MAXPATH_LEN + 1];
char myname[XCE_MAXNAME_LEN + 1];
/* build-time-versioning task 3.2: composed once, read by both
* argp_program_version (--version/-V) and the startup INFO log below --
* never recomputed, so the two can never disagree (Req 2.2). static so
* it outlives this point in main() (contract documented on
* xce_compose_version() in utils.c). */
static char version_buf[128];
/* Capture the NULL-terminated argv for self-restart BEFORE argp_parse so a
* later demotion/rejoin convergence can execv() the same image (Req 1.3). */
g_saved_argv = argv;
/* Must run before argp_parse(): argp reads argp_program_version by
* pointer when --version/-V is processed. */
xce_compose_version(version_buf, sizeof(version_buf), "xce v0.0.1-",
STR(VERSION_COMMIT_ID), STR(VERSION_BUILD_TIME));
argp_program_version = version_buf;
memset(&arguments, 0x0, sizeof(arguments));
arguments.conf_keep_n = 2;
arguments.conf_stale_timeout = 86400;
@ -362,7 +379,7 @@ int main(int argc, char* argv[])
arguments.myname = myname;
}
INFO("My name is %s", arguments.myname);
INFO("My name is %s, version %s", arguments.myname, version_buf);
const char *certdir = arguments.certdir;
char certdir_buf[XCE_MAXPATH_LEN + 1];