bazelbuild / bazelisk

A user-friendly launcher for Bazel.
Apache License 2.0
2k stars 305 forks source link

Universal shell scripts to run baselisk #84

Open SKART1 opened 5 years ago

SKART1 commented 5 years ago

What do you think about having files with native shell scripts like gradle wrapper have? Somthing like this:

#!/usr/bin/env sh

##############################################################################
##
##  Bazel start up script for UN*X (based on gradlew script from gradle wrapper project)
##
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`"/$link"
    fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="bazelisk"
APP_BASE_NAME=`basename "$0"`

warn () {
    echo "$*"
}

die () {
    echo
    echo "$*"
    echo
    exit 1
}

## Determine OS.
darwin=false
linux=false

case "`uname`" in
  Darwin* )
    darwin=true
    ;;
  Linux* )
    linux=true
    ;;
esac

BINARY_PATH=""
if $darwin; then
    BINARY_PATH=bazelisk-darwin-amd64
elif $linux; then
    BINARY_PATH=bazelisk-linux-amd64
else
   die "UNSUPPORTED OS! Command 'uname' says: `uname`. 'darwin' = $darwin and 'linux' = $linux"
fi

exec "$APP_HOME/bazelisk/$BINARY_PATH" "$@"

while having bazelisk binaries inside VCS repo?

philwo commented 4 years ago

I like the idea of having a wrapper for Bazelisk, now that it apparently is a popular thing to check-in Bazelisk as tools/bazel into a repository. We could call it Bazeliskisk 😄

I'll see what I can do about this.

jeremyschlatter commented 4 years ago

Another example of this pattern, in case it's helpful: someone made a shell script wrapper like this for hugo.

strangemonad commented 4 years ago

+1 to having a wrapper. I generally prefer how Bazel approaches things vs Gradle but the gradle wrapper option is so convenient. Other devs never have to think, just clone the repo and run the script.

One thing I'd like to suggest and bazelisk becomes robust. As an end user, I generally don't care about the inner workings of the launcher or if I'm launching through Bazelisk. I just want to run a bazel build. The details of building bazel from source or installing bazelisk via go get are really best left for the bazel developer's guide.