[REFACTOR] embed file name into manifest/matrix object
Instead of attaching name to the object as a new type Named<T>,
embed the file name or file path of the object into the object
directly.
The type Named<T> is re-written so that its subclass extends its
setFileName() and fileName() methods.
Test: libvintf_test, vintf_object_test
Bug: 118757553
Change-Id: Ib3356cf56632b00c77c26df1cfa1a1aaf8878876
diff --git a/AssembleVintf.cpp b/AssembleVintf.cpp
index a954acd..f084076 100644
--- a/AssembleVintf.cpp
+++ b/AssembleVintf.cpp
@@ -294,18 +294,16 @@
return true;
}
- template <typename S>
- using Schemas = std::vector<Named<S>>;
- using HalManifests = Schemas<HalManifest>;
- using CompatibilityMatrices = Schemas<CompatibilityMatrix>;
+ using HalManifests = std::vector<HalManifest>;
+ using CompatibilityMatrices = std::vector<CompatibilityMatrix>;
template <typename M>
- void outputInputs(const Schemas<M>& inputs) {
+ void outputInputs(const std::vector<M>& inputs) {
out() << "<!--" << std::endl;
out() << " Input:" << std::endl;
for (const auto& e : inputs) {
- if (!e.name.empty()) {
- out() << " " << base::Basename(e.name) << std::endl;
+ if (!e.fileName().empty()) {
+ out() << " " << base::Basename(e.fileName()) << std::endl;
}
}
out() << "-->" << std::endl;
@@ -364,17 +362,17 @@
bool assembleHalManifest(HalManifests* halManifests) {
std::string error;
- HalManifest* halManifest = &halManifests->front().object;
+ HalManifest* halManifest = &halManifests->front();
for (auto it = halManifests->begin() + 1; it != halManifests->end(); ++it) {
- const std::string& path = it->name;
- HalManifest& manifestToAdd = it->object;
+ const std::string& path = it->fileName();
+ HalManifest& manifestToAdd = *it;
if (manifestToAdd.level() != Level::UNSPECIFIED) {
if (halManifest->level() == Level::UNSPECIFIED) {
halManifest->mLevel = manifestToAdd.level();
} else if (halManifest->level() != manifestToAdd.level()) {
std::cerr << "Inconsistent FCM Version in HAL manifests:" << std::endl
- << " File '" << halManifests->front().name << "' has level "
+ << " File '" << halManifests->front().fileName() << "' has level "
<< halManifest->level() << std::endl
<< " File '" << path << "' has level " << manifestToAdd.level()
<< std::endl;
@@ -516,8 +514,8 @@
Level getLowestFcmVersion(const CompatibilityMatrices& matrices) {
Level ret = Level::UNSPECIFIED;
for (const auto& e : matrices) {
- if (ret == Level::UNSPECIFIED || ret > e.object.level()) {
- ret = e.object.level();
+ if (ret == Level::UNSPECIFIED || ret > e.level()) {
+ ret = e.level();
}
}
return ret;
@@ -537,7 +535,7 @@
}
}
- if (matrices->front().object.mType == SchemaType::DEVICE) {
+ if (matrices->front().mType == SchemaType::DEVICE) {
builtMatrix = CompatibilityMatrix::combineDeviceMatrices(matrices, &error);
matrix = builtMatrix.get();
@@ -551,7 +549,7 @@
auto& valueInMatrix = matrix->device.mVendorNdk;
if (!valueInMatrix.version().empty() && valueInMatrix.version() != vndkVersion) {
std::cerr << "Hard-coded <vendor-ndk> version in device compatibility matrix ("
- << matrices->front().name << "), '" << valueInMatrix.version()
+ << matrices->front().fileName() << "), '" << valueInMatrix.version()
<< "', does not match value inferred "
<< "from BOARD_VNDK_VERSION '" << vndkVersion << "'" << std::endl;
return false;
@@ -564,7 +562,7 @@
}
}
- if (matrices->front().object.mType == SchemaType::FRAMEWORK) {
+ if (matrices->front().mType == SchemaType::FRAMEWORK) {
Level deviceLevel =
checkManifest != nullptr ? checkManifest->level() : Level::UNSPECIFIED;
if (deviceLevel == Level::UNSPECIFIED) {
@@ -638,17 +636,19 @@
template <typename Schema, typename AssembleFunc>
AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName,
AssembleFunc assemble, std::string* error) {
- Schemas<Schema> schemas;
+ std::vector<Schema> schemas;
Schema schema;
+ schema.setFileName(mInFiles.front().name());
if (!converter(&schema, read(mInFiles.front().stream()), error)) {
return TRY_NEXT;
}
auto firstType = schema.type();
- schemas.emplace_back(mInFiles.front().name(), std::move(schema));
+ schemas.emplace_back(std::move(schema));
for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
Schema additionalSchema;
const std::string& fileName = it->name();
+ additionalSchema.setFileName(fileName);
if (!converter(&additionalSchema, read(it->stream()), error)) {
std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " "
<< schemaName << " (but the first file is a valid " << firstType << " "
@@ -662,7 +662,7 @@
return FAIL_AND_EXIT;
}
- schemas.emplace_back(fileName, std::move(additionalSchema));
+ schemas.emplace_back(std::move(additionalSchema));
}
return assemble(&schemas) ? SUCCESS : FAIL_AND_EXIT;
}