Evaluate absolute paths for imports in 'parsing' stage

This commit is contained in:
Marenz
2021-11-08 16:34:02 +01:00
committed by chriseth
parent cede36930d
commit fc224f74c7
7 changed files with 101 additions and 11 deletions
+17 -9
View File
@@ -350,8 +350,22 @@ bool CompilerStack::parse()
else
{
source.ast->annotation().path = path;
for (auto const& import: ASTNode::filteredNodes<ImportDirective>(source.ast->nodes()))
{
solAssert(!import->path().empty(), "Import path cannot be empty.");
// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
import->annotation().absolutePath = applyRemapping(util::absolutePath(
import->path(),
path
), path);
}
if (m_stopAfter >= ParsedAndImported)
for (auto const& newSource: loadMissingSources(*source.ast, path))
for (auto const& newSource: loadMissingSources(*source.ast))
{
string const& newPath = newSource.first;
string const& newContents = newSource.second;
@@ -1091,7 +1105,7 @@ string const& CompilerStack::Source::ipfsUrl() const
return ipfsUrlCached;
}
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath)
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast)
{
solAssert(m_stackState < ParsedAndImported, "");
StringMap newSources;
@@ -1100,14 +1114,8 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string
for (auto const& node: _ast.nodes())
if (ImportDirective const* import = dynamic_cast<ImportDirective*>(node.get()))
{
solAssert(!import->path().empty(), "Import path cannot be empty.");
string const& importPath = *import->annotation().absolutePath;
string importPath = util::absolutePath(import->path(), _sourcePath);
// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
importPath = applyRemapping(importPath, _sourcePath);
import->annotation().absolutePath = importPath;
if (m_sources.count(importPath) || newSources.count(importPath))
continue;