google / shipshape

Program analysis platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

building shipshape without realpath fails "silently"

AlexTelon opened this issue · comments

When building shipshape from source after the guidelines with ubuntu 14.04 you get the error message:

ERROR: could not locate `go` binary on PATH

While the real error in my case was that realpath is not installed on the system (not default in 14.04 it seems). Any reason as to why readlink -e is not used instead? Readlink is used further down in the same file.

So my thinking is either to use readlink, or check if realpath is installed on the system.

This is the second time i stumble upon this and even though last time was only a week ago I forgot about this and was looking around how I had messed up my PATH this time until I took a look at configure and remembered. A fix would save some time and energy of potential new contributors.

Would do a pull request, but Im doing a thesis work at a company but we haven't had the time to look into corporate CLA's yet so I haven't dared to write code yet.

@zrlk @schroederc
This code comes from https://github.com/google/kythe/blame/master/setup_bazel.sh originally.

I notice that we always call realpath -s and we furnish the following workaround for MacOS:

realpath() {
    python -c 'import os, sys; print os.path.realpath(sys.argv[2])' $@
}

But realpath -s and os.path.realpath() don't do the same thing! E.g.,

$ realpath -s bazel-bin/../foo
/home/clconway/git/shipshape/foo
$ python -c 'import os, sys; print os.path.realpath(sys.argv[2])' -s bazel-bin/../foo
/home/clconway/.cache/bazel/_bazel_clconway/221df40891e1938542beb77d30927c8e/shipshape/bazel-out/local_linux-fastbuild/foo

I think we can easily add the workaround for non-Mac systems, but I wonder which behavior is correct?

BTW I agree that readlink is probably preferable to realpath, but readlink -e also doesn't match the behavior of realpath -s.

Indeed they are not interchangable with those flags.

Another simple way to improve the way it currently works without breaking anything is to check for realpath before first usage and give a better error message if it does not exist. Thought it might be better to only use readlink.

Something like this below, adapted from SO:

#!/bin/bash
command -v realpath >/dev/null 2>&1 || { echo >&2 "I require realpath but it's not installed.  Aborting."; exit 1; }

I tried it on my ubuntu and it worked like intended when removing and reinstalling realpath.