Move StringFromEnv to libcuttlefish_utils
Test: run on gce
Bug: 79170615
Change-Id: Ia052238f4b19573886fbc34d79aec42567ab310d
Merged-In: Ia052238f4b19573886fbc34d79aec42567ab310d
(cherry picked from commit 2a777f67372e2baf4a8216880773b90a0f8ec777)
diff --git a/Android.bp b/Android.bp
index 0dc83d0..be209a0 100644
--- a/Android.bp
+++ b/Android.bp
@@ -161,6 +161,7 @@
shared_libs: [
"vsoc_lib",
"libbase",
+ "libcuttlefish_utils",
],
defaults: ["cuttlefish_host_only"],
}
@@ -202,6 +203,7 @@
shared_libs: [
"vsoc_lib",
"libcuttlefish_fs",
+ "libcuttlefish_utils",
"cuttlefish_auto_resources",
"libbase",
],
diff --git a/common/commands/wifi_relay/Android.bp b/common/commands/wifi_relay/Android.bp
index 5393d4a..fa7a678 100644
--- a/common/commands/wifi_relay/Android.bp
+++ b/common/commands/wifi_relay/Android.bp
@@ -25,6 +25,7 @@
"libbase",
"vsoc_lib",
"libcuttlefish_fs",
+ "libcuttlefish_utils",
"cuttlefish_auto_resources",
"liblog",
"libnl",
diff --git a/common/frontend/socket_forward_proxy/Android.bp b/common/frontend/socket_forward_proxy/Android.bp
index 3eba53f..3a1a11d 100644
--- a/common/frontend/socket_forward_proxy/Android.bp
+++ b/common/frontend/socket_forward_proxy/Android.bp
@@ -21,6 +21,7 @@
shared_libs: [
"libbase",
"libcuttlefish_fs",
+ "libcuttlefish_utils",
"libcuttlefish_strings",
"cuttlefish_auto_resources",
"vsoc_lib",
diff --git a/common/libs/utils/Android.bp b/common/libs/utils/Android.bp
index 3b6992c..c30543b 100644
--- a/common/libs/utils/Android.bp
+++ b/common/libs/utils/Android.bp
@@ -17,6 +17,7 @@
name: "libcuttlefish_utils",
srcs: [
"subprocess.cpp",
+ "environment.cpp",
],
header_libs: [
"cuttlefish_glog",
diff --git a/common/libs/utils/environment.cpp b/common/libs/utils/environment.cpp
new file mode 100644
index 0000000..11a0b8c
--- /dev/null
+++ b/common/libs/utils/environment.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/libs/utils/environment.h"
+
+#include <stdlib.h>
+
+namespace cvd {
+
+std::string StringFromEnv(const std::string& varname,
+ const std::string& defval) {
+ const char* const valstr = getenv(varname.c_str());
+ if (!valstr) {
+ return defval;
+ }
+ return valstr;
+}
+
+} // namespace cvd
diff --git a/common/libs/utils/environment.h b/common/libs/utils/environment.h
new file mode 100644
index 0000000..1aab8de
--- /dev/null
+++ b/common/libs/utils/environment.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <string>
+
+namespace cvd {
+
+std::string StringFromEnv(const std::string& varname,
+ const std::string& defval);
+
+} // namespace cvd
diff --git a/common/libs/utils/subprocess.cpp b/common/libs/utils/subprocess.cpp
index 593c421..4fd5f80 100644
--- a/common/libs/utils/subprocess.cpp
+++ b/common/libs/utils/subprocess.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "common/libs//utils/subprocess.h"
+#include "common/libs/utils/subprocess.h"
#include <stdlib.h>
#include <sys/types.h>
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index e37b98c..4c74009 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -37,6 +37,7 @@
#include "common/libs/fs/shared_fd.h"
#include "common/libs/fs/shared_select.h"
#include "common/libs/strings/str_split.h"
+#include "common/libs/utils/environment.h"
#include "common/libs/utils/subprocess.h"
#include "common/vsoc/lib/vsoc_memory.h"
#include "common/vsoc/shm/screen_layout.h"
@@ -554,8 +555,8 @@
config->disable_usb_adb();
}
- config->set_cuttlefish_env_path(
- StringFromEnv("HOME", ".") + "/.cuttlefish.sh");
+ config->set_cuttlefish_env_path(cvd::StringFromEnv("HOME", ".") +
+ "/.cuttlefish.sh");
return true;
}
diff --git a/host/commands/record_audio/Android.bp b/host/commands/record_audio/Android.bp
index b7bfe92..13f47ef 100644
--- a/host/commands/record_audio/Android.bp
+++ b/host/commands/record_audio/Android.bp
@@ -23,6 +23,7 @@
],
shared_libs: [
"libbase",
+ "libcuttlefish_utils",
"vsoc_lib",
],
static_libs: [
diff --git a/host/frontend/vnc_server/Android.bp b/host/frontend/vnc_server/Android.bp
index 6508945..241df83 100644
--- a/host/frontend/vnc_server/Android.bp
+++ b/host/frontend/vnc_server/Android.bp
@@ -31,6 +31,7 @@
shared_libs: [
"vsoc_lib",
"libcuttlefish_fs",
+ "libcuttlefish_utils",
"cuttlefish_tcp_socket",
"cuttlefish_auto_resources",
"libbase",
diff --git a/host/libs/config/Android.bp b/host/libs/config/Android.bp
index 9b70a07..38d4ac0 100644
--- a/host/libs/config/Android.bp
+++ b/host/libs/config/Android.bp
@@ -23,6 +23,7 @@
],
shared_libs: [
"libcuttlefish_fs",
+ "libcuttlefish_utils",
"cuttlefish_auto_resources",
"libbase",
],
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index f6e0b11..ea0d5db 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -28,6 +28,8 @@
#include <glog/logging.h>
#include <json/json.h>
+#include "common/libs/utils/environment.h"
+
DEFINE_string(config_file,
vsoc::GetDefaultPerInstanceDir() + "/cuttlefish_config.json",
"A file from where to load the config values. This flag is "