Skip to content

Commit dc837ff

Browse files
authored
Sight facelift to shell files: (#35)
* Sight facelift to shell files: This is mostly a collection of various stashes combined together. * making setup-linux a bit less unsafe * adding a diagram * printing all sorts of veresions in the bin/setup * making **gemfile** mandatory for `bundle_install`. * Minor fixes to setup-linux to make CI work
1 parent 3a554f4 commit dc837ff

File tree

12 files changed

+144
-32
lines changed

12 files changed

+144
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
**/bazel-*
22
**/.idea
3+
**/.vscode

.rules_version

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

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020

2121
Ruby rules for [Bazel](https://bazel.build).
2222

23-
## Status
23+
## Status:
2424

25-
Work in progress.
25+
**Work in progress.**
2626

27-
## How to use
27+
28+
## USAGE
2829

2930
Add `ruby_rules_dependencies` and `ruby_register_toolchains` into your `WORKSPACE` file.
3031

@@ -79,6 +80,11 @@ ruby_test(
7980

8081
## Rules
8182

83+
The following diagram attempts to capture the implementation behind `ruby_library` that depends on the result of `bundle install`, and a `ruby_binary` that depends on both:
84+
85+
![Ruby Rules](docs/img/ruby_rules.png)
86+
87+
8288
### `ruby_library`
8389

8490
<pre>

bin/deps

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33

44
export BashMatic="${HOME}/.bashmatic"
55

6-
[[ -s ${BashMatic}/init.sh ]] || {
6+
if [[ ! -f "${BashMatic}/init.sh" ]]; then
7+
printf "Please wait a minute while we install required dependencies...\n"
78
rm -rf "${BashMatic}" 2>/dev/null
8-
git clone https://github.com/kigster/bashmatic "${BashMatic}" 2>&1 1>/dev/null
9-
}
9+
git clone https://github.com/kigster/bashmatic "${BashMatic}" 1>/dev/null 2>&1
10+
fi
1011

12+
# shellcheck disable=SC1090
1113
source "${BashMatic}/init.sh"
14+
15+
# Application Constants
16+
export RulesRuby__Version=$(cat .rules_version)
17+
export RulesRuby__BazelVersion=$(cat .bazelversion)

bin/setup

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env bash
22

3-
[[ -x bin/deps ]] && source bin/deps
3+
[[ -n "${DEBUG}" ]] && set -x
44

5-
[[ -z ${BashMatic} ]] && {
5+
[[ -x bin/deps ]] && source "bin/deps"
6+
7+
[[ -z "${BashMatic}" ]] && {
68
echo "Failed to initialize BASH library."
79
exit 1
810
}
@@ -27,9 +29,39 @@ function setup::detect-bazel-version() {
2729
printf "%s" "${version}"
2830
}
2931

30-
#—————————————————————————————— main ———————————————————————————————————————————
32+
function setup::header() {
33+
h2 "Installing required development dependencies for working with rules_ruby and Bazel." \
34+
"Please wait...."
35+
}
36+
37+
# prints first argument as the key, right arligned, the second left aligned.
38+
function setup::table-rows() {
39+
local value="$2"
40+
value="$(printf "%s" "${value}" | head -1 | tr -C -d '[:digit:][:punct:]' | sed 's/([0-9]+.[0-9]+.[0+9]+)//g;s/[()]/-/g')"
41+
printf "${bldylw}%12.12s : ${bldblu}%20.20s ${txtpur}%s\n${clr}" "$1" "${value}" "$3"
42+
43+
}
44+
45+
function setup::print-versions() {
46+
local bazelisk_version="$(ls -ls "$(command -v bazel)" | grep bazelisk | awk 'BEGIN{FS="/"}{print $8}')"
47+
48+
set +e
49+
hl::subtle "Your Current Runtime Environment:"
50+
setup::table-rows 'Bazel' "$(bazel --version)" "$(command -v bazel)"
51+
setup::table-rows 'Bazelisk' "${bazelisk_version}"
52+
setup::table-rows 'Python ' "$(python --version 2>&1)" "$(command -v python) -> $(readlink "$(command -v python)")"
53+
setup::table-rows 'Python2' "$(python2 --version 2>&1)" "$(command -v python2)"
54+
setup::table-rows 'Python3' "$(python3 --version 2>&1)" "$(command -v python3)"
55+
setup::table-rows 'Ruby' "$(ruby --version | sed -E 's/p[0-9]+.*$//g' 2>&1)" "$(command -v ruby)"
56+
setup::table-rows 'BASH' "$(bash --version 2>/dev/null | tr -d ',')" "$(command -v bash)"
57+
setup::table-rows 'CC' "$(cc --version 2>/dev/null)" "$(cc --version | grep clang)"
58+
setup::table-rows 'GO' "$(go version 2>/dev/null)" "$(command -v go)"
59+
set -e
60+
hr
61+
}
3162

3263
function setup::main() {
64+
setup::header
3365
setup::gem::dependencies
3466
[[ -z ${CI} ]] && setup::git::commit-hook
3567

@@ -38,13 +70,36 @@ function setup::main() {
3870

3971
script="./bin/setup-${os}"
4072

41-
if [[ -x ${script} ]]; then
42-
"${script}" "$(setup::detect-bazel-version)"
73+
if [[ -x "${script}" ]]; then
74+
run::set-all show-output-on abort-on-error
75+
run "${script} $(setup::detect-bazel-version)"
76+
success 'Setup Completed ✅ '
4377
else
44-
echo "Operating system $(uname -s) is not currently supported." >&2
45-
return 1
78+
error "Operating system $(uname -s) is not currently supported." >&2
4679
fi
80+
81+
hr
82+
83+
setup::print-versions
4784
}
4885

49-
setup::main "$@"
86+
if [[ "$1" =~ "-h" ]]; then
87+
printf "
88+
${bldblu}USAGE: ${clr}
89+
bin/setup
90+
91+
${bldblu}DESCRIPTION:${clr}
92+
Installs Bazel via bazelisk on Mac, and directly on Linux.
93+
94+
Both MacOSX and Linux are supported.
5095
96+
Additionally sets up the git commit hook to check styles.
97+
98+
${bldblu}DO I HAVE TO RUN IT?:${clr}
99+
100+
${bldred}RUNNING REQUIRED PRIOR TO USING THE REPO.${clr}
101+
102+
"
103+
exit 0
104+
fi
105+
setup::main "$@"

bin/setup-darwin

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@ function setup::brew-validate() {
1818
function setup::brew-install-jdk() {
1919
# The JDK homebrew cask is a required to install the java dependencies for Bazel
2020
if ! brew cask list | grep -q openjdk; then
21-
brew cask install homebrew/cask-versions/adoptopenjdk8
21+
run "brew cask install homebrew/cask-versions/adoptopenjdk8"
2222
fi
2323
}
2424

2525
function setup::brew-deps() {
2626
if ! brew list | grep -q xz; then
27-
brew install xz
27+
"brew install xz"
2828
fi
2929
}
3030

3131
function setup::osx-deps() {
3232
# xcode command line tools are required, specifically gcc
3333
# 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."
34+
if [[ -n $(xcode-select --install 2>&1) ]]; then
35+
hl::subtle "Good News! xcode-select tools are already installed."
3636
fi
3737
}
38+
function setup::is-bazelisk-installed() {
39+
ls -al "$(command -v bazel)" | grep -q bazelisk
40+
}
3841

3942
function setup::bazelisk-install() {
40-
brew install bazelbuild/tap/bazelisk
43+
setup::is-bazelisk-installed ||
44+
run "brew install bazelbuild/tap/bazelisk"
4145
}
4246

4347
function setup::darwin() {

bin/setup-linux

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22

33
[[ -x bin/deps ]] && source bin/deps
44

5+
[[ -n ${DISABLE_COLOR} ]] && lib::color::disable
6+
57
[[ -z "${BashMatic}" ]] && {
68
echo "Failed to initialize BASH library."
79
exit 1
810
}
911

12+
function setup::linux::deps() {
13+
[[ -n $(command -v curl) && -n $(command -v wget) ]] && return 0
14+
15+
if [[ -z $(command -v apt-get) ]]; then
16+
error "Unable to find the right packaging tool to install dependencies."
17+
exit 1
18+
fi
19+
20+
[[ -n $(command -v curl) && -n $(command -v wget) ]] || {
21+
error "curl and wget must be pre-installed."
22+
exit 2
23+
}
24+
}
25+
1026
function setup::linux() {
11-
local version
12-
version="${1}"
27+
local version="${1}"
1328

1429
[[ -z "${version}" && -f .bazelversion ]] && version=$(cat .bazelversion | tr -d '\n')
1530

@@ -20,25 +35,34 @@ function setup::linux() {
2035
hl::subtle "Installing Bazel version ${version}"
2136
fi
2237

23-
local installer=bazel-${version}-installer-linux-x86_64.sh
24-
local release_base_uri=https://github.com/bazelbuild/bazel/releases/download/${version}
38+
# Ensure we have the tools like curl and wget installe d
39+
setup::linux::deps
40+
41+
local installer="bazel-${version}-installer-linux-x86_64.sh"
42+
local release_base_uri="https://github.com/bazelbuild/bazel/releases/download/${version}"
2543
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
44+
45+
local installer_path="${HOME}/.ruby_local"
46+
local installer_exe="${installer_path}/${installer}"
47+
48+
if [[ -x "${installer_exe}" ]]; then
49+
if curl -q "${release_base_uri}/${installer}.sha256" | sha256sum -c; then
2950
require_install=false
3051
fi
3152
fi
3253

3354
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}"
55+
run "rm -rf ${installer_path}"
56+
run "mkdir -p ${installer_path}"
57+
run "cd ${installer_path}"
58+
run "wget ${release_base_uri}/${installer} 2>&1"
3859
run "chmod +x ${installer}"
3960

40-
run::set-next show-output-on
41-
run "./${installer} --prefix=${HOME}/local --base=${HOME}/.bazel"
61+
hl::subtle 'Running Bazel Installer...'
62+
run::set-next show-output-on abort-on-error
63+
64+
run "${installer_exe} --prefix=${installer_path} --base=${HOME}/.bazel 2>&1"
65+
success 'Bazel installer completed successfully ✅ '
4266
fi
4367
}
4468

docs/faq.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# FAQ — Frequently Asked Questions
2+
3+
Coming soon.
4+
5+
Also see: [Troubleshooting](troubleshooting.md).

docs/img/ruby_rules.png

139 KB
Loading

docs/rules_ruby_architecture.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is the document that represents the current state of things in the `rules_ruby` repository, and will be updated as major changes happen.
2+
3+
Check back here often
4+
5+
# Ruby Rules Architecture & Design

0 commit comments

Comments
 (0)