mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Compile only requested sources and contracts
This commit is contained in:
parent
7de18b37c2
commit
6f8fd309a2
@ -9,6 +9,7 @@ Language Features:
|
||||
Compiler Features:
|
||||
* eWasm: Highly experimental eWasm output using ``--ewasm`` in the commandline interface or output selection of ``ewasm.wast`` in standard-json.
|
||||
* Metadata: Update the swarm hash, changes ``bzzr0`` to ``bzzr1`` and urls to use ``bzz-raw://``.
|
||||
* Standard JSON Interface: compile only selected sources and contracts.
|
||||
|
||||
|
||||
|
||||
|
@ -398,13 +398,29 @@ bool CompilerStack::parseAndAnalyze()
|
||||
return parse() && analyze();
|
||||
}
|
||||
|
||||
bool CompilerStack::isRequestedContract(ContractDefinition const& _contract) const
|
||||
bool CompilerStack::isRequestedSource(string const& _sourceName) const
|
||||
{
|
||||
return
|
||||
m_requestedContractNames.empty() ||
|
||||
m_requestedContractNames.count(_contract.fullyQualifiedName()) ||
|
||||
m_requestedContractNames.count(_contract.name()) ||
|
||||
m_requestedContractNames.count(":" + _contract.name());
|
||||
m_requestedContractNames.count("") ||
|
||||
m_requestedContractNames.count(_sourceName);
|
||||
}
|
||||
|
||||
bool CompilerStack::isRequestedContract(ContractDefinition const& _contract) const
|
||||
{
|
||||
/// In case nothing was specified in outputSelection.
|
||||
if (m_requestedContractNames.empty())
|
||||
return true;
|
||||
|
||||
for (auto const& key: vector<string>{"", _contract.sourceUnitName()})
|
||||
{
|
||||
auto const& it = m_requestedContractNames.find(key);
|
||||
if (it != m_requestedContractNames.end())
|
||||
if (it->second.count(_contract.name()) || it->second.count(""))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CompilerStack::compile()
|
||||
@ -900,7 +916,8 @@ void CompilerStack::resolveImports()
|
||||
};
|
||||
|
||||
for (auto const& sourcePair: m_sources)
|
||||
toposort(&sourcePair.second);
|
||||
if (isRequestedSource(sourcePair.first))
|
||||
toposort(&sourcePair.second);
|
||||
|
||||
swap(m_sourceOrder, sourceOrder);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -145,9 +146,12 @@ public:
|
||||
/// Must be set before parsing.
|
||||
void setEVMVersion(langutil::EVMVersion _version = langutil::EVMVersion{});
|
||||
|
||||
/// 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>{}) {
|
||||
/// Sets the requested contract names by source.
|
||||
/// 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::map<std::string, std::set<std::string>> const& _contractNames = std::map<std::string, std::set<std::string>>{})
|
||||
{
|
||||
m_requestedContractNames = _contractNames;
|
||||
}
|
||||
|
||||
@ -318,6 +322,9 @@ private:
|
||||
std::string applyRemapping(std::string const& _path, std::string const& _context);
|
||||
void resolveImports();
|
||||
|
||||
/// @returns true if the source is requested to be compiled.
|
||||
bool isRequestedSource(std::string const& _sourceName) const;
|
||||
|
||||
/// @returns true if the contract is requested to be compiled.
|
||||
bool isRequestedContract(ContractDefinition const& _contract) const;
|
||||
|
||||
@ -387,7 +394,7 @@ private:
|
||||
ReadCallback::Callback m_readFile;
|
||||
OptimiserSettings m_optimiserSettings;
|
||||
langutil::EVMVersion m_evmVersion;
|
||||
std::set<std::string> m_requestedContractNames;
|
||||
std::map<std::string, std::set<std::string>> m_requestedContractNames;
|
||||
bool m_generateIR;
|
||||
bool m_generateEWasm;
|
||||
std::map<std::string, h160> m_libraries;
|
||||
|
@ -100,20 +100,19 @@ Json::Value formatErrorWithException(
|
||||
return formatError(_warning, _type, _component, message, formattedMessage, sourceLocation);
|
||||
}
|
||||
|
||||
set<string> requestedContractNames(Json::Value const& _outputSelection)
|
||||
map<string, set<string>> requestedContractNames(Json::Value const& _outputSelection)
|
||||
{
|
||||
set<string> names;
|
||||
map<string, set<string>> contracts;
|
||||
for (auto const& sourceName: _outputSelection.getMemberNames())
|
||||
{
|
||||
string key = (sourceName == "*") ? "" : sourceName;
|
||||
for (auto const& contractName: _outputSelection[sourceName].getMemberNames())
|
||||
{
|
||||
/// Consider the "all sources" shortcuts as requesting everything.
|
||||
if (contractName == "*" || contractName == "")
|
||||
return set<string>();
|
||||
names.insert((sourceName == "*" ? "" : sourceName) + ":" + contractName);
|
||||
string value = (contractName == "*") ? "" : contractName;
|
||||
contracts[key].insert(value);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
return contracts;
|
||||
}
|
||||
|
||||
/// Returns true iff @a _hash (hex with 0x prefix) is the Keccak256 hash of the binary data in @a _content.
|
||||
|
Loading…
Reference in New Issue
Block a user