fbthrift: add Thrift compiler patch to scrub build directory references
Part of my Darwin reproducibility work.
This commit is contained in:
@@ -43,6 +43,10 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
};
|
||||
|
||||
patches = [
|
||||
# Map `$NIX_BUILD_TOP` to `/build` in the Thrift compiler output to
|
||||
# avoid reproducibility issues on Darwin.
|
||||
./scrub-build-directory-from-output.patch
|
||||
|
||||
# Remove a line that breaks the build due to the CMake classic of
|
||||
# incorrect path concatenation.
|
||||
./remove-cmake-install-rpath.patch
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
diff --git a/thrift/compiler/generate/t_mstch_cpp2_generator.cc b/thrift/compiler/generate/t_mstch_cpp2_generator.cc
|
||||
index d232df5158..96d15efbda 100644
|
||||
--- a/thrift/compiler/generate/t_mstch_cpp2_generator.cc
|
||||
+++ b/thrift/compiler/generate/t_mstch_cpp2_generator.cc
|
||||
@@ -1116,6 +1116,13 @@
|
||||
mstch::node autogen_path() {
|
||||
std::string path = service_->program()->path();
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
+ // Ensure output reproducibility for Nix builds.
|
||||
+ if (auto nix_build_top = std::getenv("NIX_BUILD_TOP")) {
|
||||
+ auto prefix = std::string(nix_build_top) + "/";
|
||||
+ if (path.starts_with(prefix)) {
|
||||
+ path.replace(0, prefix.length(), "/build/");
|
||||
+ }
|
||||
+ }
|
||||
return path;
|
||||
}
|
||||
mstch::node cpp_includes() {
|
||||
diff --git a/thrift/compiler/generate/t_whisker_generator.cc b/thrift/compiler/generate/t_whisker_generator.cc
|
||||
index 99a6ac14af..fa91a05247 100644
|
||||
--- a/thrift/compiler/generate/t_whisker_generator.cc
|
||||
+++ b/thrift/compiler/generate/t_whisker_generator.cc
|
||||
@@ -572,6 +572,13 @@
|
||||
// use posix path separators, even on windows, for autogen comment
|
||||
// to avoid spurious fixture regen diffs
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
+ // Ensure output reproducibility for Nix builds.
|
||||
+ if (auto nix_build_top = std::getenv("NIX_BUILD_TOP")) {
|
||||
+ auto prefix = std::string(nix_build_top) + "/";
|
||||
+ if (path.starts_with(prefix)) {
|
||||
+ path.replace(0, prefix.length(), "/build/");
|
||||
+ }
|
||||
+ }
|
||||
return path;
|
||||
});
|
||||
def.property("namespaces", [&](const t_program& self) -> map::ptr {
|
||||
Reference in New Issue
Block a user