Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve solc detection for glob targets #15

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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