Skip to content

Commit ea38ff0

Browse files
authored
Merge pull request ethereum#9715 from ethereum/macosx-readlink
OSX: Fix readlink & ASTImportTest.sh issues.
2 parents 6b38c64 + 5f7b4a2 commit ea38ff0

File tree

3 files changed

+71
-20
lines changed

3 files changed

+71
-20
lines changed

scripts/ASTImportTest.sh

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#!/usr/bin/env bash
22

3+
set -e
4+
35
# Bash script to test the ast-import option of the compiler by
46
# first exporting a .sol file to JSON, then loading it into the compiler
57
# and exporting it again. The second JSON should be identical to the first
6-
7-
REPO_ROOT=$(readlink -f "$(dirname "$0")"/..)
8+
READLINK=readlink
9+
if [[ "$OSTYPE" == "darwin"* ]]; then
10+
READLINK=greadlink
11+
fi
12+
REPO_ROOT=$(${READLINK} -f "$(dirname "$0")"/..)
813
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}
914
SOLC=${SOLIDITY_BUILD_DIR}/solc/solc
1015
SPLITSOURCES=${REPO_ROOT}/scripts/splitSources.py
@@ -83,8 +88,11 @@ do
8388
FILETMP=$(mktemp -d)
8489
cd $FILETMP
8590

91+
set +e
8692
OUTPUT=$($SPLITSOURCES $solfile)
87-
if [ $? != 1 ]
93+
SPLITSOURCES_RC=$?
94+
set -e
95+
if [ ${SPLITSOURCES_RC} == 0 ]
8896
then
8997
# echo $OUTPUT
9098
NSOURCES=$((NSOURCES - 1))
@@ -93,9 +101,26 @@ do
93101
testImportExportEquivalence $i $OUTPUT
94102
NSOURCES=$((NSOURCES + 1))
95103
done
96-
97-
else
104+
elif [ ${SPLITSOURCES_RC} == 1 ]
105+
then
98106
testImportExportEquivalence $solfile
107+
elif [ ${SPLITSOURCES_RC} == 2 ]
108+
then
109+
# The script will exit with return code 2, if an UnicodeDecodeError occurred.
110+
# This is the case if e.g. some tests are using invalid utf-8 sequences. We will ignore
111+
# these errors, but print the actual output of the script.
112+
echo -e "\n${OUTPUT}\n"
113+
testImportExportEquivalence $solfile
114+
else
115+
# All other return codes will be treated as critical errors. The script will exit.
116+
echo -e "\nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES}. Aborting."
117+
echo -e "\n${OUTPUT}\n"
118+
119+
cd $WORKINGDIR
120+
# Delete temporary files
121+
rm -rf $FILETMP
122+
123+
exit 1
99124
fi
100125

101126
cd $WORKINGDIR

scripts/splitSources.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@
1111

1212
import sys
1313
import os
14+
import traceback
1415

1516
hasMultipleSources = False
1617
createdSources = []
1718

19+
20+
def uncaught_exception_hook(exc_type, exc_value, exc_traceback):
21+
# The script `scripts/ASTImportTest.sh` will interpret return code 3
22+
# as a critical error (because of the uncaught exception) and will
23+
# terminate further execution.
24+
print("Unhandled exception: %s", "".join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
25+
sys.exit(3)
26+
27+
1828
def extractSourceName(line):
1929
if line.find("/") > -1:
2030
filePath = line[13: line.rindex("/")]
@@ -23,6 +33,7 @@ def extractSourceName(line):
2333
return filePath, srcName
2434
return False, line[line.find(":")+2 : line.find(" ====")]
2535

36+
2637
# expects the first line of lines to be "==== Source: sourceName ===="
2738
# writes the following source into a file named sourceName
2839
def writeSourceToFile(lines):
@@ -45,18 +56,29 @@ def writeSourceToFile(lines):
4556
writeSourceToFile(lines[1+idx:])
4657
break
4758

59+
4860
if __name__ == '__main__':
4961
filePath = sys.argv[1]
50-
# decide if file has multiple sources
51-
lines = open(filePath, mode='r', encoding='utf8').read().splitlines()
52-
if lines[0][:12] == "==== Source:":
53-
hasMultipleSources = True
54-
writeSourceToFile(lines)
55-
56-
if hasMultipleSources:
57-
srcString = ""
58-
for src in createdSources:
59-
srcString += src + ' '
60-
print(srcString)
61-
else:
62-
sys.exit(1)
62+
sys.excepthook = uncaught_exception_hook
63+
64+
try:
65+
# decide if file has multiple sources
66+
lines = open(filePath, mode='r', encoding='utf8').read().splitlines()
67+
if lines[0][:12] == "==== Source:":
68+
hasMultipleSources = True
69+
writeSourceToFile(lines)
70+
71+
if hasMultipleSources:
72+
srcString = ""
73+
for src in createdSources:
74+
srcString += src + ' '
75+
print(srcString)
76+
sys.exit(0)
77+
else:
78+
sys.exit(1)
79+
80+
except UnicodeDecodeError as ude:
81+
print("UnicodeDecodeError in '" + filePath + "': " + str(ude))
82+
print("This is expected for some tests containing invalid utf8 sequences. "
83+
"Exception will be ignored.")
84+
sys.exit(2)

scripts/test_antlr_grammar.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
set -e
44

5-
ROOT_DIR=$(readlink -f "$(dirname "$0")"/..)
5+
READLINK=readlink
6+
if [[ "$OSTYPE" == "darwin"* ]]; then
7+
READLINK=greadlink
8+
fi
9+
ROOT_DIR=$(${READLINK} -f "$(dirname "$0")"/..)
610
WORKDIR="${ROOT_DIR}/build/antlr"
711
ANTLR_JAR="${ROOT_DIR}/build/deps/antlr4.jar"
812
ANTLR_JAR_URI="https://www.antlr.org/download/antlr-4.8-complete.jar"
@@ -54,7 +58,7 @@ failed_count=0
5458
test_file()
5559
{
5660
local SOL_FILE
57-
SOL_FILE="$(readlink -m "${1}")"
61+
SOL_FILE="$(${READLINK} -m "${1}")"
5862
local cur=${2}
5963
local max=${3}
6064
local solOrYul=${4}

0 commit comments

Comments
 (0)