|
17 | 17 | */ |
18 | 18 |
|
19 | 19 | #include <cctype> |
20 | | -#ifndef _WIN32 |
21 | | -#include <ctime> |
22 | | -#endif |
23 | 20 | #include <fstream> |
24 | 21 | #include <iostream> |
25 | 22 | #include <map> |
|
30 | 27 | #include <boost/lexical_cast.hpp> |
31 | 28 | #include <boost/program_options.hpp> |
32 | 29 |
|
33 | | -#include <boost/random/mersenne_twister.hpp> |
34 | 30 | #include <utility> |
35 | 31 |
|
36 | 32 | #include "Compiler.hh" |
@@ -92,7 +88,6 @@ class CodeGen { |
92 | 88 | const std::string includePrefix_; |
93 | 89 | const bool noUnion_; |
94 | 90 | const std::string guardString_; |
95 | | - boost::mt19937 random_; |
96 | 91 |
|
97 | 92 | vector<PendingSetterGetter> pendingGettersAndSetters; |
98 | 93 | vector<PendingConstructor> pendingConstructors; |
@@ -123,8 +118,7 @@ class CodeGen { |
123 | 118 | std::string includePrefix, bool noUnion) : unionTracker_(schemaFile), os_(os), inNamespace_(false), ns_(std::move(ns)), |
124 | 119 | schemaFile_(std::move(schemaFile)), headerFile_(std::move(headerFile)), |
125 | 120 | includePrefix_(std::move(includePrefix)), noUnion_(noUnion), |
126 | | - guardString_(std::move(guardString)), |
127 | | - random_(static_cast<uint32_t>(::time(nullptr))) { |
| 121 | + guardString_(std::move(guardString)) { |
128 | 122 | } |
129 | 123 |
|
130 | 124 | void generate(const ValidSchema &schema); |
@@ -770,7 +764,14 @@ void CodeGen::emitGeneratedWarning() { |
770 | 764 | string CodeGen::guard() { |
771 | 765 | string h = headerFile_; |
772 | 766 | 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"; |
774 | 775 | } |
775 | 776 |
|
776 | 777 | void CodeGen::generate(const ValidSchema &schema) { |
|
0 commit comments