Skip to content

Commit

Permalink
Strip comments before compiling for solidity contracts to avoid hitting
Browse files Browse the repository at this point in the history
bug described in ethereum/solc-js#460
  • Loading branch information
yarkinwho committed Jul 21, 2024
1 parent 8add202 commit be21a2f
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion solidity_contracts/compile_tools/compile_solidity_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,51 @@ set -o pipefail
# 3 solcjs --starndard-json has some bugs (https://github.com/ethereum/solc-js/issues/460) so we can only use "content" as input.
# 4 To copy the source code into the json file, we have to escape \\ \" \t \n. (Ignore \b \r \f as we shouldn't have them in sol file)
tmpfile=$(mktemp)
cat "$SOLIDITY_SOURCE_FILE_PATH" \
awk 'BEGIN {
found=0;
}
{
spos=index($0,"/*");
epos=index($0,"*/");
if(spos > 0 && epos ==0)
{
printf("%s\n",substr($0,1,spos-1));
found=1;
}
else if(spos == 0 && epos >0)
{
found=0;
if(length($0) != epos+1)
{
printf("%s\n",substr($0,epos+2));
}
}
else if(spos > 0 && epos > 0)
{
printf("%s %s\n",substr($0,1,spos-1),substr($0,epos+2));
}
else if(found==0)
{
cpp_comment=index($0,"//");
if(cpp_comment == 0)
{
print;
}
else
{
printf("%s\n",substr($0,1,cpp_comment-1));
}
}
}
END {
if(found==1)
{
print "there is unmatched comment"
}
}' "$SOLIDITY_SOURCE_FILE_PATH" \
| awk -v token="__CONTRACT_CONTENT" '
BEGIN {
RS = "\0" # Set record separator to null to read the whole input
Expand Down

0 comments on commit be21a2f

Please sign in to comment.