Skip to content

Commit bdeab3a

Browse files
authored
Merge pull request #399 from redpanda-data/td-stable-avrogen-include-guard
[c++] avrogencpp: emit deterministic include guard
2 parents 7d1c69c + 96c2f51 commit bdeab3a

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

lang/c++/impl/avrogencpp.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
*/
1818

1919
#include <cctype>
20-
#ifndef _WIN32
21-
#include <ctime>
22-
#endif
2320
#include <fstream>
2421
#include <iostream>
2522
#include <map>
@@ -30,7 +27,6 @@
3027
#include <boost/lexical_cast.hpp>
3128
#include <boost/program_options.hpp>
3229

33-
#include <boost/random/mersenne_twister.hpp>
3430
#include <utility>
3531

3632
#include "Compiler.hh"
@@ -92,7 +88,6 @@ class CodeGen {
9288
const std::string includePrefix_;
9389
const bool noUnion_;
9490
const std::string guardString_;
95-
boost::mt19937 random_;
9691

9792
vector<PendingSetterGetter> pendingGettersAndSetters;
9893
vector<PendingConstructor> pendingConstructors;
@@ -123,8 +118,7 @@ class CodeGen {
123118
std::string includePrefix, bool noUnion) : unionTracker_(schemaFile), os_(os), inNamespace_(false), ns_(std::move(ns)),
124119
schemaFile_(std::move(schemaFile)), headerFile_(std::move(headerFile)),
125120
includePrefix_(std::move(includePrefix)), noUnion_(noUnion),
126-
guardString_(std::move(guardString)),
127-
random_(static_cast<uint32_t>(::time(nullptr))) {
121+
guardString_(std::move(guardString)) {
128122
}
129123

130124
void generate(const ValidSchema &schema);
@@ -770,7 +764,14 @@ void CodeGen::emitGeneratedWarning() {
770764
string CodeGen::guard() {
771765
string h = headerFile_;
772766
makeCanonical(h, true);
773-
return h + "_" + lexical_cast<string>(random_()) + "_H";
767+
// headerFile_ is already a unique-per-output path, so the canonicalised
768+
// form is already a valid, unique include guard. Avoid mixing in a
769+
// time-seeded RNG here so the generated output is byte-deterministic
770+
// across invocations -- otherwise build systems that key their cache on
771+
// input-content digests (e.g. Bazel remote cache, Nix store paths) end
772+
// up rebuilding every downstream consumer on every invocation, even on
773+
// byte-identical schemas.
774+
return h + "_H";
774775
}
775776

776777
void CodeGen::generate(const ValidSchema &schema) {

0 commit comments

Comments
 (0)