Apply CleanPath() before comparing paths
Paths are sometimes prefixed with "./". CleanPath() is moved from
FakeIoDelegate to IoDelegate so that Parser uses it before comparing
paths.
Ideally, we should use std::filesystem::path::lexically_normal(), but
it's not available on windows platform which we support.
Removing "./" is good enough for most cases. To be specific, this
happens when we pass "-I.".
Bug: n/a
Test: m (aidl_unittests)
Change-Id: Ied6eaf1b264102d997306ac0cc2c32934056b27c
diff --git a/parser.cpp b/parser.cpp
index 93770bb..abe1dbf 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -28,16 +28,17 @@
const AidlDocument* Parser::Parse(const std::string& filename,
const android::aidl::IoDelegate& io_delegate,
AidlTypenames& typenames) {
+ auto clean_path = android::aidl::IoDelegate::CleanPath(filename);
// reuse pre-parsed document from typenames
for (auto& doc : typenames.AllDocuments()) {
- if (doc->GetLocation().GetFile() == filename) {
+ if (doc->GetLocation().GetFile() == clean_path) {
return doc.get();
}
}
// Make sure we can read the file first, before trashing previous state.
- unique_ptr<string> raw_buffer = io_delegate.GetFileContents(filename);
+ unique_ptr<string> raw_buffer = io_delegate.GetFileContents(clean_path);
if (raw_buffer == nullptr) {
- AIDL_ERROR(filename) << "Error while opening file for parsing";
+ AIDL_ERROR(clean_path) << "Error while opening file for parsing";
return nullptr;
}
@@ -45,7 +46,7 @@
// nulls at the end.
raw_buffer->append(2u, '\0');
- Parser parser(filename, *raw_buffer, typenames);
+ Parser parser(clean_path, *raw_buffer, typenames);
if (yy::parser(&parser).parse() != 0 || parser.HasError()) {
return nullptr;