aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/cpp/blaze_util.h')
-rw-r--r--src/main/cpp/blaze_util.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index b8055c3b0a..e7f8ba1c46 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -21,6 +21,7 @@
#include <sys/types.h>
+#include <map>
#include <sstream>
#include <string>
#include <vector>
@@ -106,6 +107,38 @@ std::string ToString(const T &value) {
// Revisit once client logging is fixed (b/32939567).
void SetDebugLog(bool enabled);
+// What WithEnvVar should do with an environment variable
+enum EnvVarAction { UNSET, SET };
+
+// What WithEnvVar should do with an environment variable
+struct EnvVarValue {
+ // What should be done with the given variable
+ EnvVarAction action;
+
+ // The value of the variable; ignored if action == UNSET
+ std::string value;
+
+ EnvVarValue() {}
+
+ EnvVarValue(EnvVarAction action, const std::string& value)
+ : action(action),
+ value(value) {}
+};
+
+// While this class is in scope, the specified environment variables will be set
+// to a specified value (or unset). When it leaves scope, changed variables will
+// be set to their original values.
+class WithEnvVars {
+ private:
+ std::map<std::string, EnvVarValue> _old_values;
+
+ void SetEnvVars(const std::map<std::string, EnvVarValue>& vars);
+
+ public:
+ WithEnvVars(const std::map<std::string, EnvVarValue>& vars);
+ ~WithEnvVars();
+};
+
} // namespace blaze
#endif // BAZEL_SRC_MAIN_CPP_BLAZE_UTIL_H_