2017-03-22 19:19:57 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Script used for cross-platform comparison as part of the travis automation.
|
|
|
|
# Splits all test source code into multiple files, generates bytecode and
|
|
|
|
# uploads the bytecode into github.com/ethereum/solidity-test-bytecode where
|
|
|
|
# another travis job is triggered to do the actual comparison.
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# This file is part of solidity.
|
|
|
|
#
|
|
|
|
# solidity is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# solidity is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with solidity. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
#
|
|
|
|
# (c) 2017 solidity contributors.
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-02-03 10:55:26 +00:00
|
|
|
if [[ "${TRAVIS_PULL_REQUEST_BRANCH}" != "" ]]; then
|
|
|
|
# Variable is set to the branch's name iff current job is a pull request,
|
|
|
|
# or is set to empty string if it is a push build.
|
|
|
|
echo "Skipping bytecode comparison."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-03-22 19:19:57 +00:00
|
|
|
REPO_ROOT="$(dirname "$0")"/../..
|
|
|
|
|
2019-02-25 13:58:54 +00:00
|
|
|
if test -z "$1"; then
|
|
|
|
BUILD_DIR="build"
|
|
|
|
else
|
|
|
|
BUILD_DIR="$1"
|
|
|
|
fi
|
|
|
|
|
2017-03-22 19:19:57 +00:00
|
|
|
echo "Compiling all test contracts into bytecode..."
|
|
|
|
TMPDIR=$(mktemp -d)
|
|
|
|
(
|
|
|
|
cd "$REPO_ROOT"
|
|
|
|
REPO_ROOT=$(pwd) # make it absolute
|
|
|
|
cd "$TMPDIR"
|
|
|
|
|
|
|
|
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/test/
|
|
|
|
|
|
|
|
if [[ "$SOLC_EMSCRIPTEN" = "On" ]]
|
|
|
|
then
|
2018-10-31 12:39:32 +00:00
|
|
|
# npm install solc
|
2018-11-06 14:14:44 +00:00
|
|
|
git clone --depth 1 https://github.com/ethereum/solc-js.git solc-js
|
|
|
|
( cd solc-js; npm install )
|
2019-02-25 13:58:54 +00:00
|
|
|
cp "$REPO_ROOT/emscripten_build/libsolc/soljson.js" solc-js/
|
2017-03-22 19:19:57 +00:00
|
|
|
cat > solc <<EOF
|
|
|
|
#!/usr/bin/env node
|
|
|
|
var process = require('process')
|
|
|
|
var fs = require('fs')
|
|
|
|
|
2018-11-06 14:14:44 +00:00
|
|
|
var compiler = require('./solc-js/wrapper.js')(require('./solc-js/soljson.js'))
|
2017-03-22 19:19:57 +00:00
|
|
|
|
2017-03-22 19:56:44 +00:00
|
|
|
for (var optimize of [false, true])
|
2017-03-22 19:19:57 +00:00
|
|
|
{
|
2017-03-22 19:56:44 +00:00
|
|
|
for (var filename of process.argv.slice(2))
|
2017-03-22 19:19:57 +00:00
|
|
|
{
|
2017-03-22 19:56:44 +00:00
|
|
|
if (filename !== undefined)
|
2017-03-22 19:19:57 +00:00
|
|
|
{
|
2017-03-22 19:56:44 +00:00
|
|
|
var inputs = {}
|
2018-11-22 11:33:58 +00:00
|
|
|
inputs[filename] = { content: fs.readFileSync(filename).toString() }
|
2018-11-06 14:14:44 +00:00
|
|
|
var input = {
|
|
|
|
language: 'Solidity',
|
|
|
|
sources: inputs,
|
|
|
|
settings: {
|
|
|
|
optimizer: { enabled: optimize },
|
|
|
|
outputSelection: { '*': { '*': ['evm.bytecode.object', 'metadata'] } }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var result = JSON.parse(compiler.compile(JSON.stringify(input)))
|
2018-11-22 11:33:58 +00:00
|
|
|
if (
|
|
|
|
!('contracts' in result) ||
|
|
|
|
Object.keys(result['contracts']).length === 0 ||
|
|
|
|
!result['contracts'][filename] ||
|
|
|
|
Object.keys(result['contracts'][filename]).length === 0
|
|
|
|
)
|
2017-03-22 19:56:44 +00:00
|
|
|
{
|
2018-11-22 11:33:58 +00:00
|
|
|
// NOTE: do not exit here because this may be run on source which cannot be compiled
|
2017-03-22 19:56:44 +00:00
|
|
|
console.log(filename + ': ERROR')
|
|
|
|
}
|
|
|
|
else
|
2017-03-22 19:19:57 +00:00
|
|
|
{
|
2018-11-22 11:33:58 +00:00
|
|
|
for (var contractName in result['contracts'][filename])
|
2017-03-22 19:56:44 +00:00
|
|
|
{
|
2019-03-04 15:19:34 +00:00
|
|
|
var contractData = result['contracts'][filename][contractName];
|
|
|
|
if (contractData.evm !== undefined && contractData.evm.bytecode !== undefined)
|
|
|
|
console.log(filename + ':' + contractName + ' ' + contractData.evm.bytecode.object)
|
|
|
|
else
|
|
|
|
console.log(filename + ':' + contractName + ' NO BYTECODE')
|
|
|
|
console.log(filename + ':' + contractName + ' ' + contractData.metadata)
|
2017-03-22 19:56:44 +00:00
|
|
|
}
|
2017-03-22 19:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
chmod +x solc
|
|
|
|
./solc *.sol > report.txt
|
|
|
|
else
|
2019-02-25 13:58:54 +00:00
|
|
|
$REPO_ROOT/scripts/bytecodecompare/prepare_report.py $REPO_ROOT/$BUILD_DIR/solc/solc
|
2017-03-22 19:19:57 +00:00
|
|
|
fi
|
|
|
|
|
2017-04-18 10:32:38 +00:00
|
|
|
if [ "$TRAVIS_SECURE_ENV_VARS" = "true" ]
|
|
|
|
then
|
|
|
|
openssl aes-256-cbc -K $encrypted_60701c962b9c_key -iv $encrypted_60701c962b9c_iv -in "$REPO_ROOT"/scripts/bytecodecompare/deploy_key.enc -out deploy_key -d
|
|
|
|
chmod 600 deploy_key
|
|
|
|
eval `ssh-agent -s`
|
|
|
|
ssh-add deploy_key
|
2017-03-22 19:19:57 +00:00
|
|
|
|
2017-04-18 10:32:38 +00:00
|
|
|
git clone --depth 2 git@github.com:ethereum/solidity-test-bytecode.git
|
|
|
|
cd solidity-test-bytecode
|
|
|
|
git config user.name "travis"
|
|
|
|
git config user.email "chris@ethereum.org"
|
|
|
|
git clean -f -d -x
|
2017-03-22 19:19:57 +00:00
|
|
|
|
2020-02-14 20:59:06 +00:00
|
|
|
DIRNAME=$(cd "$REPO_ROOT" && git show -s --format="%cd-%H" --date="format:%Y-%m-%d-%H-%M")
|
2017-05-24 12:36:46 +00:00
|
|
|
mkdir -p "$DIRNAME"
|
|
|
|
REPORT="$DIRNAME/$ZIP_SUFFIX.txt"
|
2017-04-18 10:32:38 +00:00
|
|
|
cp ../report.txt "$REPORT"
|
2017-05-19 13:43:26 +00:00
|
|
|
# Only push if adding actually worked, i.e. there were changes.
|
2017-07-03 16:25:37 +00:00
|
|
|
if git add "$REPORT" && git commit -a -m "Added report $REPORT"
|
2017-05-19 13:43:26 +00:00
|
|
|
then
|
|
|
|
git pull --rebase
|
|
|
|
git push origin
|
|
|
|
else
|
|
|
|
echo "Adding report failed, it might already exist in the repository."
|
|
|
|
fi
|
2017-04-18 10:32:38 +00:00
|
|
|
fi
|
2017-03-22 19:19:57 +00:00
|
|
|
)
|
2017-05-24 12:36:46 +00:00
|
|
|
rm -rf "$TMPDIR"
|