|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +#------------------------------------------------------------------------------ |
| 4 | +# Script used for cross-platform comparison as part of the travis automation. |
| 5 | +# Splits all test source code into multiple files, generates bytecode and |
| 6 | +# uploads the bytecode into github.com/ethereum/solidity-test-bytecode where |
| 7 | +# another travis job is triggered to do the actual comparison. |
| 8 | +# |
| 9 | +# ------------------------------------------------------------------------------ |
| 10 | +# This file is part of solidity. |
| 11 | +# |
| 12 | +# solidity is free software: you can redistribute it and/or modify |
| 13 | +# it under the terms of the GNU General Public License as published by |
| 14 | +# the Free Software Foundation, either version 3 of the License, or |
| 15 | +# (at your option) any later version. |
| 16 | +# |
| 17 | +# solidity is distributed in the hope that it will be useful, |
| 18 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | +# GNU General Public License for more details. |
| 21 | +# |
| 22 | +# You should have received a copy of the GNU General Public License |
| 23 | +# along with solidity. If not, see <http://www.gnu.org/licenses/> |
| 24 | +# |
| 25 | +# (c) 2017 solidity contributors. |
| 26 | +#------------------------------------------------------------------------------ |
| 27 | + |
| 28 | +set -e |
| 29 | + |
| 30 | +SCRIPTDIR=$(dirname "$0") |
| 31 | +SCRIPTDIR=$(realpath "${SCRIPTDIR}") |
| 32 | + |
| 33 | + |
| 34 | +echo "Compiling all test contracts into bytecode..." |
| 35 | +TMPDIR=$(mktemp -d) |
| 36 | +( |
| 37 | + cd "${TMPDIR}" |
| 38 | + "${SCRIPTDIR}/isolate_tests.py" /src/test/ |
| 39 | + |
| 40 | + cat > solc <<EOF |
| 41 | +#!/usr/bin/env node |
| 42 | +var process = require('process') |
| 43 | +var fs = require('fs') |
| 44 | +
|
| 45 | +var compiler = require('/root/solc-js/wrapper.js')(require("${1}")) |
| 46 | +
|
| 47 | +for (var optimize of [false, true]) |
| 48 | +{ |
| 49 | + for (var filename of process.argv.slice(2)) |
| 50 | + { |
| 51 | + if (filename !== undefined) |
| 52 | + { |
| 53 | + var inputs = {} |
| 54 | + inputs[filename] = { content: fs.readFileSync(filename).toString() } |
| 55 | + var input = { |
| 56 | + language: 'Solidity', |
| 57 | + sources: inputs, |
| 58 | + settings: { |
| 59 | + optimizer: { enabled: optimize }, |
| 60 | + outputSelection: { '*': { '*': ['*'] } } |
| 61 | + } |
| 62 | + } |
| 63 | + try { |
| 64 | + var result = JSON.parse(compiler.compile(JSON.stringify(input))) |
| 65 | + if ( |
| 66 | + !('contracts' in result) || |
| 67 | + Object.keys(result['contracts']).length === 0 |
| 68 | + ) |
| 69 | + { |
| 70 | + // NOTE: do not exit here because this may be run on source which cannot be compiled |
| 71 | + console.log(filename + ': ERROR') |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + for (var outputName in result['contracts']) |
| 76 | + for (var contractName in result['contracts'][outputName]) |
| 77 | + { |
| 78 | + var contractData = result['contracts'][outputName][contractName]; |
| 79 | + if (contractData.evm !== undefined && contractData.evm.bytecode !== undefined) |
| 80 | + console.log(filename + ':' + contractName + ' ' + contractData.evm.bytecode.object) |
| 81 | + else |
| 82 | + console.log(filename + ':' + contractName + ' NO BYTECODE') |
| 83 | + console.log(filename + ':' + contractName + ' ' + contractData.metadata) |
| 84 | + } |
| 85 | + } |
| 86 | + } catch (e) { |
| 87 | + console.log(filename + ': FATAL ERROR') |
| 88 | + console.error(filename) |
| 89 | + console.error(inputs) |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | +EOF |
| 95 | + chmod +x solc |
| 96 | + ./solc *.sol > /tmp/report.txt |
| 97 | +) |
| 98 | +rm -rf "$TMPDIR" |
0 commit comments