Skip to content

Commit 1fda0b3

Browse files
authored
Merge pull request #241 from pipermerriam/piper/solidity-0.4.9
Backport some utilities from 2.0 line
2 parents d83ca4e + 12bf0e2 commit 1fda0b3

30 files changed

+618
-267
lines changed

.travis.yml

+19-18
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ dist: trusty
55
sudo: required
66
env:
77
matrix:
8-
# Solc 0.4.6 py35
9-
- TOX_ENV=py27-stdlib SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.6.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6
10-
- TOX_ENV=py27-gevent SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.6.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6
11-
# Solc 0.4.6 py34
12-
- TOX_ENV=py34-stdlib SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.6.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6
13-
- TOX_ENV=py34-gevent SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.6.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6
14-
# Solc 0.4.6 py35
15-
- TOX_ENV=py35-stdlib SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.6.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6
16-
- TOX_ENV=py35-gevent SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.6.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.6
17-
# Solc 0.4.1 py35
18-
#- TOX_ENV=py35 SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.1/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.1.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.1
19-
# Solc 0.4.2 py35
20-
#- TOX_ENV=py35-stdlib SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.2/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.2.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.2
21-
#- TOX_ENV=py35-gevent SOLC_BINARY=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.2/solc SOLC_INSTALL_SCRIPT=$TRAVIS_BUILD_DIR/bin/install_solc-0.4.2.sh LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/solc-versions/solc-0.4.2
22-
- TOX_ENV=flake8 SOLC_BINARY=ls SOLC_INSTALL_SCRIPT=/bin/ls
8+
#
9+
# Solc 0.4.8
10+
#
11+
# py27
12+
- TOX_ENV=py27-stdlib SOLC_VERSION=0.4.8
13+
- TOX_ENV=py27-gevent SOLC_VERSION=0.4.8
14+
# py34
15+
- TOX_ENV=py34-stdlib SOLC_VERSION=0.4.8
16+
- TOX_ENV=py34-gevent SOLC_VERSION=0.4.8
17+
# py35
18+
- TOX_ENV=py35-stdlib SOLC_VERSION=0.4.8
19+
- TOX_ENV=py35-gevent SOLC_VERSION=0.4.8
20+
# Linting
21+
- TOX_ENV=flake8
2322
global:
2423
- CHAIN_SYNC_BLOCK_DELTA=100
2524
cache:
@@ -28,16 +27,18 @@ cache:
2827
- $HOME/.ethash/
2928
- $TRAVIS_BUILD_DIR/.tox --recreate
3029
before_install:
30+
- if [ -n "$SOLC_VERSION" ]; then export SOLC_BINARY="$TRAVIS_BUILD_DIR/solc-versions/solc-$SOLC_VERSION/solc"; fi
31+
- if [ -n "$SOLC_VERSION" ]; then export LD_LIBRARY_PATH="$TRAVIS_BUILD_DIR/solc-versions/solc-$SOLC_VERSION"; fi
32+
- if [ -n "$SOLC_VERSION" ]; then sudo apt-get install -y tree unzip; fi
3133
- sudo add-apt-repository -y ppa:ethereum/ethereum
3234
- sudo apt-get update
3335
install:
34-
- sudo apt-get install -y tree unzip
35-
- /.$SOLC_INSTALL_SCRIPT
36+
- if [ -n "$SOLC_VERSION" ]; then /.$TRAVIS_BUILD_DIR/bin/install_solc.sh; fi
3637
- travis_retry sudo apt-get install -y ethereum
3738
- travis_retry pip install setuptools --upgrade
3839
- travis_retry pip install tox
3940
before_script:
40-
- $SOLC_BINARY --version
41+
- if [ -n "$SOLC_BINARY" ]; then $SOLC_BINARY --version; fi
4142
- mkdir -p $HOME/.ethash
4243
- geth makedag 0 $HOME/.ethash
4344
script:

bin/install_solc-0.4.1.sh

-16
This file was deleted.

bin/install_solc-0.4.2.sh

-16
This file was deleted.

bin/install_solc-0.4.6.sh

-16
This file was deleted.

bin/install_solc.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
#
3+
# Install solc
4+
#
5+
6+
set -e
7+
set -u
8+
9+
mkdir -p solc-versions/solc-$SOLC_VERSION
10+
cd solc-versions/solc-$SOLC_VERSION
11+
git clone --recurse-submodules --branch v$SOLC_VERSION --depth 50 https://github.com/ethereum/solidity.git
12+
./solidity/scripts/install_deps.sh
13+
wget https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solidity-ubuntu-trusty.zip
14+
unzip solidity-ubuntu-trusty.zip
15+
echo "Solidity installed at $TRAVIS_BUILD_DIR/solc-versions/solc-$SOLC_VERSION/solc"
16+
tree $TRAVIS_BUILD_DIR/solc-versions/solc-$SOLC_VERSION

docs/config.rst

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ Enable or disable compile optimization.
6363
* default: ``True``
6464

6565

66+
Determine compiler output.
67+
68+
* key: ``compilation.settings.output_values``
69+
* value: List of strings
70+
* default: ``['bin', 'bin-runtime', 'abi']``
71+
72+
6673
Chains
6774
^^^^^^
6875

populus/assets/config.schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
"properties": {
4141
"optimize": {
4242
"type": "boolean"
43+
},
44+
"output_values": {
45+
"title": "Determines which compiler values will be output by the solc compiler",
46+
"type": "array",
47+
"items": {
48+
"type": "string"
49+
}
4350
}
4451
}
4552
},

populus/chain.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
HTTPProvider,
2222
)
2323

