assemble_vintf: getFlagIfUnset harder errors
assemble_vintf fails if, for BOARD_SEPOLICY_VERS, POLICYVERS and
FRAMEWORK_VBMETA_VERSION:
- If the environment variable is set and the value has an unknown
format; or
- If the environment variable is set and it conflicts with an
existing value (e.g. hard-coded in a device manifest file)
Remove spurious warnings for undefined environment variables since
the manifest / matrix merge logic merge these values from fragments;
it is okay for these values to be undefined in fragments.
Fixes: 116614862
Test: cd hardware/interfaces/health/storage/1.0/default && mma
Test: builds
Change-Id: I387cedf03ff0c8f703507f4a95e5807eb03b65d2
diff --git a/AssembleVintf.cpp b/AssembleVintf.cpp
index 5da734d..16df52a 100644
--- a/AssembleVintf.cpp
+++ b/AssembleVintf.cpp
@@ -108,10 +108,12 @@
/**
* Set *out to environment variable only if *out is a dummy value (i.e. default constructed).
- * Return true if *out is set to environment variable, otherwise false.
+ * Return false if a fatal error has occurred:
+ * - The environment variable has an unknown format
+ * - The value of the environment variable does not match a predefined variable in the files
*/
template <typename T>
- bool getFlagIfUnset(const std::string& envKey, T* out, bool log = true) const {
+ bool getFlagIfUnset(const std::string& envKey, T* out) const {
bool hasExistingValue = !(*out == T{});
bool hasEnvValue = false;
@@ -119,29 +121,23 @@
std::string envStrValue = getEnv(envKey);
if (!envStrValue.empty()) {
if (!parse(envStrValue, &envValue)) {
- if (log) {
- std::cerr << "Cannot parse " << envValue << "." << std::endl;
- }
+ std::cerr << "Cannot parse " << envValue << "." << std::endl;
return false;
}
hasEnvValue = true;
}
if (hasExistingValue) {
- if (hasEnvValue && log) {
- std::cerr << "Warning: cannot override existing value " << *out << " with "
- << envKey << " (which is " << envValue << ")." << std::endl;
+ if (hasEnvValue && (*out != envValue)) {
+ std::cerr << "Cannot override existing value " << *out << " with " << envKey
+ << " (which is " << envValue << ")." << std::endl;
+ return false;
}
- return false;
+ return true;
}
- if (!hasEnvValue) {
- if (log) {
- std::cerr << "Warning: " << envKey << " is not specified. Default to " << T{} << "."
- << std::endl;
- }
- return false;
+ if (hasEnvValue) {
+ *out = envValue;
}
- *out = envValue;
return true;
}
@@ -365,7 +361,9 @@
}
if (halManifest->mType == SchemaType::DEVICE) {
- (void)getFlagIfUnset("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion);
+ if (!getFlagIfUnset("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion)) {
+ return false;
+ }
if (!setDeviceFcmVersion(halManifest)) {
return false;
@@ -584,10 +582,13 @@
v.minorVer);
}
- getFlagIfUnset("POLICYVERS", &matrix->framework.mSepolicy.mKernelSepolicyVersion,
- false /* log */);
- getFlagIfUnset("FRAMEWORK_VBMETA_VERSION", &matrix->framework.mAvbMetaVersion,
- false /* log */);
+ if (!getFlagIfUnset("POLICYVERS",
+ &matrix->framework.mSepolicy.mKernelSepolicyVersion)) {
+ return false;
+ }
+ if (!getFlagIfUnset("FRAMEWORK_VBMETA_VERSION", &matrix->framework.mAvbMetaVersion)) {
+ return false;
+ }
// Hard-override existing AVB version
getFlag("FRAMEWORK_VBMETA_VERSION_OVERRIDE", &matrix->framework.mAvbMetaVersion,
false /* log */);