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

Stylecheck script fails on MacOS #13492 #14348

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion libsolidity/analysis/ControlFlowBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ void ControlFlowBuilder::operator()(yul::FunctionCall const& _functionCall)
solAssert(m_currentNode && m_inlineAssembly, "");
yul::ASTWalker::operator()(_functionCall);

if (auto const *builtinFunction = m_inlineAssembly->dialect().builtin(_functionCall.functionName.name))
if (auto const* builtinFunction = m_inlineAssembly->dialect().builtin(_functionCall.functionName.name))
{
if (builtinFunction->controlFlowSideEffects.canTerminate)
connect(m_currentNode, m_transactionReturnNode);
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/ControlFlowBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ControlFlowBuilder: private ASTConstVisitor, private yul::ASTWalker

CFGNode* newLabel();
CFGNode* createLabelHere();
void placeAndConnectLabel(CFGNode *_node);
void placeAndConnectLabel(CFGNode* _node);

CFG::NodeContainer& m_nodeContainer;

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const&
{
bool isLocalOrReturn = false;
if (auto const* identifier = dynamic_cast<Identifier const*>(&_expression))
if (auto const *variableDeclaration = dynamic_cast<VariableDeclaration const*>(identifier->annotation().referencedDeclaration))
if (auto const* variableDeclaration = dynamic_cast<VariableDeclaration const*>(identifier->annotation().referencedDeclaration))
if (variableDeclaration->isLocalOrReturn())
isLocalOrReturn = true;
if (!isLocalOrReturn)
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ASTNode const* _scope) const
if (auto const* functionDefinition = dynamic_cast<FunctionDefinition const*>(m_declaration))
{
solAssert(functionDefinition->visibility() > Visibility::Internal, "");
auto const *contract = dynamic_cast<ContractDefinition const*>(m_declaration->scope());
auto const* contract = dynamic_cast<ContractDefinition const*>(m_declaration->scope());
solAssert(contract, "");
solAssert(contract->isLibrary(), "");
return {{"selector", TypeProvider::fixedBytes(4)}};
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/CompilerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class CompilerContext
/// Stack of current visited AST nodes, used for location attachment
std::stack<ASTNode const*> m_visitedNodes;
/// The runtime context if in Creation mode, this is used for generating tags that would be stored into the storage and then used at runtime.
CompilerContext *m_runtimeContext;
CompilerContext* m_runtimeContext;
/// The index of the runtime subroutine.
size_t m_runtimeSub = std::numeric_limits<size_t>::max();
/// An index of low-level function labels by name.
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ bool ExpressionCompiler::visit(IndexRangeAccess const& _indexAccess)

Type const& baseType = *_indexAccess.baseExpression().annotation().type;

ArrayType const *arrayType = dynamic_cast<ArrayType const*>(&baseType);
ArrayType const* arrayType = dynamic_cast<ArrayType const*>(&baseType);
if (!arrayType)
if (ArraySliceType const* sliceType = dynamic_cast<ArraySliceType const*>(&baseType))
arrayType = &sliceType->arrayType();
Expand Down
2 changes: 1 addition & 1 deletion libyul/backends/evm/StackLayoutGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void StackLayoutGenerator::processEntryPoint(CFG::BasicBlock const& _entry, CFG:
// entry layout of the backwards jump target as the initial exit layout of the backwards-jumping block.
while (!toVisit.empty())
{
CFG::BasicBlock const *block = *toVisit.begin();
CFG::BasicBlock const* block = *toVisit.begin();
toVisit.pop_front();

if (visited.count(block))
Expand Down
37 changes: 25 additions & 12 deletions scripts/check_style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ set -eu

ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)"

if [ "$(uname)" == "Darwin" ]; then
if ! command -v ggrep &> /dev/null
then
brew install grep # install GNU grep on macOS
fi
grepCommand="ggrep"
else
grepCommand="grep"
fi
Comment on lines +7 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A style check script should absolutely not modify your system by installing new software. If it requires something and it's not available, it just fail.

We actually added a portable grep helper recently, so please source common.sh and use it:

solidity/scripts/common.sh

Lines 317 to 326 in fbbac9c

function gnu_grep
{
if [[ "$OSTYPE" == "darwin"* ]]; then
command_available ggrep --version
ggrep "$@"
else
command_available grep --version
grep "$@"
fi
}


EXCLUDE_FILES=(
# The line below is left unquoted to allow the shell globbing path expansion
test/cmdlineTests/*/{err,output}
Expand Down Expand Up @@ -57,7 +67,7 @@ REPO_ROOT="$(dirname "$0")"/..
cd "$REPO_ROOT" || exit 1

WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" |
grep -v "test/libsolidity/ASTJSON\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true
${grepCommand} -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true
)

if [[ "$WHITESPACE" != "" ]]
Expand All @@ -70,27 +80,30 @@ fi

function preparedGrep
{
git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}"
git grep -nIE "$1" -- '*.h' '*.cpp' | ${grepCommand} -v "${EXCLUDE_FILES_JOINED}"
return $?
}

FORMATERROR=$(
(
preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters
preparedGrep "#include \"" | ${grepCommand} -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters
preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch"
preparedGrep "\<for\>\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop
preparedGrep "\<if\>\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if"
preparedGrep "\<for\>[[:space:]]*\([^=]*\>[[:space:]]:[[:space:]].*\)" # no space before range based for-loop
preparedGrep "\<if\>[[:space:]]*\(.*\)[[:space:]]*\{[[:space:]]*$" # "{\n" on same line as "if"
preparedGrep "namespace .*\{"
preparedGrep "[,\(<]\s*const " # const on left side of type
preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line)
preparedGrep "[,\(<][[:space:]]*const " # const on left side of type
preparedGrep "^[[:space:]]*(static)?[[:space:]]*const " # const on left side of type (beginning of line)
preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs
preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return)
preparedGrep "[a-zA-Z0-9_][[:space:]]*[&][a-zA-Z_]" | ${grepCommand} -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return)
# right-aligned reference pointer star (needs to exclude return and comments)
preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*"
preparedGrep "[a-zA-Z0-9_][[:space:]]*[*][a-zA-Z_]" | ${grepCommand} -E -v -e "return [*]" -e ":[[:space:]]*[*]" -e ".*//.*"
# unqualified move()/forward() checks, i.e. make sure that std::move() and std::forward() are used instead of move() and forward()
preparedGrep "move\(.+\)" | grep -v "std::move" | grep -E "[^a-z]move"
preparedGrep "forward\(.+\)" | grep -v "std::forward" | grep -E "[^a-z]forward"
) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" || true
preparedGrep "move\(.+\)" | ${grepCommand} -v "std::move" | ${grepCommand} -E "[^a-z]move"
preparedGrep "forward\(.+\)" | ${grepCommand} -v "std::forward" | ${grepCommand} -E "[^a-z]forward"
# make sure `using namespace std` is not used in INCLUDE_DIRECTORIES
# shellcheck disable=SC2068,SC2068
${grepCommand} -nIE -d skip "using namespace std;" ${NAMESPACE_STD_FREE_FILES[@]}
) | ${grepCommand} -E -v -e "^[a-zA-Z\./]*:[0-9]*:[[:space:]]*/(/|\*)" -e "^test/" || true
)

# Special error handling for `using namespace std;` exclusion, since said statement can be present in the test directory
Expand Down