24+
from populus.legacy.contracts import (
25+
get_contract_library_dependencies,
26+
)
27+
2428
from populus.utils.functional import (
2529
cached_property,
2630
)
@@ -37,11 +41,12 @@
3741
get_blockchains_dir,
3842
tempdir,
3943
)
44+
from populus.utils.linking import (
45+
link_bytecode_by_name,
46+
)
4047
from populus.utils.contracts import (
4148
construct_contract_factories,
4249
package_contracts,
43-
get_contract_library_dependencies,
44-
link_bytecode,
4550
)
4651
from populus.utils.chains import (
4752
get_chaindata_dir,
@@ -307,7 +312,7 @@ def _link_code(self, bytecodes,
307312
}
308313

309314
linked_bytecodes = [
310-
link_bytecode(bytecode, **all_link_dependencies)
315+
link_bytecode_by_name(bytecode, **all_link_dependencies)
311316
for bytecode in bytecodes
312317
]
313318
return linked_bytecodes

populus/compilation.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
DEFAULT_CONTRACTS_DIR
1616
)
1717
from populus.utils.compile import (
18-
normalize_contract_data,
18+
process_compiler_output,
1919
get_contract_meta,
2020
)
2121

@@ -41,11 +41,14 @@ def write_compiled_sources(project_dir, compiled_sources):
4141
return compiled_contract_path
4242

4343

44+
DEFAULT_COMPILER_OUTPUT_VALUES = ['bin', 'bin-runtime', 'abi']
45+
46+
4447
def compile_project_contracts(project_dir, contracts_dir, compiler_settings=None):
4548
if compiler_settings is None:
4649
compiler_settings = {}
4750

48-
compiler_settings.setdefault('output_values', ['bin', 'bin-runtime', 'abi'])
51+
compiler_settings.setdefault('output_values', DEFAULT_COMPILER_OUTPUT_VALUES)
4952
contract_source_paths = find_project_contracts(project_dir, contracts_dir)
5053
try:
5154
compiled_contracts = compile_files(contract_source_paths, **compiler_settings)
@@ -55,11 +58,11 @@ def compile_project_contracts(project_dir, contracts_dir, compiler_settings=None
5558
solc_version = get_solc_version()
5659
contract_meta = get_contract_meta(compiler_settings, solc_version)
5760

58-
normalized_compiled_contracts = {
59-
contract_name: normalize_contract_data(contract_data, contract_meta)
61+
normalized_compiled_contracts = dict(
62+
process_compiler_output(contract_name, contract_data, contract_meta)
6063
for contract_name, contract_data
6164
in compiled_contracts.items()
62-
}
65+
)
6366

6467
return contract_source_paths, normalized_compiled_contracts
6568

populus/legacy/contracts.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from populus.utils.linking import (
2+
find_link_references,
3+
)
4+
5+
6+
def get_contract_library_dependencies(bytecode, full_contract_names):
7+
"""
8+
Given a contract bytecode and an iterable of all of the known full names of
9+
contracts, returns a set of the contract names that this contract bytecode
10+
depends on.
11+
To get the full dependency graph use the `get_recursive_contract_dependencies`
12+
function.
13+
"""
14+
return {
15+
ref.full_name for ref in find_link_references(bytecode, full_contract_names)
16+
}

populus/migrations/operations.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
force_text,
55
)
66

7-
from populus.utils.contracts import (
7+
from populus.legacy.contracts import (
88
get_contract_library_dependencies,
99
)
10+
1011
from populus.utils.deploy import (
1112
deploy_contract,
1213
)

populus/migrations/registrar.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from populus.utils.compile import (
99
normalize_contract_data,
1010
)
11-
from populus.utils.contracts import (
12-
link_bytecode,
11+
from populus.utils.linking import (
12+
link_bytecode_by_name,
1313
)
1414

1515

@@ -34,14 +34,15 @@ def is_solc_04x():
3434

3535
def get_compiled_registrar_contract():
3636
if is_solc_03x():
37-
compiled_contracts = compile_files([REGISTRAR_V3_SOURCE_PATH])
37+
registrar_source_path = REGISTRAR_V3_SOURCE_PATH
3838
elif is_solc_04x():
39-
compiled_contracts = compile_files([REGISTRAR_V4_SOURCE_PATH])
39+
registrar_source_path = REGISTRAR_V4_SOURCE_PATH
4040
else:
4141
raise ValueError(
4242
"Unsupported version of solc. Found: {0}. Only 0.3.x and 0.4.x "
4343
"are supported".format(get_solc_version())
4444
)
45+
compiled_contracts = compile_files([registrar_source_path])
4546
contract_data = compiled_contracts['Registrar']
4647
normalized_data = normalize_contract_data(contract_data, {})
4748
return normalized_data
@@ -73,7 +74,7 @@ def get_contract_from_registrar(chain,
7374

7475
contract_address = registrar.call().getAddress(registrar_key)
7576

76-
expected_runtime = link_bytecode(
77+
expected_runtime = link_bytecode_by_name(
7778
contract_factory.code_runtime,
7879
**link_dependencies
7980
)

populus/utils/compile.py

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
)
88

99

10+
def process_compiler_output(name_from_compiler, data_from_compiler, contract_meta):
11+
# TODO: use the source path.
12+
_, _, contract_name = name_from_compiler.rpartition(':')
13+
contract_data = normalize_contract_data(data_from_compiler, contract_meta)
14+
return contract_name, contract_data
15+
16+
1017
@cast_return_to_dict
1118
def normalize_contract_data(contract_data, contract_meta):
1219
yield 'meta', contract_meta

0 commit comments

Comments
 (0)