Skip to content

Commit

Permalink
Merge pull request #15 from crytic/dev-glob-target
Browse files Browse the repository at this point in the history
Improve solc detection for glob targets
  • Loading branch information
elopez authored Jul 28, 2022
2 parents b146de7 + f3f803e commit df7985c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ install_solc()

if [[ -f "$TARGET" ]]; then
SOLCVER="$(grep --no-filename '^pragma solidity' "$TARGET" | cut -d' ' -f3)"
else
elif [[ -d "$TARGET" ]]; then
pushd "$TARGET" >/dev/null
SOLCVER="$(grep --no-filename '^pragma solidity' -r --include \*.sol --exclude-dir node_modules | \
cut -d' ' -f3 | sort | uniq -c | sort -n | tail -1 | tr -s ' ' | cut -d' ' -f3)"
popd >/dev/null
else
echo "[-] Target is neither a file nor a directory, assuming it is a path glob"
SOLCVER="$( shopt -s globstar; for file in $TARGET; do
grep --no-filename '^pragma solidity' -r "$file" ; \
done | cut -d' ' -f3 | sort | uniq -c | sort -n | tail -1 | tr -s ' ' | cut -d' ' -f3)"
fi
SOLCVER="$(echo "$SOLCVER" | sed 's/[^0-9\.]//g')"

if [[ -z "$SOLCVER" ]]; then
# Fallback to latest version if the above fails.
# Fallback to latest version if the above fails.
SOLCVER="$(solc-select install | tail -1)"
fi

Expand Down

0 comments on commit df7985c

Please sign in to comment.