bazelisk icon indicating copy to clipboard operation
bazelisk copied to clipboard

Universal shell scripts to run baselisk

Open SKART1 opened this issue 5 years ago • 3 comments

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?

SKART1 avatar Aug 02 '19 17:08 SKART1

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.

philwo avatar Jan 26 '20 12:01 philwo

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

jeremyschlatter avatar May 20 '20 17:05 jeremyschlatter

+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.

strangemonad avatar Jul 20 '20 00:07 strangemonad