Disable EnvUtil::setAsCurrentEnvironment() on platforms without clearenv()
authorChristopher Dykes <cdykes@fb.com>
Wed, 5 Apr 2017 19:50:28 +0000 (12:50 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 5 Apr 2017 19:52:23 +0000 (12:52 -0700)
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

folly/experimental/EnvUtil.cpp
folly/experimental/EnvUtil.h
folly/experimental/test/EnvUtilTest.cpp

index 5c16ee7407a53b6d2a80fa8d612190c9b01f0d36..1035575dc81a0c1542ddff612b38b7d44e250db1 100644 (file)
@@ -44,12 +44,14 @@ EnvironmentState EnvironmentState::fromCurrentEnvironment() {
   return EnvironmentState{std::move(data)};
 }
 
   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));
   }
 }
 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;
 
 std::vector<std::string> EnvironmentState::toVector() const {
   std::vector<std::string> result;
index 3ab3b16af726bf35aa4add3cdcca6da28318cf15..3ab06164fd5b8b1a36fd2dbc566206db31dc1394 100644 (file)
@@ -64,12 +64,14 @@ struct EnvironmentState {
     return &env_;
   }
 
     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();
   // 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;
 
   // Get a copy of the model environment in the form used by `folly::Subprocess`
   std::vector<std::string> toVector() const;
index bcac455da34643277472a2b11fd7afc1c9a66f38..1e1e3d2d8a8096064f25f06fd039f31a843bd399 100644 (file)
@@ -132,6 +132,7 @@ TEST(EnvironmentStateTest, Separation) {
   EXPECT_STREQ("foon", getenv("spork"));
 }
 
   EXPECT_STREQ("foon", getenv("spork"));
 }
 
+#if __linux__ && !FOLLY_MOBILE
 TEST(EnvironmentStateTest, Update) {
   EnvVarSaver saver{};
   auto env = EnvironmentState::fromCurrentEnvironment();
 TEST(EnvironmentStateTest, Update) {
   EnvVarSaver saver{};
   auto env = EnvironmentState::fromCurrentEnvironment();
@@ -141,6 +142,7 @@ TEST(EnvironmentStateTest, Update) {
   env.setAsCurrentEnvironment();
   EXPECT_STREQ("foon", getenv("spork"));
 }
   env.setAsCurrentEnvironment();
   EXPECT_STREQ("foon", getenv("spork"));
 }
+#endif
 
 TEST(EnvironmentStateTest, forSubprocess) {
   auto env = EnvironmentState::empty();
 
 TEST(EnvironmentStateTest, forSubprocess) {
   auto env = EnvironmentState::empty();