From bf0e6cec3bdb0492139a4921407915d4e9b1bbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Thu, 16 Jun 2022 18:21:09 -0300 Subject: [PATCH 1/2] Improve solc detection for glob targets This adjusts the solc detection behaviour to the following: * if the target is a file or directory, the existing behavior is retained; * otherwise, the target is assumed to be a glob expression and expanded before attempting to guess the solc version. Fixes: #2 --- entrypoint.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 346d423..41237a0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -32,16 +32,22 @@ 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="$( while read -r file; do + grep --no-filename '^pragma solidity' -r "$file" ; \ + done < <(compgen -G "$TARGET" || true) | \ + 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 From f3f803e6442048361540927e482ed766696792fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Thu, 16 Jun 2022 18:52:39 -0300 Subject: [PATCH 2/2] Accept globstar style globs --- entrypoint.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 41237a0..5c7ef96 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,10 +39,9 @@ install_solc() popd >/dev/null else echo "[-] Target is neither a file nor a directory, assuming it is a path glob" - SOLCVER="$( while read -r file; do + SOLCVER="$( shopt -s globstar; for file in $TARGET; do grep --no-filename '^pragma solidity' -r "$file" ; \ - done < <(compgen -G "$TARGET" || true) | \ - cut -d' ' -f3 | sort | uniq -c | sort -n | tail -1 | tr -s ' ' | cut -d' ' -f3)" + 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')"