-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix ShellCheck errors + Add support for generic shell script #14
Conversation
Hello @k-lar. Thanks a lot for the PR – lots of great stuff in there. I'm not sure what I think about supporting
That being said I'm not entirely opposed to this either. A good argument in favor is that it is quite unlikely that a present I would love to hear what you think about the above and thanks again for the PR :) |
Thanks @paldepind for taking a look! I do agree that it's trivial to add the build commands to a Makefile, but I did this from the perspective of allowing people to minimize the use of external tools and to enable a "shell-centric" approach that at least I enjoy.
I love the idea of this project and I might contribute more! I can definitely make a manpage for it in a couple of days and I can probably conjure up some other stuff that might be useful. |
try_build_script() { | ||
if [ "$ACTION" = build ]; then | ||
if [ -f build.sh ]; then | ||
execute "sh -c build.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be ./build.sh
? That could work better if the script is a Bash script and the user is running the Bash shell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didn't know that, sure I'll change it to ./build.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general sh script.sh
will execute sh
and have it run script.sh
. When doing ./script.sh
the shebang in the top of the script determines what program the script is run through. This makes a difference if the shebang does not specify sh
. For instance if the shebang is #!/bin/bash
, then the script should be run with bash. In theory the script could also be written in Python or JavaScript or something else (though it wouldn't make sense with the .sh
extension).
What I wrote before was slightly inaccurate, the users shell doesn't matter. Running a Bash specific script with ./script.sh
works no matter what the users shell is.
else | ||
echo "Did not find build.sh script" | ||
exit | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this else
branch could be removed. It will echo and exit every time projectdo gets to to try_build_script
and we will never get to the generic nothing_found
function.
Thanks for the reply. I think those are good points. I definitely see the argument that it's nice to support a way of building that is completely dependency-free which the tool based ones obviously can't be. The documentation currently suggests doing a dry-run if running projectdo in a new project where one is not exactly sure what it will do. Given that, I think it's fine to just run the
I'm happy to hear that you like the idea 😄. A manpage would be a really great addition! |
projectdo
Outdated
fi | ||
if [ $DRY_RUN = false ]; then | ||
if [ $QUIET = false ]; then | ||
eval "$1" $TOOL_ARGS | ||
eval "$1" "$TOOL_ARGS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will pass all the arguments along to the tool as one single argument with spaces. We want to actually pass the arguments along to the tool as multiple arguments.
I think we need to preserve the TOOL_ARGS=$@
below. I found this SO answer which seems imply that $@
. We need to keep the echo line or find something equivalent. Shellcheck complains about the eval
but maybe that is a false positive or maybe there is a better way of achieving what the original eval
line does in a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I reverted it back to the previous state but we should probably look into that a bit more because judging from the information here, the behavior of string=$@
is dependent on the shell and using $*
would eliminate that uncertainty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good idea. I think I'll see if I can add a test that ensures that the arguments are passed correctly, and then from there we can refactor while ensuring that the behavior is preserved :)
I think it would also be helpful to integrate ShellCheck into the testing somehow, either that or to integrate it into CI for it to catch errors and if there is something that we want to ignore, we would have to explicitly disable warnings for that specific code. |
Thanks a lot for the PR! |
Sometimes I have projects that don't require tooling systems to be present in the repository but I do need a build step, that's where a
build.sh
comes in. I've seen this in other people's projects too so this would be a nice feature to merge.I also took care of some low hanging fruit by fixing errors thrown by ShellCheck, thereby achieving POSIX compliance.
Makefile was also expanded to include
install
anduninstall
targets to make it easier to do those things.All tests pass and I also added one for
build.sh
.I can also add support for
.bat
and.ps1
scripts.There could also be a
tests.sh
or something like that that could be supported to have a generic way to build/run/test smaller projects.