mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Evaluate absolute paths for imports in 'parsing' stage
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user