mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
CommandLineInterface: Accept output streams as parameters
This commit is contained in:
@@ -70,7 +70,6 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#if !defined(STDERR_FILENO)
|
||||
@@ -86,25 +85,18 @@ using namespace solidity::langutil;
|
||||
namespace solidity::frontend
|
||||
{
|
||||
|
||||
namespace
|
||||
ostream& CommandLineInterface::sout(bool _markAsUsed)
|
||||
{
|
||||
|
||||
static bool g_hasOutput = false;
|
||||
|
||||
std::ostream& sout(bool _used = true)
|
||||
{
|
||||
if (_used)
|
||||
g_hasOutput = true;
|
||||
return cout;
|
||||
if (_markAsUsed)
|
||||
m_hasOutput = true;
|
||||
return m_sout;
|
||||
}
|
||||
|
||||
std::ostream& serr(bool _used = true)
|
||||
ostream& CommandLineInterface::serr(bool _markAsUsed)
|
||||
{
|
||||
if (_used)
|
||||
g_hasOutput = true;
|
||||
return cerr;
|
||||
}
|
||||
|
||||
if (_markAsUsed)
|
||||
m_hasOutput = true;
|
||||
return m_serr;
|
||||
}
|
||||
|
||||
#define cout
|
||||
@@ -497,11 +489,11 @@ void CommandLineInterface::createJson(string const& _fileName, string const& _js
|
||||
|
||||
bool CommandLineInterface::parseArguments(int _argc, char const* const* _argv)
|
||||
{
|
||||
CommandLineParser parser(sout(false), serr(false));
|
||||
CommandLineParser parser(sout(/* _markAsUsed */ false), serr(/* _markAsUsed */ false));
|
||||
bool success = parser.parse(_argc, _argv, isatty(fileno(stdin)));
|
||||
if (!success)
|
||||
return false;
|
||||
g_hasOutput = g_hasOutput || parser.hasOutput();
|
||||
m_hasOutput = m_hasOutput || parser.hasOutput();
|
||||
m_options = parser.options();
|
||||
|
||||
return true;
|
||||
@@ -626,7 +618,7 @@ bool CommandLineInterface::compile()
|
||||
|
||||
for (auto const& error: m_compiler->errors())
|
||||
{
|
||||
g_hasOutput = true;
|
||||
m_hasOutput = true;
|
||||
formatter.printErrorInformation(*error);
|
||||
}
|
||||
|
||||
@@ -635,7 +627,7 @@ bool CommandLineInterface::compile()
|
||||
}
|
||||
catch (CompilerError const& _exception)
|
||||
{
|
||||
g_hasOutput = true;
|
||||
m_hasOutput = true;
|
||||
formatter.printExceptionInformation(_exception, "Compiler error");
|
||||
return false;
|
||||
}
|
||||
@@ -669,7 +661,7 @@ bool CommandLineInterface::compile()
|
||||
serr() << "Documentation parsing error: " << *boost::get_error_info<errinfo_comment>(_error) << endl;
|
||||
else
|
||||
{
|
||||
g_hasOutput = true;
|
||||
m_hasOutput = true;
|
||||
formatter.printExceptionInformation(_error, _error.typeName());
|
||||
}
|
||||
|
||||
@@ -985,7 +977,7 @@ bool CommandLineInterface::assemble(
|
||||
|
||||
for (auto const& error: stack.errors())
|
||||
{
|
||||
g_hasOutput = true;
|
||||
m_hasOutput = true;
|
||||
formatter.printErrorInformation(*error);
|
||||
}
|
||||
if (!Error::containsOnlyWarnings(stack.errors()))
|
||||
@@ -1134,7 +1126,7 @@ void CommandLineInterface::outputCompilationResults()
|
||||
handleNatspec(false, contract);
|
||||
} // end of contracts iteration
|
||||
|
||||
if (!g_hasOutput)
|
||||
if (!m_hasOutput)
|
||||
{
|
||||
if (!m_options.output.dir.empty())
|
||||
sout() << "Compiler run successful. Artifact(s) can be found in directory " << m_options.output.dir << "." << endl;
|
||||
|
||||
Reference in New Issue
Block a user