Attach filenames to objects appropriately.
Now that HalManifest and CompatibilityMatrix has file names/paths,
set them appropriately so that we have more information for
debugging.
Test: libvintf_test
Test: vintf_object_test
Bug: 118757553
Change-Id: Ic2f1ff824ce6a4fd20607becd1fe939e7fae7b38
diff --git a/AssembleVintf.cpp b/AssembleVintf.cpp
index f084076..71ea1bc 100644
--- a/AssembleVintf.cpp
+++ b/AssembleVintf.cpp
@@ -47,10 +47,12 @@
// It takes ownership on the istream.
class NamedIstream {
public:
+ NamedIstream() = default;
NamedIstream(const std::string& name, std::unique_ptr<std::istream>&& stream)
: mName(name), mStream(std::move(stream)) {}
const std::string& name() const { return mName; }
std::istream& stream() { return *mStream; }
+ bool hasStream() { return mStream != nullptr; }
private:
std::string mName;
@@ -433,9 +435,10 @@
}
out().flush();
- if (mCheckFile != nullptr) {
+ if (mCheckFile.hasStream()) {
CompatibilityMatrix checkMatrix;
- if (!gCompatibilityMatrixConverter(&checkMatrix, read(*mCheckFile), &error)) {
+ checkMatrix.setFileName(mCheckFile.name());
+ if (!gCompatibilityMatrixConverter(&checkMatrix, read(mCheckFile.stream()), &error)) {
std::cerr << "Cannot parse check file as a compatibility matrix: " << error
<< std::endl;
return false;
@@ -527,9 +530,10 @@
std::unique_ptr<HalManifest> checkManifest;
std::unique_ptr<CompatibilityMatrix> builtMatrix;
- if (mCheckFile != nullptr) {
+ if (mCheckFile.hasStream()) {
checkManifest = std::make_unique<HalManifest>();
- if (!gHalManifestConverter(checkManifest.get(), read(*mCheckFile), &error)) {
+ checkManifest->setFileName(mCheckFile.name());
+ if (!gHalManifestConverter(checkManifest.get(), read(mCheckFile.stream()), &error)) {
std::cerr << "Cannot parse check file as a HAL manifest: " << error << std::endl;
return false;
}
@@ -707,9 +711,9 @@
return it->stream();
}
- std::istream& setCheckInputStream(Istream&& in) override {
- mCheckFile = std::move(in);
- return *mCheckFile;
+ std::istream& setCheckInputStream(const std::string& name, Istream&& in) override {
+ mCheckFile = NamedIstream(name, std::move(in));
+ return mCheckFile.stream();
}
bool hasKernelVersion(const KernelVersion& kernelVer) const override {
@@ -763,7 +767,7 @@
private:
std::vector<NamedIstream> mInFiles;
Ostream mOutRef;
- Istream mCheckFile;
+ NamedIstream mCheckFile;
bool mOutputMatrix = false;
bool mHasSetHalsOnlyFlag = false;
SerializeFlags::Type mSerializeFlags = SerializeFlags::EVERYTHING;
@@ -783,7 +787,8 @@
}
bool AssembleVintf::openCheckFile(const std::string& path) {
- return static_cast<std::ifstream&>(setCheckInputStream(std::make_unique<std::ifstream>(path)))
+ return static_cast<std::ifstream&>(
+ setCheckInputStream(path, std::make_unique<std::ifstream>(path)))
.is_open();
}