summaryrefslogtreecommitdiff
path: root/test/utils/test_env.hpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
commit619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch)
tree01868de723cb82c86842f33743fa7b14e24c1fa3 /test/utils/test_env.hpp
downloadjustbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz
Initial self-hosting commit
This is the initial version of our tool that is able to build itself. In can be bootstrapped by ./bin/bootstrap.py Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com> Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'test/utils/test_env.hpp')
-rw-r--r--test/utils/test_env.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/utils/test_env.hpp b/test/utils/test_env.hpp
new file mode 100644
index 00000000..3bc49901
--- /dev/null
+++ b/test/utils/test_env.hpp
@@ -0,0 +1,44 @@
+#ifndef INCLUDED_SRC_TEST_UTILS_TEST_ENV_HPP
+#define INCLUDED_SRC_TEST_UTILS_TEST_ENV_HPP
+
+#include <cstdlib>
+#include <map>
+#include <optional>
+#include <sstream>
+#include <string>
+
+#include "test/utils/logging/log_config.hpp"
+
+[[nodiscard]] static inline auto ReadPlatformPropertiesFromEnv()
+ -> std::map<std::string, std::string> {
+ std::map<std::string, std::string> properties{};
+ auto* execution_props = std::getenv("REMOTE_EXECUTION_PROPERTIES");
+ if (execution_props not_eq nullptr) {
+ std::istringstream pss(std::string{execution_props});
+ std::string keyval_pair;
+ while (std::getline(pss, keyval_pair, ';')) {
+ std::istringstream kvss{keyval_pair};
+ std::string key;
+ std::string val;
+ if (not std::getline(kvss, key, ':') or
+ not std::getline(kvss, val, ':')) {
+ Logger::Log(LogLevel::Error,
+ "parsing property '{}' failed.",
+ keyval_pair);
+ std::exit(EXIT_FAILURE);
+ }
+ properties.emplace(std::move(key), std::move(val));
+ }
+ }
+ return properties;
+}
+
+[[nodiscard]] static inline auto ReadRemoteAddressFromEnv()
+ -> std::optional<std::string> {
+ auto* execution_address = std::getenv("REMOTE_EXECUTION_ADDRESS");
+ return execution_address == nullptr
+ ? std::nullopt
+ : std::make_optional(std::string{execution_address});
+}
+
+#endif // INCLUDED_SRC_TEST_UTILS_TEST_ENV_HPP