Skip to content

Conversation

@simonbyrne
Copy link
Member

@simonbyrne simonbyrne commented Jun 8, 2016

Some of the shell files were using bash features with /bin/sh, others could have safely used /bin/sh. Now all .sh files pass checkbashisms.

Partially addresses #16819.

@yuyichao
Copy link
Contributor

yuyichao commented Jun 8, 2016

lgtm

@simonbyrne
Copy link
Member Author

Here are the remaining warnings in the bash-using files:

├ checkbashisms -f filterArgs.sh 
possible bashism in filterArgs.sh line 7 (alternative test command ([[ foo ]] should be [ foo ])):
    if [[ $i == -L* ]]; then
possible bashism in filterArgs.sh line 7 (should be 'b = a'):
    if [[ $i == -L* ]]; then


├ checkbashisms -f install.sh
possible bashism in install.sh line 19 ($'...' should be "$(printf '...')"):
    DESTFILE=$(LC_ALL=C cp -va $SRC $DEST | sed -e $'s/ -> /\\\n/g' | tail -n 1)


├ checkbashisms -f relative_path.sh
possible bashism in relative_path.sh line 12 (alternative test command ([[ foo ]] should be [ foo ])):
if [[ ! "$source" == /* ]] || [[ ! "$target" == /* ]]; then
possible bashism in relative_path.sh line 12 (should be 'b = a'):
if [[ ! "$source" == /* ]] || [[ ! "$target" == /* ]]; then
possible bashism in relative_path.sh line 20 (alternative test command ([[ foo ]] should be [ foo ])):
while [[ "${target#$common_part/}" == "${target}" ]] && [[ "$common_part" != "/" ]]; do
possible bashism in relative_path.sh line 20 (should be 'b = a'):
while [[ "${target#$common_part/}" == "${target}" ]] && [[ "$common_part" != "/" ]]; do
possible bashism in relative_path.sh line 25 (alternative test command ([[ foo ]] should be [ foo ])):
    if [[ -z $result ]]; then
possible bashism in relative_path.sh line 32 (alternative test command ([[ foo ]] should be [ foo ])):
if [[ "$common_part" == "/" ]]; then
possible bashism in relative_path.sh line 32 (should be 'b = a'):
if [[ "$common_part" == "/" ]]; then
possible bashism in relative_path.sh line 42 (alternative test command ([[ foo ]] should be [ foo ])):
if [[ -n $result ]] && [[ -n $forward_part ]]; then
possible bashism in relative_path.sh line 44 (alternative test command ([[ foo ]] should be [ foo ])):
elif [[ -n $forward_part ]]; then
possible bashism in relative_path.sh line 46 (${foo:3[:1]}):
    result="${forward_part:1}"

#!/bin/sh
# This file is a part of Julia. License is MIT: http://julialang.org/license

last_tag=$(git describe --tags --abbrev=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

not part of this issue/pr, but the next line really shouldn't say 0.4.0-dev any more. @yuyichao did you not port the improved Compat.jl version back to contrib?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't even aware of this script .....

Copy link

Choose a reason for hiding this comment

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

You can use find to see all scripts.
$ cd julia
$ find . -name "*.sh"

./contrib/prepare_release.sh
./contrib/fixup-libstdc++.sh
./contrib/commit-name.sh
./contrib/fixup-libgfortran.sh
./contrib/filterArgs.sh
./contrib/travis_fastfail.sh
./contrib/install.sh
./contrib/mac/app/run-install-name-tool-change.sh
./contrib/mac/mac-gtk.sh
./contrib/windows/get_toolchain.sh
./contrib/windows/msys_build.sh
./contrib/windows/winrpm.sh
./contrib/relative_path.sh
./contrib/check-whitespace.sh
./src/flisp/bootstrap.sh
./test/perf/micro/java/setup.sh
./base/version_git.sh

Copy link
Member Author

Choose a reason for hiding this comment

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

git ls-files '*.sh' is a better bet, as otherwise you'll pick up scripts from dependencies

@ghost
Copy link

ghost commented Jun 8, 2016

base/version_git.sh is missing a #!/bin/sh on the first line.

@yuyichao
Copy link
Contributor

yuyichao commented Jun 8, 2016

base/version_git.sh is invoked with sh base/version_git.sh directly but adding a shebang won't hurt either.

@simonbyrne
Copy link
Member Author

Done. I've also imported the changes to commit-name.sh from Compat.jl

@ghost
Copy link

ghost commented Jun 8, 2016

Scripts that still don't comply to standards and use bashisms:

  • contrib/filterArgs.sh
  • contrib/install.sh
  • contrib/relative_path.sh

Scripts that are portable:

  • contrib/prepare_release.sh
  • contrib/fixup-libstdc++.sh
  • contrib/commit-name.sh
  • contrib/fixup-libgfortran.sh
  • contrib/travis_fastfail.sh
  • contrib/mac/app/run-install-name-tool-change.sh
  • contrib/mac/mac-gtk.sh
  • contrib/windows/get_toolchain.sh
  • contrib/windows/msys_build.sh
  • contrib/windows/winrpm.sh
  • contrib/check-whitespace.sh
  • src/flisp/bootstrap.sh
  • test/perf/micro/java/setup.sh
  • base/version_git.sh

@ghost
Copy link

ghost commented Jun 8, 2016

Found a caveat on Mac specific code. https://github.com/JuliaLang/julia/blob/master/contrib/mac/app/Makefile#L43

It's not very important, but also won't harm, to use /bin/sh here too. Just so the source is clean from "bash" and people don't get encouraged to use it.

For keeping scripts portable, I propose Travis automatically fails if a pull request has the word "bash" on it ;-)

@tkelman
Copy link
Contributor

tkelman commented Jun 8, 2016

Or more realistically, set up CI for a system that doesn't have bash installed. We nominally support freebsd but I don't know who (if anyone) is regularly testing it lately, and I think because of these scripts you might need bash installed to build on freebsd anyway.

oh, and a useful github trick - when linking to specific lines of code, hit y and github will refresh the page but at a specific sha, that way the link will always point to what you meant even if code moves around

@simonbyrne
Copy link
Member Author

I wouldn't worry about the mac code: bash is already installed on OS X.

I think it's more important to have working scripts (with correct shebangs) than worry too much about working bash-free: e.g. I have no idea how one would write filterArgs.sh in pure sh.

@ghost
Copy link

ghost commented Jun 8, 2016

Or more realistically, set up CI for a system that doesn't have bash installed

I think a CI for Alpine Linux would be perfect for this, since it has neither glibc or bash installed by default (it uses musl libc and busybox ash). This would solve 2 problems (finding glibc-specific unportable code and bashisms). Alpine is also one damn small distribution.

@yuyichao
Copy link
Contributor

yuyichao commented Jun 8, 2016

I have no idea how one would write filterArgs.sh in pure sh.

It's possible https://wiki.ubuntu.com/DashAsBinSh but not without much longer code, additional dependencies on addition (yet "standard") tools and code that is much harder to understand.

@simonbyrne
Copy link
Member Author

I guess we could call perl, since that is an official requirement, but that seems absurd.

@ghost
Copy link

ghost commented Jun 8, 2016

Problem solved.
#16827

@ghost
Copy link

ghost commented Jun 8, 2016

With #16829 I think contrib/install.sh becomes posix-compliant.

Last script that doesn't comply to standards and use bashism is contrib/relative_path.sh

@ghost
Copy link

ghost commented Jun 8, 2016

Looks like this can be merged, all checks passed.

@tkelman
Copy link
Contributor

tkelman commented Jun 8, 2016

#16827 means filterArgs.sh won't need to change

@ghost
Copy link

ghost commented Jun 8, 2016

True, good catch.
install.sh too, I think. #16829

@ghost
Copy link

ghost commented Jun 8, 2016

So the last remaining bashism is contrib/relative_path.sh.
That shell script comes from a stackoverflow answer.
But there are other answer that may be better suited.

One of @simonair solutions is a POSIX shell function. It works with a variety of paths, but does not clean multiple slashes or resolve symlinks. Would that be a problem for Julia's case? If so, we could work from simonair's shell script and try to add that feature.
http://stackoverflow.com/a/14914070

There's also Jens solution, which is pretty cool. But I haven't tested it.
http://stackoverflow.com/a/7023490

Do you think we could use either one of these solutions?

@tkelman
Copy link
Contributor

tkelman commented Jun 8, 2016

(moved to the right pr)
Looks like contrib/relative_path.sh actually should not have been given the Julia license header since most of it was copied from stack overflow, and prior to this March stack overflow code is CC-BY-SA.

@ghost
Copy link

ghost commented Jun 8, 2016

@simonbyrne can you please revert changes to filterArgs.sh and install.sh? We already got them covered, #16827 and #16829

And with this PR (after reverting those 2 changes) we get everything else covered, except for contrib/relative_path.sh

@ghost
Copy link

ghost commented Jun 9, 2016

#16827 and #16829 got merged and contrib/relative_path.sh discussion is taking place at #16838

Now when this PR is merged (after changes to filterArgs.sh and install.sh are reverted by @simonbyrne since those files were already fixed) we will basically bashism-free!

Nice.

@simonbyrne simonbyrne force-pushed the sb/bashisms branch 2 times, most recently from e8d9804 to f4abb17 Compare June 9, 2016 13:43
@simonbyrne
Copy link
Member Author

Updated.

Switches shebangs that can safely use /bin/sh. Partially addresses #16819.

Also updates commit-name.sh from Compat.jl
@ghost
Copy link

ghost commented Jun 9, 2016

Great! I don't think we need to wait for Travis CI again, since this is the same patch minus changes to 2 files. Good to be merged.

@tkelman tkelman merged commit 8479012 into master Jun 9, 2016
@tkelman tkelman deleted the sb/bashisms branch June 9, 2016 13:53
@tkelman
Copy link
Contributor

tkelman commented Jun 9, 2016

Are the shell scripts in contrib/mac even being used any more since 47dc275, or should we delete them? Gtk.jl is handled pretty well by Homebrew I'd say.

@ghost ghost mentioned this pull request Jun 9, 2016
9 tasks
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.

4 participants