Skip to content

Commit 2277b75

Browse files
authored
Upgrade Bazel version to 1.2.1 + use bin/setup(s) (#31)
* instead of .travis/install-bazel.sh use bin/setup-linux * checkin ~/.bazelversion file used by bazelisk on OS-X * split up Darwin and Linux installers, but reuse what's common * updated .travis.yml
1 parent 16a6457 commit 2277b75

File tree

10 files changed

+167
-42
lines changed

10 files changed

+167
-42
lines changed

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.2.1

.envrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# vi: ft=sh
2+
3+
PATH_add bin
4+
5+
source bin/deps
6+

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ addons:
2626
- g++
2727

2828
before_install:
29-
- .travis/install-bazel.sh 1.1.0
29+
- bin/setup-linux 1.2.1
3030
- bazel $BAZEL_OPTS version
3131
- bazel $BAZEL_OPTS info
3232
- bazel $BAZEL_OPTS fetch --curses=no -- "//ruby/..."

.travis/install-bazel.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

WORKSPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
1010

1111
bazel_skylib_workspace()
1212

13+
load("@bazel_skylib//lib:versions.bzl", "versions")
14+
15+
versions.check("1.2.1")
16+
1317
local_repository(
1418
name = "bazelruby_ruby_rules_ruby_tests_testdata_another_workspace",
1519
path = "ruby/tests/testdata/another_workspace",
@@ -47,7 +51,7 @@ go_rules_dependencies()
4751

4852
go_register_toolchains(go_version = "1.12.9")
4953

50-
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
54+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
5155

5256
gazelle_dependencies()
5357

bin/deps

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# vim: ft=shell
1+
#!/usr/bin/env bash
2+
# vim: ft=sh
23

34
export BashMatic="${HOME}/.bashmatic"
45

@@ -8,4 +9,3 @@ export BashMatic="${HOME}/.bashmatic"
89
}
910

1011
source "${BashMatic}/init.sh"
11-

bin/pre-commit

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
#!/usr/bin/env bash
2+
#
3+
# Main dependency shell script that installs BashMatic Library in ~/.bashmatic folder.
24

35
export COLUMNS=90
46

5-
[[ -x bin/deps ]] && source bin/deps
6-
[[ -x bin/setup ]] && source bin/setup
7+
export BashMatic="${HOME}/.bashmatic"
78

8-
[[ -z ${BashMatic} ]] && {
9+
[[ -x ./bin/deps ]] && {
10+
# shellcheck disable=SC1091
11+
source bin/deps
12+
}
13+
14+
[[ -x ./bin/setup ]] && {
15+
# shellcheck disable=SC1091
16+
source bin/setup gem::dependencies
17+
}
18+
19+
[[ -z "${BashMatic}" ]] && {
920
echo "Failed to initialize BASH library."
1021
exit 1
1122
}
1223

1324
set +e
1425

1526
info "Running Rubocop, please wait..."
16-
rubocop -F -D
27+
rubocop -F -D
1728
code=$?
1829

1930
if [[ ${code} -ne 0 ]]; then
2031
run::set-next show-output-on
2132
run "rubocop -a -D -P"
22-
33+
2334
run::set-next abort-on-error
2435
run "rubocop -D -P"
2536
fi
26-
37+
2738
success "RuboCop ran successfully."

bin/setup

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,44 @@
77
exit 1
88
}
99

10-
# abort on error
11-
run::set-all abort-on-error
10+
function setup::gem::dependencies() {
11+
# abort on error
12+
run::set-all abort-on-error
1213

13-
lib::gem::cache-refresh
14-
lib::gem::install rubocop
15-
lib::gem::install relaxed-rubocop
14+
lib::gem::cache-refresh
15+
lib::gem::install rubocop
16+
lib::gem::install relaxed-rubocop
17+
}
18+
19+
function setup::git::commit-hook() {
20+
[[ -L .git/hooks/pre-commit ]] || run "ln -nfs bin/pre-commit .git/hooks/pre-commit"
21+
}
22+
23+
function setup::detect-bazel-version() {
24+
local version
25+
version="$(grep versions.check WORKSPACE | awk 'BEGIN{FS="\""}{print $2}')"
26+
[[ -z "${version}" && -f .bazelversion ]] && version="$(cat .bazelversion | tr -d '\n')"
27+
printf "%s" "${version}"
28+
}
29+
30+
#—————————————————————————————— main ———————————————————————————————————————————
31+
32+
function setup::main() {
33+
setup::gem::dependencies
34+
[[ -z ${CI} ]] && setup::git::commit-hook
35+
36+
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
37+
local script
38+
39+
script="./bin/setup-${os}"
40+
41+
if [[ -x ${script} ]]; then
42+
"${script}" "$(setup::detect-bazel-version)"
43+
else
44+
echo "Operating system $(uname -s) is not currently supported." >&2
45+
return 1
46+
fi
47+
}
48+
49+
setup::main "$@"
1650

