1
0
mirror of https://github.com/anope/anope.git synced 2026-06-30 19:26:38 +02:00

Improve support for versioning builds.

- Don't increment the build id when doing reproducible builds.
- Generate the build date in build.h so it always gets updated.
This commit is contained in:
Sadie Powell
2026-06-17 22:52:14 +01:00
parent b9cacf1d0f
commit b49f984598
3 changed files with 19 additions and 8 deletions
+17 -2
View File
@@ -18,6 +18,8 @@
#include <sstream>
#include <map>
#include "sysconf.h"
static std::string get_git_hash(const std::string &git_dir)
{
std::fstream fd;
@@ -78,14 +80,18 @@ static bool read_version_sh(const std::string &version_sh, std::map<std::string,
static bool write_build_h(const std::string &buildh, const std::string &git_version)
{
std::fstream fd(buildh.c_str(), std::ios::in);
std::fstream fd;
std::string build = "#define BUILD 1";
#if !REPRODUCIBLE_BUILD
fd.open(buildh.c_str(), std::ios::in);
if (fd.is_open())
{
for (std::string filebuf; getline(fd, filebuf);)
{
if (!filebuf.find("#define BUILD"))
if (!filebuf.find("#define BUILD\t"))
{
size_t tab = filebuf.find(' ');
@@ -101,6 +107,8 @@ static bool write_build_h(const std::string &buildh, const std::string &git_vers
}
fd.clear();
#endif
fd.open(buildh.c_str(), std::ios::out);
if (!fd.is_open())
{
@@ -111,6 +119,13 @@ static bool write_build_h(const std::string &buildh, const std::string &git_vers
fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << std::endl
<< "#pragma once" << std::endl
<< build << std::endl;
#if !REPRODUCIBLE_BUILD
auto time_now = time(NULL);
auto *local_tm = localtime(&time_now);
char buffer[100];
strftime(buffer, sizeof(buffer), "%a %b %e %Y %T %Z", local_tm);
fd << "#define BUILD_DATE \"" << buffer << "\"" << std::endl;
#endif
if (!git_version.empty())
fd << "#define VERSION_GIT \"" << git_version << "\"" << std::endl;
fd.close();