From f24ca136e8b4faee91f05b56b43a505c0ee1331d Mon Sep 17 00:00:00 2001 From: Ruben de Vries Date: Mon, 20 Jun 2016 15:03:21 +0200 Subject: [PATCH 1/2] use solc stderr for CompileError --- ethereum/_solidity.py | 20 +++++++++++++------- ethereum/tests/test_solidity.py | 13 +++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ethereum/_solidity.py b/ethereum/_solidity.py index 3b743798a..0de63a1a2 100644 --- a/ethereum/_solidity.py +++ b/ethereum/_solidity.py @@ -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(): @@ -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): @@ -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): diff --git a/ethereum/tests/test_solidity.py b/ethereum/tests/test_solidity.py index bddf4ad8c..5ce6386af 100644 --- a/ethereum/tests/test_solidity.py +++ b/ethereum/tests/test_solidity.py @@ -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() From dd2a98229b8a9aca28a7130ba2e9f3848da35f43 Mon Sep 17 00:00:00 2001 From: Ruben de Vries Date: Mon, 20 Jun 2016 17:27:32 +0200 Subject: [PATCH 2/2] print solc version in travis for debuggin --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 83ced25b8..418fea221 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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