17-
[[ -L .git/hooks/pre-commit ]] || run "ln -nfs bin/pre-commit .git/hooks/pre-commit"

bin/setup-darwin

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
[[ -x bin/deps ]] && source bin/deps
4+
[[ -z "${BashMatic}" ]] && {
5+
echo "Failed to initialize BASH library."
6+
exit 1
7+
}
8+
9+
#—————————————————————————————— OS-X SPECIFIC INSTALLERS —————————————————————————
10+
11+
function setup::brew-validate() {
12+
# Homebrew is required to install Bazel
13+
if ! brew help >/dev/null; then
14+
echo "brew is not installed, please install from https://brew.sh"
15+
fi
16+
}
17+
18+
function setup::brew-install-jdk() {
19+
# The JDK homebrew cask is a required to install the java dependencies for Bazel
20+
if ! brew cask list | grep -q openjdk; then
21+
brew cask install homebrew/cask-versions/adoptopenjdk8
22+
fi
23+
}
24+
25+
function setup::brew-deps() {
26+
if ! brew list | grep -q xz; then
27+
brew install xz
28+
fi
29+
}
30+
31+
function setup::osx-deps() {
32+
# xcode command line tools are required, specifically gcc
33+
# if xcode already exists, this command will error, otherwise prompt the user
34+
if [[ -n $(xcode-select --install 2>&1 | grep 'already installed') ]]; then
35+
echo "xcode-select tools are already installed."
36+
fi
37+
}
38+
39+
function setup::bazelisk-install() {
40+
brew install bazelbuild/tap/bazelisk
41+
}
42+
43+
function setup::darwin() {
44+
setup::brew-validate
45+
setup::brew-install-jdk
46+
setup::brew-deps
47+
setup::osx-deps
48+
setup::bazelisk-install
49+
}
50+
51+
setup::darwin "$@"

bin/setup-linux

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
[[ -x bin/deps ]] && source bin/deps
4+
5+
[[ -z "${BashMatic}" ]] && {
6+
echo "Failed to initialize BASH library."
7+
exit 1
8+
}
9+
10+
function setup::linux() {
11+
local version
12+
version="${1}"
13+
14+
[[ -z "${version}" && -f .bazelversion ]] && version=$(cat .bazelversion | tr -d '\n')
15+
16+
if [[ -z "${version}" ]]; then
17+
echo "Usage: setup-linux BAZEL-VERSION" >&2
18+
exit 1
19+
else
20+
hl::subtle "Installing Bazel version ${version}"
21+
fi
22+
23+
local installer=bazel-${version}-installer-linux-x86_64.sh
24+
local release_base_uri=https://github.com/bazelbuild/bazel/releases/download/${version}
25+
local require_install=true
26+
if test -x ${HOME}/local/${installer}; then
27+
cd ${HOME}/local
28+
if curl ${release_base_uri}/${installer}.sha256 | sha256sum -c; then
29+
require_install=false
30+
fi
31+
fi
32+
33+
if ${require_install}; then
34+
run "rm -rf ${HOME}/local"
35+
run "mkdir ${HOME}/local"
36+
run "cd ${HOME}/local"
37+
run "wget ${release_base_uri}/${installer}"
38+
run "chmod +x ${installer}"
39+
40+
run::set-next show-output-on
41+
run "./${installer} --prefix=${HOME}/local --base=${HOME}/.bazel"
42+
fi
43+
}
44+
45+
setup::linux "$@"

0 commit comments

Comments
 (0)