Improve error message for conflicting HAL major versions.
Provide more debug information (specifically, names of files where
the conflicting entry is located).
Test: libvintf_test
Test: vintf_object_test
Test: manually create a conflict, then m check-vintf-all
Fixes: 118757553
Change-Id: I45b2262936975df947fbd0864477f32e18ce813a
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index f5a1aee..3fdc6e2 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -24,15 +24,29 @@
namespace android {
namespace vintf {
-bool ManifestHal::isValid() const {
- std::unordered_set<size_t> existing;
- for (const auto &v : versions) {
- if (existing.find(v.majorVer) != existing.end()) {
- return false;
- }
- existing.insert(v.majorVer);
+bool ManifestHal::isValid(std::string* error) const {
+ if (error) {
+ error->clear();
}
- return transportArch.isValid();
+
+ bool success = true;
+ std::map<size_t, Version> existing;
+ for (const auto &v : versions) {
+ auto&& [it, inserted] = existing.emplace(v.majorVer, v);
+ if (inserted) {
+ continue;
+ }
+ success = false;
+ if (error) {
+ *error += "Duplicated major version: " + to_string(v) + " vs. " + to_string(it->second);
+ }
+ }
+ std::string transportArchError;
+ if (!transportArch.isValid(&transportArchError)) {
+ success = false;
+ if (error) *error += transportArchError;
+ }
+ return success;
}
bool ManifestHal::operator==(const ManifestHal &other) const {