summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-12-31 02:24:58 -0600
committerandroid-build-team Robot2017-12-31 02:24:58 -0600
commit2437a770c7f6efb73d722cdac206402128eec2eb (patch)
tree7886d3854c611d9a875d40393892cc7986ee06b9
parent867ed81ea2defdcfbad6bc48c6efd7f332c807f1 (diff)
parent771c41f7555d5cfec1567c13e156de07843eb744 (diff)
downloadplatform-system-libvintf-2437a770c7f6efb73d722cdac206402128eec2eb.tar.gz
platform-system-libvintf-2437a770c7f6efb73d722cdac206402128eec2eb.tar.xz
platform-system-libvintf-2437a770c7f6efb73d722cdac206402128eec2eb.zip
Snap for 4521654 from 771c41f7555d5cfec1567c13e156de07843eb744 to pi-release
Change-Id: I0346f05514d8176dd7c28f1e7d6d0bde988b351d
-rw-r--r--assemble_vintf.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/assemble_vintf.cpp b/assemble_vintf.cpp
index 17f5d0c..fd8eb9f 100644
--- a/assemble_vintf.cpp
+++ b/assemble_vintf.cpp
@@ -79,6 +79,40 @@ class AssembleVintf {
79 return true; 79 return true;
80 } 80 }
81 81
82 /**
83 * Set *out to environment variable if *out is not a dummy value (i.e. default constructed).
84 */
85 template <typename T>
86 bool getFlagIfUnset(const std::string& envKey, T* out) {
87 bool hasExistingValue = !(*out == T{});
88
89 bool hasEnvValue = false;
90 T envValue;
91 const char* envCValue = getenv(envKey.c_str());
92 if (envCValue != nullptr) {
93 if (!parse(envCValue, &envValue)) {
94 std::cerr << "Cannot parse " << envCValue << "." << std::endl;
95 return false;
96 }
97 hasEnvValue = true;
98 }
99
100 if (hasExistingValue) {
101 if (hasEnvValue) {
102 std::cerr << "Warning: cannot override existing value " << *out << " with "
103 << envKey << " (which is " << envValue << ")." << std::endl;
104 }
105 return false;
106 }
107 if (!hasEnvValue) {
108 std::cerr << "Warning: " << envKey << " is not specified. Default to " << T{} << "."
109 << std::endl;
110 return false;
111 }
112 *out = envValue;
113 return true;
114 }
115
82 static bool getBooleanFlag(const char* key) { 116 static bool getBooleanFlag(const char* key) {
83 const char* envValue = getenv(key); 117 const char* envValue = getenv(key);
84 return envValue != nullptr && strcmp(envValue, "true") == 0; 118 return envValue != nullptr && strcmp(envValue, "true") == 0;