diff --git a/.bash_bazel b/.bash_bazel new file mode 100644 index 0000000..9277e80 --- /dev/null +++ b/.bash_bazel @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Install me in your ${HOME} folder, and add me to your ~/.bashrc: +# +# cp .bash_bazel ~/ && echo 'source ~/.bash_bazel' >> ~/.bashrc +# + +[[ -n $(command -V brew) ]] && { + completion="$(brew --prefix)/etc/bash_completion" + [[ -f "${completion}" ]] && { + source "${completion}" + } +} + +alias bb='bazel build' +alias bba='bazel build //...:all' +alias bbr='bazel run' +alias bbx='bazel clean --expunge' +alias bbq='bazel query' +alias bbt='bazel test' +alias bbqa='bazel query //...:all' + diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..18a2a1e --- /dev/null +++ b/.bazelrc @@ -0,0 +1,29 @@ +# Bazel RC file for Local +# +# Flare Folks: please feel free to update this as you see fit. I put +# initial values here that make the output pretty and github caching +# possible. I am not as certain about the JVM args. + +# Startup Options +startup --host_jvm_args=-Xmx500m + +# Build Options +build --verbose_failures +build --jobs 30 +build --progress_report_interval=2 +build --color yes +build --incompatible_strict_action_env +build --show_timestamps + +# These inherit from Build +test --verbose_failures +test --test_verbose_timeout_warnings +test --verbose_explanations + +# These also inherit from build +query --keep_going + +# Custom user overrides +# https://docs.bazel.build/versions/master/best-practices.html#bazelrc +try-import %workspace%/.bazelrc.user +try-import %workspace%/user.bazelrc diff --git a/.bazelversion b/.bazelversion index 3e3c2f1..47b322c 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -2.1.1 +3.4.1 diff --git a/.circleci/.bazelrc b/.circleci/.bazelrc deleted file mode 100644 index 3d8914d..0000000 --- a/.circleci/.bazelrc +++ /dev/null @@ -1,17 +0,0 @@ -# Common options -common --color=yes -common --show_progress -common --show_progress_rate_limit=0.5 - -# Build options -build --spawn_strategy=standalone -build --strategy=Genrule=standalone -build --show_timestamps -build --curses=no -build --jobs=10 - -# Test options -test --spawn_strategy=standalone -test --test_output=all -test --test_verbose_timeout_warnings -test --verbose_failures diff --git a/.circleci/Dockerfile b/.circleci/Dockerfile index 155b09c..aaaf8c3 100644 --- a/.circleci/Dockerfile +++ b/.circleci/Dockerfile @@ -1,7 +1,7 @@ # # rules_ruby circleci Docker file. # -FROM ruby:2.7.0 +FROM ruby:2.7.1 # make Apt non-interactive RUN echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90circleci \ diff --git a/.circleci/config.yml b/.circleci/config.yml index b9e9884..0e941be 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ jobs: working_directory: /home/circleci/repo resource_class: medium docker: - - image: bazelruby/ruby-2.7.0 + - image: bazelruby/ruby-2.7.1 environment: PATH: "/usr/local/bin:/usr/bin:/sbin:/opt/bin:/home/circleci/repo/bin:/bin:/sbin:/usr/sbin" BUNDLE_PATH: /home/circleci/.bundle_cache @@ -19,7 +19,6 @@ jobs: - run: name: "Install ~/.bazelrc and run setup" command: | - cp .circleci/.bazelrc ${HOME} /usr/bin/env bash bin/setup - run: @@ -40,7 +39,6 @@ jobs: - run: name: "Install ~/.bazelrc and run setup" command: | - cp .circleci/.bazelrc ${HOME} /usr/bin/env bash bin/setup - run: @@ -57,7 +55,6 @@ jobs: - run: name: "Install ~/.bazelrc and run setup" command: | - cp .circleci/.bazelrc ${HOME} /usr/bin/env bash bin/setup - run: @@ -74,7 +71,6 @@ jobs: - run: name: "Install ~/.bazelrc and run setup" command: | - cp .circleci/.bazelrc ${HOME} /usr/bin/env bash bin/setup - run: @@ -91,7 +87,6 @@ jobs: - run: name: "Install ~/.bazelrc and run setup" command: | - cp .circleci/.bazelrc ${HOME} /usr/bin/env bash bin/setup - run: diff --git a/.envrc b/.envrc index f8ae38d..861e443 100644 --- a/.envrc +++ b/.envrc @@ -2,3 +2,11 @@ PATH_add bin +[[ -n $(command -V brew) ]] && { + completion="$(brew --prefix)/etc/bash_completion" + [[ -f "${completion}" ]] && { + echo "Loading bash completion" + source "${completion}" + } +} + diff --git a/.gitignore b/.gitignore index 32327d7..3cecada 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ **/vendor/bundle/** **/.DS_Store **/.vscode + +.bazelrc.user +user.bazelrc diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..860487c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.1 diff --git a/.rules_version b/.rules_version index d917d3e..1d0ba9e 100644 --- a/.rules_version +++ b/.rules_version @@ -1 +1 @@ -0.1.2 +0.4.0 diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..7e8bf49 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +disable=SC1090,SC1091,SC2155,SC2154,SC2059,SC2046 diff --git a/.travis.yml b/.travis.yml index 3363cb2..8ba055b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ jdk: openjdk11 cache: directories: - ${HOME}/.rbenv + - ${HOME}/.bazel - ${HOME}/.bundle/gems addons: @@ -15,9 +16,30 @@ addons: - libstdc++6 - build-essential - g++ + - autoconf + - bison + - libssl-dev + - libyaml-dev + - libreadline6-dev + - zlib1g-dev + - libncurses5-dev + - libffi-dev + - libgdbm-dev -script: +before_script: + - rm -f /home/travis/.phpenv/bin/rbenv + - hash -r + - mkdir -p /home/travis/.cache/bazel-out + - mkdir -p /home/travis/.cache/bazel-cache + - rm -f .bazelrc.user + - echo 'build --disk_cache=/home/travis/.cache/bazel-cache' >> .bazelrc.user + - echo 'startup --output_base=/home/travis/.cache/bazel-out' >> .bazelrc.user + - cat .bazelrc + - cat .bazelrc.user - /usr/bin/env bash bin/setup + - /usr/bin/env bash bin/show-env + +script: - /usr/bin/env bash bin/test-suite after_script: @@ -26,6 +48,8 @@ after_script: env: global: - CI=true + - SCREEN_WIDTH=70 + - RBENV_ROOT="${HOME}/.rbenv" - BUNDLE_PATH="${HOME}/.bundle/gems" - PATH="${HOME}/.rbenv/bin:${HOME}/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/opt/local/bin:${PATH}" - BAZEL_OPTS="--host_jvm_args=-Xmx1200m --host_jvm_args=-Xms1200m" diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e627bc..bb7b668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.0 / 2020-07-29 + +[Total Changes since v0.3.0](https://github.com/bazelruby/rules_ruby/compare/v0.3.0...v0.4.0) + # 0.3.0 / 2020-03-02 [Total Changes since v0.2.0](https://github.com/bazelruby/rules_ruby/compare/v0.2.0...v0.3.0) @@ -13,10 +17,10 @@ ## Other Changes -* Introduced `ruby_gem` rule for packaging Ruby sources into a RubyGem-compatible zip file. Note, the resulting file has `.zip` extension. +* Introduced `ruby_gem` rule for packaging Ruby sources into a RubyGemInfo-compatible zip file. Note, the resulting file has `.zip` extension. * Introduced `ruby_rubocop` rule for running rubocop in analysis mode or auto-correcting mode. * Added an example gem workspace under `examples/example-gem` -* Default ruby used is now 2.7.0. We also now allow 2.7.0 to be built by Bazel. +* Default ruby used is now 2.7.1. We also now allow 2.7.1 to be built by Bazel. * Bazelisk has been updated to 1.3.0 * Updated Bazel version from 2.0.0 to 2.1.0 * Updated gem versions in the Gemfile @@ -29,4 +33,4 @@ # 0.1.0 / 2019-11-20 -* Initial migration from [Yugui](https://github.com/yugui) rules ruby. \ No newline at end of file +* Initial migration from [Yugui](https://github.com/yugui) rules ruby. diff --git a/Gemfile b/Gemfile index 8232bbe..aecd445 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,5 @@ source 'https://rubygems.org' -gem 'rubocop', '~> 0.78' +gem 'bundler' +gem 'rubocop', '~> 0.88' diff --git a/Gemfile.lock b/Gemfile.lock index f77a2ef..228e957 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GEM rubocop-ast (>= 0.1.0, < 1.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.1.0) + rubocop-ast (0.2.0) parser (>= 2.7.0.1) ruby-progressbar (1.10.1) unicode-display_width (1.7.0) @@ -26,7 +26,8 @@ PLATFORMS ruby DEPENDENCIES - rubocop (~> 0.78) + bundler + rubocop (~> 0.88) BUNDLED WITH - 2.1.2 + 2.1.4 diff --git a/README.md b/README.md index fffe5cb..6c5a28d 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ rules_ruby_dependencies() load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() -rules_ruby_select_sdk(version = "2.7.0") +rules_ruby_select_sdk(version = "2.7.1") #——————————————————————————————————————————————————————————————————————— # Now, load the ruby_bundle rule & install gems specified in the Gemfile diff --git a/WORKSPACE b/WORKSPACE index 4c1bdf1..028298d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -10,9 +10,9 @@ bazel_skylib_workspace() load("@bazel_skylib//lib:versions.bzl", "versions") -versions.check("2.1.1") +versions.check("3.4.1") -rules_ruby_select_sdk("2.7.0") +rules_ruby_select_sdk("2.7.1") local_repository( name = "bazelruby_rules_ruby_ruby_tests_testdata_another_workspace", @@ -25,22 +25,21 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") # installing go for buildifier http_archive( name = "io_bazel_rules_go", - sha256 = "842ec0e6b4fbfdd3de6150b61af92901eeb73681fd4d185746644c338f51d4c0", + sha256 = "8663604808d2738dc615a2c3eb70eba54a9a982089dd09f6ffe5d0e75771bc4f", urls = [ - "https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.1/rules_go-v0.20.1.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/v0.20.1/rules_go-v0.20.1.tar.gz", + "https://github.com/bazelbuild/rules_go/releases/download/v0.23.6/rules_go-v0.23.6.tar.gz", ], ) git_repository( name = "bazel_gazelle", - commit = "11a9ed24876401ee8b570c04de3a132e62415304", + commit = "c00612418c4dbc9f3cd35fe71fe1147748048b69", remote = "https://github.com/bazelbuild/bazel-gazelle", ) git_repository( name = "com_google_protobuf", - commit = "09745575a923640154bcf307fba8aedff47f240a", + commit = "6c61c1e63b9be3c36db6bed19032dfc0d63aadda", remote = "https://github.com/protocolbuffers/protobuf", shallow_since = "1558721209 -0700", ) @@ -49,7 +48,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe go_rules_dependencies() -go_register_toolchains(go_version = "1.12.9") +go_register_toolchains(go_version = "1.14.6") load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") @@ -63,9 +62,9 @@ protobuf_deps() http_archive( name = "io_bazel_rules_docker", - sha256 = "14ac30773fdb393ddec90e158c9ec7ebb3f8a4fd533ec2abbfd8789ad81a284b", - strip_prefix = "rules_docker-0.12.1", - urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.12.1/rules_docker-v0.12.1.tar.gz"], + sha256 = "4521794f0fba2e20f3bf15846ab5e01d5332e587e9ce81629c7f96c793bb7036", + strip_prefix = "rules_docker-0.14.4", + urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.14.4/rules_docker-v0.14.4.tar.gz"], ) load( diff --git a/bin/clean b/bin/clean new file mode 100755 index 0000000..6171763 --- /dev/null +++ b/bin/clean @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# vim: ft=sh +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— + +export BashMatic="${HOME}/.bashmatic" + +if [[ ! -f "${BashMatic}/init.sh" ]]; then + rm -rf "${BashMatic}" 2>/dev/null + git clone https://github.com/kigster/bashmatic "${BashMatic}" 1>/dev/null 2>&1 +fi + +# shellcheck disable=SC1090 +source "${BashMatic}/init.sh" 1>/dev/null 2>&1 + +main() { + export BAZEL_OPTS="--max_idle_secs=10800 --noshutdown_on_low_sys_mem --connect_timeout_secs=30" + h1 "Cleaning Bazel directories... Please wait." + local -a du_before=($(du -hs .)) + run "bazel clean --expunge" + for dir in $(ls -1 examples); do + run "cd examples/${dir}" + run "bazel clean --expunge" + run "cd -" + done + local -a du_after=($(du -hs .)) + h2 "Space before cleaning: ${bldylw}${du_before[0]}" \ + "Space after cleaning: ${bldgrn}${du_after[0]}" +} + +main "$@" + diff --git a/bin/deps b/bin/deps index 7a0e5fb..353492a 100755 --- a/bin/deps +++ b/bin/deps @@ -1,5 +1,13 @@ #!/usr/bin/env bash # vim: ft=sh +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— export BashMatic="${HOME}/.bashmatic" @@ -26,9 +34,9 @@ __version.detect() { } # Application Constants -export RulesRuby__RulesVersion=$(__version.detect .rules_version) -export RulesRuby__RubyVersion=2.7.0 -export RulesRuby__BazelVersion=$(__version.detect .bazelversion) +export RulesRuby__RulesVersion="$(__version.detect .rules_version)" +export RulesRuby__RubyVersion="$(__version.detect .ruby_version)" +export RulesRuby__BazelVersion="$(__version.detect .bazelversion)" bazel-sha() { bazel info | grep output_path | awk 'BEGIN{FS="/"}{ for(i = 1; i <= NF; i++) { if (length($i) == 32) print $i; } }' @@ -52,11 +60,10 @@ deps.start-clock() { deps.print-duration() { local finish=$(millis) - local duration=$(( finish - __start )) + local duration=$((finish - __start)) info "Total running time for was ${bldylw}$(time.duration.millis-to-secs ${duration}) seconds.\n\n" } - run.set-all abort-on-error # ensure we can exit with Ctrl-C diff --git a/bin/linter b/bin/linter index 609800e..255307b 100755 --- a/bin/linter +++ b/bin/linter @@ -1,6 +1,16 @@ #!/usr/bin/env bash +# vim: ft=bash # # Main dependency shell script that installs BashMatic Library in ~/.bashmatic folder. +# +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— export COLUMNS=65 @@ -100,7 +110,7 @@ lint.all() { hl.subtle "Git status -s output changed after before-commit hook." info "Changes before before-commit hook:" hr - diff "${pre}" "${post}" + diff "${__git_pre}" "${__git_post}" hr echo info "ACTION: ${bldylw}Please add any respective files to the commit and retry." diff --git a/bin/setup b/bin/setup index 552b2b9..f313335 100755 --- a/bin/setup +++ b/bin/setup @@ -2,10 +2,18 @@ # vim: ft=bash # # Runs setup. -# Run bin/setup help for info. # -set -e -# shellcheck disable=SC1091 +# Run "bin/setup help" for usage. +# +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— + source "bin/deps" #————————————————————————————————————————————————————————————————————————————————————————————————————————————— @@ -14,45 +22,69 @@ source "bin/deps" __setup.actions() { local sep="${1}" - printf "${bldylw}$(array.join "${sep}" $(util.functions-matching "setup." | sed 's/ main//g'))${clr}" + printf "$(array.join "${sep}" $(util.functions-matching "setup." | sed 's/ main//g'))" } #————————————————————————————————————————————————————————————————————————————————————————————————————————————— # Public Functions #————————————————————————————————————————————————————————————————————————————————————————————————————————————— -setup.help() { - printf " -$(help-header USAGE) - ${bldblk}# without any arguments runs a complete setup.${clr} -$(help-usage "bin/setup") +setup.rbenv() { + local rbenv_home="${HOME}/.rbenv" + local ruby_version="$(cat .ruby-version | tr -d '\n')" - ${bldblk}# alternatively, a sub-setup function name can be passed:${clr} -$(help-usage "bin/setup [ $(__setup.actions " | ") ]") + if [[ -n $(command -v ruby) ]]; then + local installed_version="$(ruby -e 'puts RUBY_VERSION' | tr -d '\n')" + if [[ ${installed_version} == ${ruby_version} ]]; then + info "RUBY already installed, current version: ${bldylw}${ruby_version}" + return 0 + fi + fi -$(help-header DESCRIPTION:) - Runs full setup without any arguments. + [[ -d "${rbenv_home}" && -f "${rbenv_home}/bin/rbenv" ]] || { + if [[ -z ${CI} ]]; then + warning "You are on a local system without any RBENV..." + run.ui.ask "Are you sure you want to wipe your local ~/.rbenv?" + fi - Accepts one optional argument — one of the actions that typically run - as part of setup, with one exception — ${bldylw}remove-git-hook${clr}. - This action removes the git commit hook installed by the setup. + warning "Recreating RBENV home, downloading rbenv..." + run "rm -rf ${rbenv_home}" + run "git clone https://github.com/rbenv/rbenv.git ${rbenv_home}" + export PATH="${rbenv_home}/bin:${rbenv_home}/shims:${PATH}" + } -$(help-header EXAMPLES:) -$(help-example "bin/setup") + export PATH="${rbenv_home}/bin:${rbenv_home}/shims:${PATH}" - Or, to run only one of the sub-functions (actions), pass - it as an argument: + [[ $(which rbenv) == "${rbenv_home}/bin/rbenv" ]] || { + error "Can't find rbenv in the PATH — which rbenv returns: $(which rbenv)" + error "PATH: ${PATH}" + return 1 + } + + # Set our current ruby version to the desired one, even if it's not yet there. + # This allows the next block to auto-detect it and skip the remainder. + run "rbenv global ${ruby_version} || true" + # see if we even need to install anything: + local ruby_sdk_marker="$(rbenv versions | grep "${ruby_version}" | cut -d ' ' -f 1)" + if [[ ${ruby_sdk_marker} == "*" ]]; then + info "Ruby Version ${ruby_version} is already present, and is RBENV default." + info "Skipping the rest of RBENV setup." + return 0 + fi -$(help-example bin/setup help) -$(help-example bin/setup remove-git-hook) + eval "$(rbenv init -)" + run "mkdir -p ${rbenv_home}/plugins" + run "git clone https://github.com/rbenv/ruby-build.git ${rbenv_home}/plugins/ruby-build" + run "rbenv rehash" + hash -r -etc. - " + run "rbenv install -s ${ruby_version}" + run "rbenv global ${ruby_version}" } setup.gems() { - for gem in rubocop relaxed-rubocop rubocop-performance; do - gem.install ${gem} + for gem in rubocop relaxed-rubocop; do + gem.install "${gem}" done } @@ -78,24 +110,25 @@ setup.git-hook() { } setup.os-specific() { - local os=$(uname -s | tr '[:upper:]' '[:lower:]') + local os="$(uname -s | tr '[:upper:]' '[:lower:]')" local setup_script setup_script="./bin/setup-${os}" if [[ -x "${setup_script}" ]]; then set -e - # shellcheck disable=SC1090 source "${setup_script}" # run it's main function eval "setup.${os} \"$*\"" echo if [[ -z ${CI} ]]; then - h2 "Please note — to print your Bazel environment run " "${bldylw}bin/show-env" + info "Please note — to print your Bazel environment run " + info "❯ ${bldylw}bin/show-env" else /usr/bin/env bash bin/show-env || true fi else error "Operating system ${os} is not currently supported." >&2 + return 1 fi echo return 0 @@ -103,29 +136,78 @@ setup.os-specific() { setup.main() { local action="$1" - [[ "${action}" == "-h" || ${action} == "--help" ]] && action="help" + local is_help=0 + local code=0 + + [[ "${action}" == "-h" || ${action} == "--help" ]] && { + action="help" + is_help=1 + } + local func="setup.${action}" if [[ -n ${action} ]]; then if util.is-a-function "${func}"; then - [[ ${action} != "help" ]] && h2 "Executing partial setup for action ${bldylw}${action}" + ((is_help)) || h2 "Executing partial setup for action ${bldylw}${action}" shift ${func} "$@" - local code=$? - [[ ${code} -eq 0 ]] && success "Setup for ${action} was successful" + code=$? + [[ ${code} -eq 0 ]] && { + ((is_help)) || success "Setup for ${action} was successful" + } [[ ${code} -ne 0 ]] && error "Error setting up ${action}" - exit ${code} else - h1 "Invalid action provided." "Valid actions are: $(__setup.actions " | ")" - exit 1 + error "Invalid action provided — '${action}'" + info "Valid actions are: [ ${bldylw}${action_list}$(txt-info) ]" + echo + code=1 fi else set +e h2 "Installing required development dependencies for working with rules_ruby and Bazel." + setup.rbenv setup.gems [[ -z ${CI} ]] && setup.git-hook setup.os-specific "$@" fi + + ((is_help)) || bin/show-env + + exit ${code} +} + +# shellcheck disable=SC2059,SC2155,SC2154 +setup.help() { + trap 'exit 0' INT + + printf " +$(help-header USAGE) + ${bldblk}# without any arguments runs a complete setup.${clr} +$(help-usage "bin/setup") + + ${bldblk}# alternatively, a sub-setup function name can be passed:${clr} +$(help-usage "bin/setup [ ${action_list} ]") + +$(help-header DESCRIPTION:) + Runs full setup without any arguments. + + Accepts one optional argument — one of the actions that typically run + as part of setup, with one exception — ${bldylw}remove-git-hook${clr}. + This action removes the git commit hook installed by the setup. + +$(help-header EXAMPLES:) +$(help-example "bin/setup") + + Or, to run only one of the sub-functions (actions), pass + it as an argument: + +$(help-example "bin/setup help") +$(help-example "bin/setup remove-git-hook") + +" } -setup.main "$@" +action_list="$(__setup.actions " | " | sed 's/setup\.//g')" +export action_list + +bashmatic.detect-subshell || setup.main "$@" diff --git a/bin/setup-darwin b/bin/setup-darwin index 9a067f3..a21487a 100755 --- a/bin/setup-darwin +++ b/bin/setup-darwin @@ -1,9 +1,20 @@ #!/usr/bin/env bash +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— set -e # shellcheck disable=SC1091 source "bin/deps" +declare -a BREW_DEPS +BREW_DEPS=(xz ydiff bash-completion) + #—————————————————————————————— OS-X SPECIFIC INSTALLERS ————————————————————————— __setup.brew-validate() { @@ -15,28 +26,22 @@ __setup.brew-validate() { fi } -__setup.brew-install-jdk() { - # The JDK homebrew cask is a required to install the java dependencies for Bazel - if ! brew cask list | grep -q openjdk; then - run "brew cask install homebrew/cask-versions/adoptopenjdk8" - else - info: "JDK already installed." - fi +function __setup.brew-deps() { + brew.install.packages "${BREW_DEPS[@]}" } -__setup.brew-deps() { - brew.install.packages 'xz' 'ydiff' +function __setup.is-bazelisk-installed() { + [[ -n "$(command -v bazelisk)" ]] } -__setup.is-bazelisk-installed() { - /bin/ls -al "$(command -v bazel)" | grep -q bazelisk +function __setup.is-bazel-installed() { + [[ -n "$(command -v bazel)" ]] } #—————————————————————————————— PUBLIC INTERFACE ————————————————————————— setup.brew() { __setup.brew-validate - __setup.brew-install-jdk __setup.brew-deps } @@ -46,18 +51,25 @@ setup.xcode-tools() { if [[ -n $(xcode-select --install 2>&1) ]]; then info: "xcode-select tools are already installed." fi + + info "Next command requires sudo privileges to accept XCode License" + run.set-next show-output-on + run "sudo xcodebuild -license accept" } -setup.bazelisk() { - if __setup.is-bazelisk-installed; then - info: "Bazelisk is already installed." +setup.bazel() { + brew.package.is-installed bazelbuild/tap/bazelisk && + brew.uninstall.package bazelbuild/tap/bazelisk + + if __setup.is-bazelisk-installed && __setup.is-bazel-installed ; then + info: "Bazel & bazelisk are already installed." else - run "brew install bazelbuild/tap/bazelisk" + brew.install.packages bazel bazelisk fi } setup.darwin() { setup.xcode-tools setup.brew - setup.bazelisk + setup.bazel } diff --git a/bin/setup-linux b/bin/setup-linux index d944ddd..7fe3a12 100755 --- a/bin/setup-linux +++ b/bin/setup-linux @@ -1,20 +1,29 @@ #!/usr/bin/env bash +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic # +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— + set -e -# shellcheck disable=SC1091 source "bin/deps" +setup.linux.bazel() { + run "sudo apt update -y || true" + run "sudo apt-get install -y libreadline-dev zlib1g-dev" + run "sudo curl -L -o /usr/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.0/bazelisk-linux-amd64" + run "sudo chmod +x /usr/bin/bazel" +} + setup.linux() { [[ -n $(command -v rvm) ]] && { run "rvm implode --force" [[ -d ${HOME}/.rvm ]] && run "rm -rf ${HOME}/.rvm" } - [[ -f ${HOME}/.bazelrc ]] || run "cp -v .circleci/.bazelrc ${HOME}" - - run "sudo apt update -y || true" - run "sudo apt-get install -y libreadline-dev zlib1g-dev" - run "sudo curl -L -o /usr/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.0/bazelisk-linux-amd64" - run "sudo chmod +x /usr/bin/bazel" + run.set-all abort-on-error + setup.linux.bazel } - diff --git a/bin/show-env b/bin/show-env index 4055b2e..6f396da 100755 --- a/bin/show-env +++ b/bin/show-env @@ -1,10 +1,19 @@ #!/usr/bin/env bash -# +# vim: ft=bash # When run, shows current runtime environment, locations of Ruby, Bazel, # python, etc. # # Safe to run, does not modify anything. +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— + set -e [[ -x bin/deps ]] && source "bin/deps" @@ -13,7 +22,7 @@ function setup.table-rows() { local value="$2" #$value="$(printf "%s" "${value}" | head -1 | tr -C -d '[:digit:][:punct:]' | sed 's/([0-9]+.[0-9]+.[0+9]+)//g;s/[()]/-/g')" value="$(printf "%s" "${value}" | head -1 | cut -b -40)" - printf "${bldylw}%12.12s : ${bldblu}%40.40s | ${txtpur}%s\n${clr}" "$1" "${value}" "$3" + printf "${bldylw}%10.10s : ${bldblu}%40.40s | ${txtpur}%s\n${clr}" "$1" "${value}" "$3" } @@ -25,15 +34,20 @@ function setup.print-versions() { echo setup.table-rows 'Bazel' "$(bazel --version)" "$(command -v bazel)" setup.table-rows 'Bazelisk' "${bazelisk_version}" - setup.table-rows 'Python ' "$(python --version 2>&1)" "$(command -v python) -> $(readlink "$(command -v python)")" - setup.table-rows 'Python2' "$(python2 --version 2>&1)" "$(command -v python2)" - setup.table-rows 'Python3' "$(python3 --version 2>&1)" "$(command -v python3)" - setup.table-rows 'Ruby' "$(ruby --version | sed -E 's/p[0-9]+.*$//g' 2>&1)" "$(command -v ruby)" setup.table-rows 'BASH' "$(bash --version 2>/dev/null | tr -d ',')" "$(command -v bash)" setup.table-rows 'CC' "$(cc --version 2>/dev/null)" "$(cc --version | grep clang)" setup.table-rows 'GO' "$(go version 2>/dev/null)" "$(command -v go)" - set -e hr + setup.table-rows 'Ruby' "$(ruby --version | sed -E 's/p[0-9]+.*$//g' 2>&1)" "$(command -v ruby)" + setup.table-rows 'RBENV' "$(rbenv --version 2>/dev/null)" "$(command -v rbenv)" + setup.table-rows 'RUBIES' " " "$(rbenv versions 2>/dev/null | sed 's/ (.*//g; s/[ \*]//g' | tr '\n' '|')" + hr + setup.table-rows 'Python' "$(python --version 2>&1)" "$(command -v python) -> $(readlink "$(command -v python)")" + setup.table-rows 'Python2' "$(python2 --version 2>&1)" "$(command -v python2)" + setup.table-rows 'Python3' "$(python3 --version 2>&1)" "$(command -v python3)" + hr + set -e + echo } diff --git a/bin/test-suite b/bin/test-suite index 4cd356e..7c17406 100755 --- a/bin/test-suite +++ b/bin/test-suite @@ -1,9 +1,18 @@ #!/usr/bin/env bash # vim: ft=bash +# ————————————————————————————————————————————————————————————————————————————————————— +# NOTE: These setup scripts rely on an open source BASH framework BashMatic. +# https://github.com/kigster/bashmatic +# +# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder. +# You can safely remove that folder after the setup if you wish, although re-running the +# setup will re-install it. +# ————————————————————————————————————————————————————————————————————————————————————— + set -e # shellcheck disable=SC1091 -source "bin/deps" +source "bin/deps" 2>/dev/null 1>/dev/null export SHELL_INIT="${HOME}/.bashrc" export BUNDLE_PATH="${BUNDLE_PATH:-${HOME}/.bundle/gems}" @@ -12,11 +21,13 @@ export PATH="${HOME}/.rbenv/bin:${HOME}/.rbenv/shims:/usr/local/bin:/usr/bin:/bi export BAZEL_OPTS="--host_jvm_args=-Xmx500m --host_jvm_args=-Xms500m" export BAZEL_BUILD_OPTS="--curses=no --verbose_failures -j 30 --progress_report_interval=2" export BAZEL_TEST_OPTS="--verbose_failures --test_verbose_timeout_warnings --verbose_explanations" -export RUBY_VERSION=2.7.0 +export RUBY_VERSION="$(__version.detect .ruby_version)" +export BUNDLER_VERSION=$(gem.gemfile.bundler-version) +export RULES_VERSION=$(__version.detect .rules_version) export BashMatic__Expr=" - [[ -f ${SHELL_INIT} ]] && source ${SHELL_INIT} - [[ -f ${HOME}/.bashmatic/init.sh ]] && source ${HOME}/.bashmatic/init.sh + [[ -f ${SHELL_INIT} ]] && source ${SHELL_INIT}; + [[ -f ${HOME}/.bashmatic/init.sh ]] && source ${HOME}/.bashmatic/init.sh; set -e " export Bazel__BuildSteps=" @@ -26,7 +37,7 @@ export Bazel__BuildSteps=" " deps.start-clock -run.set-all abort-on-error +run.set-all abort-on-error show-output-on #————————————————————————————————————————————————————————————————————————————————————————————————————————————— # Private Functions @@ -34,7 +45,7 @@ run.set-all abort-on-error __test-suite.setup.environment() { # shellcheck disable=SC2016 - grep -q 'bashmatic/init.sh' ${SHELL_INIT} || echo '[[ -d ${HOME}/.bashmatic ]] && source ${HOME}/.bashmatic/init.sh' >>"${SHELL_INIT}" + grep -q 'bashmatic/init.sh' "${SHELL_INIT}" || echo '[[ -d ${HOME}/.bashmatic ]] && source ${HOME}/.bashmatic/init.sh' >>"${SHELL_INIT}" [[ -n $(command -v rbenv) ]] && { export PATH="${HOME}/.rbenv/shims:${HOME}/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:${PATH}" @@ -52,12 +63,7 @@ __test-suite.setup.environment() { # Setup rbenv if needed, and install Ruby but only if needed __test-suite.setup.rbenv-ruby() { - - if [[ ! -d ${HOME}/.rbenv || -z $(command -v rbenv) ]]; then - [[ -d "${HOME}/.rbenv" ]] && run "mv ${HOME}/.rbenv ${HOME}/.rbenv.backup.$(date '+%s')" - run "rm -rf ${HOME}/.rbenv" - run "git clone https://github.com/rbenv/rbenv.git ${HOME}/.rbenv" - fi + [[ -d "${HOME}/.rbenv" ]] || run "git clone https://github.com/rbenv/rbenv.git ${HOME}/.rbenv" export PATH="${HOME}/.rbenv/bin:${HOME}/.rbenv/shims:${PATH}" @@ -68,15 +74,17 @@ __test-suite.setup.rbenv-ruby() { __test-suite.setup.environment - run "source ${SHELL_INIT}" + set +e + source "${SHELL_INIT}" 2>&1 1>/dev/null + set -e + run "rbenv install -s ${RUBY_VERSION}" run "rbenv global ${RUBY_VERSION}" run "rbenv rehash" run "ruby --version" run "gem update --system --no-doc" - run "gem install bundler --version 2.0.2 --no-doc" - run "bundle install --jobs=4 --retry=3 --path "${BUNDLE_PATH}"" - + run "gem install bundler --version ${BUNDLER_VERSION} --no-doc" + run "bundle install --jobs=4 --retry=3 --path ${BUNDLE_PATH}" } __test.actions() { @@ -96,6 +104,11 @@ __test.exec() { " } +__test.header() { + box.green-in-cyan "RulesRuby Test Suite Runner" "RubyRules Version ${bldylw}${RULES_VERSION}" + test-suite.setup +} + [[ -n ${DEBUG} ]] && set -x #————————————————————————————————————————————————————————————————————————————————————————————————————————————— @@ -222,14 +235,16 @@ test-suite.main() { shift if util.is-a-function "${func}"; then [[ "${action}" != "help" ]] && { - box.green-in-cyan "RulesRuby Test Suite Runner" "RubyRules Version $(cat .rules_version)" - test-suite.setup + __test.header h1 "Executing partial tests for action ${bldylw}${action}" } ${func} "$@" local code=$? - [[ ${code} -eq 0 ]] && success "Test Suite for ${action} was successful" - [[ ${code} -ne 0 ]] && error "Error running tests for ${action}" + if [[ ${code} -eq 0 ]]; then + success "Test Suite for ${action} was successful" + else + error "Error running tests for ${action}" + fi deps.print-duration exit ${code} else @@ -238,8 +253,7 @@ test-suite.main() { exit 1 fi else - box.green-in-cyan "RulesRuby Test Suite Runner —— full test suite in series." "RubyRules Version $(cat .rules_version)" - test-suite.setup + __test.header run.set-all abort-on-error set -e test.all diff --git a/examples/example_gem/WORKSPACE b/examples/example_gem/WORKSPACE index 2fee5d4..d0ee220 100644 --- a/examples/example_gem/WORKSPACE +++ b/examples/example_gem/WORKSPACE @@ -15,7 +15,7 @@ load( rules_ruby_dependencies() -rules_ruby_select_sdk("2.7.0") +rules_ruby_select_sdk("2.7.1") load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/examples/simple_rails_api/WORKSPACE b/examples/simple_rails_api/WORKSPACE index 52d2999..c0febc9 100644 --- a/examples/simple_rails_api/WORKSPACE +++ b/examples/simple_rails_api/WORKSPACE @@ -15,7 +15,7 @@ load( rules_ruby_dependencies() -rules_ruby_select_sdk(version = "2.7.0") +rules_ruby_select_sdk(version = "2.7.1") load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/examples/simple_script/WORKSPACE b/examples/simple_script/WORKSPACE index e99b80a..1caa54b 100644 --- a/examples/simple_script/WORKSPACE +++ b/examples/simple_script/WORKSPACE @@ -15,7 +15,7 @@ load( rules_ruby_dependencies() -rules_ruby_select_sdk(version = "2.7.0") +rules_ruby_select_sdk(version = "2.7.1") load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_bundle") diff --git a/ruby/private/bundle/def.bzl b/ruby/private/bundle/def.bzl index d3fc880..fade53e 100644 --- a/ruby/private/bundle/def.bzl +++ b/ruby/private/bundle/def.bzl @@ -8,7 +8,7 @@ load( "SCRIPT_BUILD_FILE_GENERATOR", "SCRIPT_INSTALL_GEM", ) -load("//ruby/private:providers.bzl", "RubyRuntimeContext") +load("//ruby/private:providers.bzl", "RubyRuntimeInfo") # Runs bundler with arbitrary arguments # eg: run_bundler(runtime_ctx, [ "lock", " --gemfile", "Gemfile.rails5" ]) @@ -161,7 +161,7 @@ def _ruby_bundle_impl(ctx): bundler_version = ctx.attr.bundler_version # Setup this provider that we pass around between functions for convenience - runtime_ctx = RubyRuntimeContext( + runtime_ctx = RubyRuntimeInfo( ctx = ctx, interpreter = ctx.path(ctx.attr.ruby_interpreter), environment = {"RUBYOPT": "--enable-gems"}, diff --git a/ruby/private/constants.bzl b/ruby/private/constants.bzl index 6600fc7..633878f 100644 --- a/ruby/private/constants.bzl +++ b/ruby/private/constants.bzl @@ -1,4 +1,5 @@ -load(":providers.bzl", "RubyLibrary") +# Ruby Constants +load(":providers.bzl", "RubyLibraryInfo") RULES_RUBY_WORKSPACE_NAME = "@bazelruby_rules_ruby" TOOLCHAIN_TYPE_NAME = "%s//ruby:toolchain_type" % RULES_RUBY_WORKSPACE_NAME @@ -20,7 +21,7 @@ RUBY_ATTRS = { allow_files = True, ), "deps": attr.label_list( - providers = [RubyLibrary], + providers = [RubyLibraryInfo], ), "includes": attr.string_list(), "rubyopt": attr.string_list(), diff --git a/ruby/private/dependencies.bzl b/ruby/private/dependencies.bzl index 883bcf2..f4be128 100644 --- a/ruby/private/dependencies.bzl +++ b/ruby/private/dependencies.bzl @@ -1,3 +1,7 @@ +""" +Dependencies +""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def rules_ruby_dependencies(): diff --git a/ruby/private/gemspec/def.bzl b/ruby/private/gemspec/def.bzl index 9560da8..2f15a02 100644 --- a/ruby/private/gemspec/def.bzl +++ b/ruby/private/gemspec/def.bzl @@ -1,7 +1,7 @@ load( "//ruby/private:providers.bzl", - "RubyGem", - "RubyLibrary", + "RubyGemInfo", + "RubyLibraryInfo", ) load( "//ruby/private:constants.bzl", @@ -14,11 +14,11 @@ load( def _get_transitive_srcs(srcs, deps): for dep in deps: - print(dep[RubyLibrary].transitive_ruby_srcs) + print(dep[RubyLibraryInfo].transitive_ruby_srcs) return depset( srcs, - transitive = [dep[RubyLibrary].transitive_ruby_srcs for dep in deps], + transitive = [dep[RubyLibraryInfo].transitive_ruby_srcs for dep in deps], ) def _unique_elems(list): @@ -126,7 +126,7 @@ def _gem_impl(ctx): DefaultInfo( files = _get_transitive_srcs([gemspec, gem_readme], ctx.attr.deps), ), - RubyGem( + RubyGemInfo( ctx = ctx, gem_author_emails = ctx.attr.gem_author_emails, gem_authors = ctx.attr.gem_authors, @@ -143,7 +143,7 @@ def _gem_impl(ctx): gemspec = rule( implementation = _gem_impl, attrs = GEMSPEC_ATTRS, - provides = [DefaultInfo, RubyGem], + provides = [DefaultInfo, RubyGemInfo], ) def gem( diff --git a/ruby/private/library.bzl b/ruby/private/library.bzl index e91cb09..b363c76 100644 --- a/ruby/private/library.bzl +++ b/ruby/private/library.bzl @@ -1,5 +1,9 @@ +""" +Constants +""" + load(":constants.bzl", "TOOLCHAIN_TYPE_NAME") -load(":providers.bzl", "RubyLibrary") +load(":providers.bzl", "RubyLibraryInfo") load( "//ruby/private/tools:deps.bzl", _transitive_deps = "transitive_deps", @@ -16,7 +20,7 @@ def _ruby_library_impl(ctx): data_runfiles = deps.data_files, files = deps.srcs, ), - RubyLibrary( + RubyLibraryInfo( transitive_ruby_srcs = deps.srcs, ruby_incpaths = deps.incpaths, rubyopt = deps.rubyopt, @@ -32,7 +36,7 @@ ruby_library = rule( "includes": attr.string_list(), "rubyopt": attr.string_list(), "deps": attr.label_list( - providers = [RubyLibrary], + providers = [RubyLibraryInfo], ), "data": attr.label_list( allow_files = True, diff --git a/ruby/private/providers.bzl b/ruby/private/providers.bzl index 33dbe1e..131f335 100644 --- a/ruby/private/providers.bzl +++ b/ruby/private/providers.bzl @@ -1,4 +1,8 @@ -RubyLibrary = provider( +""" +Provider Structs +""" + +RubyLibraryInfo = provider( fields = [ "transitive_ruby_srcs", "ruby_incpaths", @@ -6,7 +10,7 @@ RubyLibrary = provider( ], ) -RubyRuntimeContext = provider( +RubyRuntimeInfo = provider( doc = "Carries info required to execute Ruby Scripts", fields = [ "ctx", @@ -15,7 +19,7 @@ RubyRuntimeContext = provider( ], ) -RubyGem = provider( +RubyGemInfo = provider( doc = "Carries info required to package a ruby gem", fields = [ "ctx", diff --git a/ruby/private/rspec.bzl b/ruby/private/rspec.bzl index e86603b..42a9378 100644 --- a/ruby/private/rspec.bzl +++ b/ruby/private/rspec.bzl @@ -46,7 +46,7 @@ def ruby_rspec( rspec_gems = ["%s:%s" % (bundle, gem) for gem in DEFAULT_RSPEC_GEMS] deps += rspec_gems - deps += ["%s:bin" % bundle] + deps.append("%s:bin" % bundle) ruby_rspec_test( name = name, diff --git a/ruby/private/sdk.bzl b/ruby/private/sdk.bzl index dc6c13c..1e06c19 100644 --- a/ruby/private/sdk.bzl +++ b/ruby/private/sdk.bzl @@ -6,7 +6,18 @@ load( def rules_ruby_select_sdk(version = "host"): """Registers ruby toolchains in the WORKSPACE file.""" - supported_versions = ["host", "2.6.3", "2.6.5", "2.7.0"] + supported_versions = [ + "host", + "2.5.8", + "2.6.3", + "2.6.4", + "2.6.5", + "2.6.6", + "2.7.1", + "2.7.1", + "2.8.0", + ] + if version in supported_versions: _ruby_runtime( name = "org_ruby_lang_ruby_toolchain", diff --git a/ruby/private/toolchains/ruby_runtime.bzl b/ruby/private/toolchains/ruby_runtime.bzl index 7fe18c2..21f8625 100644 --- a/ruby/private/toolchains/ruby_runtime.bzl +++ b/ruby/private/toolchains/ruby_runtime.bzl @@ -4,9 +4,9 @@ load("//ruby/private/toolchains:repository_context.bzl", "ruby_repository_contex def _install_ruby_version(ctx, version): print("download and extract ruby-build") ctx.download_and_extract( - url = "https://github.com/rbenv/ruby-build/archive/v20200224.tar.gz", - sha256 = "dc3799a1c784c9a0f214a3c0c861a0bb798cd40ee2df49bce95b4c95adf6fc79", - stripPrefix = "ruby-build-20200224", + url = "https://github.com/rbenv/ruby-build/archive/v20200727.tar.gz", + sha256 = "71679d49d9190250059eaa0bc0bedd080c00a523ec47662f559f7629f71772ea", + stripPrefix = "ruby-build-20200727", ) install_path = "./build" diff --git a/ruby/private/tools/deps.bzl b/ruby/private/tools/deps.bzl index f537740..9a24140 100644 --- a/ruby/private/tools/deps.bzl +++ b/ruby/private/tools/deps.bzl @@ -1,20 +1,21 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load( "//ruby/private:providers.bzl", - "RubyLibrary", + "RubyLibraryInfo", ) def _transitive_srcs(deps): return struct( - srcs = [d[RubyLibrary].transitive_ruby_srcs for d in deps if RubyLibrary in d], - incpaths = [d[RubyLibrary].ruby_incpaths for d in deps if RubyLibrary in d], - rubyopt = [d[RubyLibrary].rubyopt for d in deps if RubyLibrary in d], + srcs = [d[RubyLibraryInfo].transitive_ruby_srcs for d in deps if RubyLibraryInfo in d], + incpaths = [d[RubyLibraryInfo].ruby_incpaths for d in deps if RubyLibraryInfo in d], + rubyopt = [d[RubyLibraryInfo].rubyopt for d in deps if RubyLibraryInfo in d], data_files = [d[DefaultInfo].data_runfiles.files for d in deps], default_files = [d[DefaultInfo].default_runfiles.files for d in deps], ) def transitive_deps(ctx, extra_files = [], extra_deps = []): - """Calculates transitive sets of args. + """ + Calculates transitive sets of args. Calculates the transitive sets for ruby sources, data runfiles, include flags and runtime flags from the srcs, data and deps attributes @@ -25,6 +26,8 @@ def transitive_deps(ctx, extra_files = [], extra_deps = []): ctx: a ctx object for a ruby_library or a ruby_binary rule. extra_files: a list of File objects to be added to the default_files extra_deps: a list of Target objects. + Returns: + struct """ deps = _transitive_srcs(ctx.attr.deps + extra_deps) files = depset(extra_files + ctx.files.srcs) diff --git a/ruby/tests/BUILD.bazel b/ruby/tests/BUILD.bazel index d26dabe..b3e7290 100644 --- a/ruby/tests/BUILD.bazel +++ b/ruby/tests/BUILD.bazel @@ -260,21 +260,21 @@ pkg_tar( }, ) -container_image( - name = "load_path_in_runfiles_container_image", - base = "@ruby_base_container//image", - entrypoint = ["/app/load_path_in_runfiles"], - tars = [":load_path_in_runfiles_container_layer"], -) +# container_image( +# name = "load_path_in_runfiles_container_image", +# base = "@ruby_base_container//image", +# entrypoint = ["/app/load_path_in_runfiles"], +# tars = [":load_path_in_runfiles_container_layer"], +# ) -sh_test( - name = "load_path_in_runfiles_container_test", - size = "small", - srcs = ["container_test.sh"], - args = [ - "$(location :load_path_in_runfiles_container_image)", - "bazel/ruby/tests:load_path_in_runfiles_container_image", - ], - data = [":load_path_in_runfiles_container_image"], - tags = ["docker"], -) +# sh_test( +# name = "load_path_in_runfiles_container_test", +# size = "small", +# srcs = ["container_test.sh"], +# args = [ +# "$(location :load_path_in_runfiles_container_image)", +# "bazel/ruby/tests:load_path_in_runfiles_container_image", +# ], +# data = [":load_path_in_runfiles_container_image"], +# tags = ["docker"], +# )