Skip to content

Commit

Permalink
Provide optional list of contract names to CompilerStack.compile
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Oct 4, 2017
1 parent 19274c7 commit f96e932
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ bool CompilerStack::parseAndAnalyze()
return parse() && analyze();
}

bool CompilerStack::isRequestedContract(ContractDefinition const& _contract) const
{
return
m_requestedContractNames.empty() ||
m_requestedContractNames.count(_contract.fullyQualifiedName()) ||
m_requestedContractNames.count(_contract.name());
}

bool CompilerStack::compile()
{
if (m_stackState < AnalysisSuccessful)
Expand All @@ -262,7 +270,8 @@ bool CompilerStack::compile()
for (Source const* source: m_sourceOrder)
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
compileContract(*contract, compiledContracts);
if (isRequestedContract(*contract))
compileContract(*contract, compiledContracts);
this->link();
m_stackState = CompilationSuccessful;
return true;
Expand Down
11 changes: 11 additions & 0 deletions libsolidity/interface/CompilerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ class CompilerStack: boost::noncopyable
m_optimizeRuns = _runs;
}

/// Sets the list of requested contract names. If empty, no filtering is performed and every contract
/// found in the supplied sources is compiled. Names are cleared iff @a _contractNames is missing.
void setRequestedContractNames(std::set<std::string> const& _contractNames = std::set<std::string>{})
{
m_requestedContractNames = _contractNames;
}

/// @arg _metadataLiteralSources When true, store sources as literals in the contract metadata.
void useMetadataLiteralSources(bool _metadataLiteralSources) { m_metadataLiteralSources = _metadataLiteralSources; }

Expand Down Expand Up @@ -259,6 +266,9 @@ class CompilerStack: boost::noncopyable
/// Helper function to return path converted strings.
std::string sanitizePath(std::string const& _path) const { return boost::filesystem::path(_path).generic_string(); }

/// @returns true if the contract is requested to be compiled.
bool isRequestedContract(ContractDefinition const& _contract) const;

/// Compile a single contract and put the result in @a _compiledContracts.
void compileContract(
ContractDefinition const& _contract,
Expand Down Expand Up @@ -297,6 +307,7 @@ class CompilerStack: boost::noncopyable
ReadCallback::Callback m_smtQuery;
bool m_optimize = false;
unsigned m_optimizeRuns = 200;
std::set<std::string> m_requestedContractNames;
std::map<std::string, h160> m_libraries;
/// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
/// "context:prefix=target"
Expand Down

0 comments on commit f96e932

Please sign in to comment.