diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc index 14351521590..1c27ba4077f 100644 --- a/lang/c++/impl/avrogencpp.cc +++ b/lang/c++/impl/avrogencpp.cc @@ -17,9 +17,6 @@ */ #include -#ifndef _WIN32 -#include -#endif #include #include #include @@ -30,7 +27,6 @@ #include #include -#include #include #include "Compiler.hh" @@ -92,7 +88,6 @@ class CodeGen { const std::string includePrefix_; const bool noUnion_; const std::string guardString_; - boost::mt19937 random_; vector pendingGettersAndSetters; vector pendingConstructors; @@ -123,8 +118,7 @@ class CodeGen { std::string includePrefix, bool noUnion) : unionTracker_(schemaFile), os_(os), inNamespace_(false), ns_(std::move(ns)), schemaFile_(std::move(schemaFile)), headerFile_(std::move(headerFile)), includePrefix_(std::move(includePrefix)), noUnion_(noUnion), - guardString_(std::move(guardString)), - random_(static_cast(::time(nullptr))) { + guardString_(std::move(guardString)) { } void generate(const ValidSchema &schema); @@ -770,7 +764,14 @@ void CodeGen::emitGeneratedWarning() { string CodeGen::guard() { string h = headerFile_; makeCanonical(h, true); - return h + "_" + lexical_cast(random_()) + "_H"; + // headerFile_ is already a unique-per-output path, so the canonicalised + // form is already a valid, unique include guard. Avoid mixing in a + // time-seeded RNG here so the generated output is byte-deterministic + // across invocations -- otherwise build systems that key their cache on + // input-content digests (e.g. Bazel remote cache, Nix store paths) end + // up rebuilding every downstream consumer on every invocation, even on + // byte-identical schemas. + return h + "_H"; } void CodeGen::generate(const ValidSchema &schema) {