Summary:
Implementing `clearenv()` correctly on multiple OS's without relying on underlying implementation details is significantly more complicated, and this is preventing being able to build on OSX.
This function isn't actually used anywhere currently.
Reviewed By: yfeldblum
Differential Revision:
D4832473
fbshipit-source-id:
a80aabb5a223264746ab45e3138d065bce5fe99c
return EnvironmentState{std::move(data)};
}
+#if __linux__ && !FOLLY_MOBILE
void EnvironmentState::setAsCurrentEnvironment() {
PCHECK(0 == clearenv());
for (const auto& kvp : env_) {
PCHECK(0 == setenv(kvp.first.c_str(), kvp.second.c_str(), (int)true));
}
}
+#endif
std::vector<std::string> EnvironmentState::toVector() const {
std::vector<std::string> result;
return &env_;
}
+#if __linux__ && !FOLLY_MOBILE
// Update the process environment with the one in the stored model.
// Subsequent changes to the model do not alter the process environment. The
// state of the process environment during execution of this method is not
// defined. If the process environment is altered by another thread during the
// execution of this method the results are not defined.
void setAsCurrentEnvironment();
+#endif
// Get a copy of the model environment in the form used by `folly::Subprocess`
std::vector<std::string> toVector() const;
EXPECT_STREQ("foon", getenv("spork"));
}
+#if __linux__ && !FOLLY_MOBILE
TEST(EnvironmentStateTest, Update) {
EnvVarSaver saver{};
auto env = EnvironmentState::fromCurrentEnvironment();
env.setAsCurrentEnvironment();
EXPECT_STREQ("foon", getenv("spork"));
}
+#endif
TEST(EnvironmentStateTest, forSubprocess) {
auto env = EnvironmentState::empty();