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

Fixes for shellcheck warnings, part 1 #10586

Merged
merged 16 commits into from
Mar 5, 2021
Merged

Fixes for shellcheck warnings, part 1 #10586

merged 16 commits into from
Mar 5, 2021

Conversation

cameel
Copy link
Member

@cameel cameel commented Dec 12, 2020

Depends on #10877. It's on develop now.

This PR fixes most of shellcheck warnings in our scripts. Those are only the ones that were not actual errors (those are covered by #10584, #10583) or just missing quotes (#10585, #10877).

These are not all fixes, just the ones that I could easily put in an independent branch. I have a few more but they depend on all the other branches so I'd like to get these here merged first. When we're done with them I'll submit the rest and another PR that removes all the scripts (now warning-free) from shellcheck ignore list. EDIT: I decided to just put it on top of the other PRs and just get them all through review one by one. So this will remain a draft until all the PRs below are merged. EDIT: Ready for review.

@cameel cameel self-assigned this Dec 12, 2020
@cameel cameel force-pushed the shellcheck-fixes-part1 branch from de00b7e to 2d99157 Compare December 12, 2020 07:08
@cameel cameel changed the base branch from develop to fix-doc-pragma-checks December 12, 2020 07:10
@cameel cameel force-pushed the shellcheck-fixes-part1 branch from 2d99157 to d54e4f0 Compare December 12, 2020 07:15
Comment on lines +47 to -55
RUN_STEPS=$(seq 2 "$STEPS" | circleci tests split | xargs)
fi
else
RUN_STEPS=$(seq "$STEPS")
RUN_STEPS=$(seq "$STEPS" | xargs)
fi

# turn newlines into spaces
RUN_STEPS=$(echo $RUN_STEPS)

Copy link
Member Author

Choose a reason for hiding this comment

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

So we ended up with #9421 (comment) anyway...

@cameel cameel marked this pull request as draft December 12, 2020 07:17
Base automatically changed from fix-doc-pragma-checks to develop December 14, 2020 10:30
@leonardoalt
Copy link
Member

@cameel why is it a draft?

preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | egrep -v -e "return [*]" -e "^* [*]" -e "^*//.*"
) | egrep -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/"
preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*"
) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/"
Copy link
Member

Choose a reason for hiding this comment

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

Does this work on MacOS as well? I think we had some problems in the past because of grep -E, but might be imagining that

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't checked that yet. This is the reason why this and #10585 are still drafts - I need to test this stuff a bit more because we have very little coverage for shell scripts but I want to finish the bytecode compare PRs first.

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be fine on macOS. -E is one of the options that work the same way between Linux and macOS. AFAIK -P (--perl-regexp) that we're using in get_version.sh is the problematic one.


mkdir -p build
cd build || exit
Copy link
Member

Choose a reason for hiding this comment

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

Why were these removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I added set -eu at the top of the script so it will fail automatically if cd fails.

@cameel
Copy link
Member Author

cameel commented Jan 19, 2021

@cameel why is it a draft?

Basically, I'm not yet 100% confident that this does not break anything and I want to test it manually a bit more but I'm stuck in the bytecode compare PRs at the moment and I want to finish them first.

@axic
Copy link
Member

axic commented Jan 19, 2021

I think you could definitely merge without hesitation the /usr/bin/env and set -e changes separately.

echo "Obtained:"
echo "$(cat ./obtained.json)"
cat ./obtained.json
Copy link
Member

Choose a reason for hiding this comment

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

Also this is pretty clearly not breaking anything?

scripts/check_style.sh Outdated Show resolved Hide resolved
@cameel
Copy link
Member Author

cameel commented Jan 21, 2021

@axic Yeah, that sounds like a good idea. I'm going to split this PR into smaller ones and get it merged in smaller pieces to make it more manageable. The changes you mentioned will go in first.

@cameel cameel force-pushed the shellcheck-fixes-part1 branch from d54e4f0 to 5cda31d Compare February 2, 2021 13:41
@cameel cameel changed the base branch from develop to fix-quoting-and-whitespace-in-shell-scripts February 2, 2021 13:43
@cameel cameel force-pushed the shellcheck-fixes-part1 branch 3 times, most recently from c61aefa to d075ffd Compare February 2, 2021 14:10
@cameel cameel changed the base branch from fix-quoting-and-whitespace-in-shell-scripts to bash-arrays-for-arg-variables February 2, 2021 14:14
@cameel cameel force-pushed the shellcheck-fixes-part1 branch from d075ffd to cde45fc Compare February 2, 2021 14:20
@cameel cameel force-pushed the bash-arrays-for-arg-variables branch from 37b0f80 to cba6e68 Compare February 2, 2021 14:47
@cameel cameel force-pushed the shellcheck-fixes-part1 branch 2 times, most recently from 1585d01 to 1e5f0e5 Compare February 2, 2021 14:56
Base automatically changed from bash-arrays-for-arg-variables to develop February 8, 2021 12:31
@@ -93,6 +93,6 @@ for (var optimize of [false, true])
}
EOF
chmod +x solc
./solc *.sol > /tmp/report.txt
./solc -- *.sol > /tmp/report.txt
Copy link
Member

Choose a reason for hiding this comment

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

Why --?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you have a file that's named like a command line option, * will match it. For example if there's a file called -rf and you do rm *, you're actually doing rm -rf * :) To avoid this the convention in many programs is that stuff after -- is never interpreted as an option. So rm -- * is safe even if you have a file called -rf.

Another way to avoid that is to use ./* instead of * because for most programs the difference between x.txt and ./x.txt does not matter. Unfortunately for solc it does (though it might change soon: #4702). I used ./* in most places that shellcheck pointed out becuase that's more universal but I could not do it here. Fortunately boost::program_options does support -- so that's the workaround I used.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok!

@cameel cameel force-pushed the shellcheck-fixes-part1 branch from 2806eb8 to 09c9591 Compare March 4, 2021 15:56
@cameel cameel force-pushed the shellcheck-fixes-part1 branch from 09c9591 to cf94c3f Compare March 4, 2021 15:58
@cameel cameel requested review from leonardoalt and axic March 4, 2021 15:58
@leonardoalt
Copy link
Member

Looks good, can you squash? I'll approve then

@cameel
Copy link
Member Author

cameel commented Mar 4, 2021

Why squash though? It's not a pile of random fixup commits :) Each commit deals with a different warning and the description says what is being fixed. It's just that there were quite a few different things to fix. It would be a jumbled mess if I squashed that so I'd rather not.

@leonardoalt
Copy link
Member

Hmmm ok, it's quite a lot of commits though. I'll approve it anyway, if anyone doesn't like it blame @cameel !

@cameel
Copy link
Member Author

cameel commented Mar 4, 2021

Yeah, I know. But do we have a rule against that? No one is being paid by the commit anyway :) I thought that it's more about whether it appropriate for the situation.

I do see that there's a tendency towards bigger commits in Solidity so I mostly try to do that too and only have a few per PR even though personally I prefer smaller ones. Especially in PRs like this one where the fix consists of many independent parts that are better off viewed separately, I think smaller ones make more sense. There are bigger and smaller changes here and I think that without separating them the smaller ones can easily get lost in the noise.

@leonardoalt
Copy link
Member

That's fine with me

@cameel cameel merged commit 093ea46 into develop Mar 5, 2021
@cameel cameel deleted the shellcheck-fixes-part1 branch March 5, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants