Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

use solc stderr for CompileError #361

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ before_install:
- sudo add-apt-repository -y ppa:ethereum/ethereum
- sudo apt-get update
- sudo apt-get install -y solc
- solc --version
env:
matrix:
- TOX_ENV=py27
Expand Down
20 changes: 13 additions & 7 deletions ethereum/_solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ def solc_arguments(libraries=None, combined='bin,abi', optimize=True):
return args


def solc_parse_output(compiler_output):
def solc_parse_output(returncode, stdout, stderr):
""" Parses the compiler output. """
result = yaml.safe_load(compiler_output)['contracts']
if returncode:
raise CompileError('compilation failed: %s' % str(stderr).replace('\\n', '\n'))

result = yaml.safe_load(stdout)['contracts']

if 'bin' in result.values()[0]:
for value in result.values():
Expand Down Expand Up @@ -251,9 +254,12 @@ def compile_file(filepath, libraries=None, combined='bin,abi', optimize=True):
args.insert(0, get_compiler_path())
args.append(filename)

output = subprocess.check_output(args, cwd=workdir)

return solc_parse_output(output)
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=workdir)
stdoutdata = process.stdout.read().strip()
stderrdata = process.stderr.read().strip()

return solc_parse_output(process.returncode, stdoutdata, stderrdata)


def compile_contract(filepath, contract_name, libraries=None, combined='bin,abi', optimize=True):
Expand Down Expand Up @@ -291,10 +297,10 @@ def compile_code(sourcecode, libraries=None, combined='bin,abi', optimize=True):
args = solc_arguments(libraries=libraries, combined=combined, optimize=optimize)
args.insert(0, get_compiler_path())

process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdoutdata, _ = process.communicate(input=sourcecode)
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdoutdata, stderrdata = process.communicate(input=sourcecode)

return solc_parse_output(stdoutdata)
return solc_parse_output(process.returncode, stdoutdata, stderrdata)


class Solc(object):
Expand Down
13 changes: 13 additions & 0 deletions ethereum/tests/test_solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
CONTRACTS_DIR = path.join(path.dirname(__file__), 'contracts')


@pytest.mark.skipif(not SOLIDITY_AVAILABLE, reason='solc compiler not available')
def test_compile_error():
code = '''
notacontract test {

}
'''

s = tester.state()
with pytest.raises(_solidity.CompileError):
s.abi_contract(code, language='solidity')


@pytest.mark.skipif(not SOLIDITY_AVAILABLE, reason='solc compiler not available')
def test_library_from_file():
state = tester.state()
Expand Down