Skip to content

Commit

Permalink
Migrate Ruby bindings from CrazyFun to Bazel
Browse files Browse the repository at this point in the history
This commit adds rb/BUILD.bazel with all the tasks from rb/build.desc
except for Ruby gem build/release. Those are missing and still need to
be implemented.

The rules are based on coinbase/rules_ruby but several patches were
needed to be done to make it work for Selenium. These patches will be
upstreamed and then we will drop the forked version.

Targets were migrated to match existing tasks as closely as possible, so
most of the current ./go commands can be replaced with bazel CLI.
See the table below for example mappings.

| crazyfun                        | bazel                                          |
| ./go //rb:gem:webdriver:build   | (not implemented yet)                          |
| ./go //rb:gem:webdriver:release | (not implemented yet)                          |
| ./go //rb:common                | bazel build //rb:common                        |
| ./go //rb:chrome                | bazel build //rb:chrome                        |
| ./go //rb:chrome-test           | bazel test //rb:chrome-test                    |
| ./go //rb:remote-chrome-test    | bazel test //rb:remote-chrome-test             |
| ./go //rb:unit-test             | bazel test //rb:unit-test                      |
| ./go //rb:unit-test focus=1     | bazel test --test_arg="-tfocus" //rb:unit-test |
| ./go //rb:unit-test log=1       | bazel test --test_env="DEBUG=1" //rb:unit-test |
| ./go //rb:docs                  | bazel run //rb:docs                            |
| ./go //rb:lint                  | bazel run //rb:lint                            |

By default, Bazel hides output for successfully passed tests, so if you
want to print, run bazel test with --test_output=all or
--test_output=streamed.

CDP client code generator can now be run a simple Ruby script that
accepts browser/JS protocol file paths as input parameters. This is
necessary to the generator from rb_binary Bazel rule.
  • Loading branch information
p0deje committed May 4, 2021
1 parent 25e848a commit c6d4516
Show file tree
Hide file tree
Showing 20 changed files with 736 additions and 28 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build --noexperimental_sandbox_default_allow_network
build --test_env=CI
build --test_env=DASHBOARD_URL
build --test_env=DISPLAY
build --test_env=FIREFOX_NIGHTLY_BINARY
build --test_env=GITHUB_ACTIONS
build --test_env=LOCALAPPDATA
build --test_env=MOZ_HEADLESS
Expand Down
67 changes: 60 additions & 7 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
task: ['chrome-test', 'remote-chrome-test']
target: ['chrome-test', 'remote-chrome-test']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
Expand All @@ -23,10 +23,20 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
- uses: actions/cache@v2
with:
path: |
~/.cache/bazel-disk
~/.cache/bazel-repo
key: ${{ runner.os }}-bazel-ruby-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
- uses: ./.github/actions/setup-bazelisk
- uses: ./.github/actions/setup-chrome
- run: Xvfb :99 &
- run: ./go //rb:${{ matrix.task }}
- uses: ./.github/actions/bazel
with:
command: test --test_output=all //rb:${{ matrix.target }}
env:
DISPLAY: :99

Expand All @@ -35,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
task: ['firefox-test', 'remote-firefox-test']
target: ['firefox-test', 'remote-firefox-test']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
Expand All @@ -44,10 +54,20 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
- uses: actions/cache@v2
with:
path: |
~/.cache/bazel-disk
~/.cache/bazel-repo
key: ${{ runner.os }}-bazel-ruby-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
- uses: ./.github/actions/setup-bazelisk
- uses: ./.github/actions/setup-firefox
- run: Xvfb :99 &
- run: ./go //rb:${{ matrix.task }}
- uses: ./.github/actions/bazel
with:
command: test --test_output=all //rb:${{ matrix.target }}
env:
DISPLAY: :99

Expand All @@ -58,7 +78,18 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
- run: ./go //rb:docs
- uses: actions/cache@v2
with:
path: |
~/.cache/bazel-disk
~/.cache/bazel-repo
key: ${{ runner.os }}-bazel-ruby-docs-${{ hashFiles('**/BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
- uses: ./.github/actions/setup-bazelisk
- uses: ./.github/actions/bazel
with:
command: run //rb:docs

lint:
runs-on: ubuntu-latest
Expand All @@ -67,7 +98,18 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
- run: ./go //rb:lint
- uses: actions/cache@v2
with:
path: |
~/.cache/bazel-disk
~/.cache/bazel-repo
key: ${{ runner.os }}-bazel-ruby-lint-${{ hashFiles('**/BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-ruby-lint-
- uses: ./.github/actions/setup-bazelisk
- uses: ./.github/actions/bazel
with:
command: run //rb:lint

unit-test:
runs-on: ubuntu-latest
Expand All @@ -80,4 +122,15 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- run: ./go //rb:unit-test
- uses: actions/cache@v2
with:
path: |
~/.cache/bazel-disk
~/.cache/bazel-repo
key: ${{ runner.os }}-bazel-ruby-unit-test-${{ matrix.ruby }}-${{ hashFiles('**/BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-ruby-unit-test-${{ matrix.ruby }}-
- uses: ./.github/actions/setup-bazelisk
- uses: ./.github/actions/bazel
with:
command: test --test_output=all //rb:unit-test
30 changes: 30 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,33 @@ k8s_defaults(
load("//common:repositories.bzl", "pin_browsers")

pin_browsers()

http_archive(
name = "coinbase_rules_ruby",
sha256 = "1023905d384a9c2822f33099127d55d151f3f1bd54b9fc8404a7c9cc80f8dba0",
strip_prefix = "rules_ruby-41f5dab4d7c4d0cb96a3b4b8e188861096a36be8",
url = "https://github.com/p0deje/rules_ruby/archive/41f5dab4d7c4d0cb96a3b4b8e188861096a36be8.tar.gz",
)

load(
"@coinbase_rules_ruby//ruby:deps.bzl",
"rules_ruby_dependencies",
"ruby_register_toolchains",
)

rules_ruby_dependencies()
ruby_register_toolchains()

load("@coinbase_rules_ruby//ruby:defs.bzl", "rb_bundle")

rb_bundle(
name = "bundle",
bundler_version = "2.1.4",
gemfile = "//:rb/Gemfile",
srcs = [
"//:rb/lib/selenium/devtools/version.rb",
"//:rb/lib/selenium/webdriver/version.rb",
"//:rb/selenium-devtools.gemspec",
"//:rb/selenium-webdriver.gemspec",
]
)
1 change: 1 addition & 0 deletions common/devtools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports_files(
visibility = [
"//javascript/node/selenium-webdriver:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions common/devtools/chromium/v85/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package(
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
"//javascript/node/selenium-webdriver:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions common/devtools/chromium/v88/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package(
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
"//javascript/node/selenium-webdriver:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions common/devtools/chromium/v89/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package(
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
"//javascript/node/selenium-webdriver:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions common/devtools/chromium/v90/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package(
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
"//javascript/node/selenium-webdriver:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions common/devtools/chromium/v91/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package(
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
"//javascript/node/selenium-webdriver:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

Expand Down
2 changes: 1 addition & 1 deletion generate_api_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rm -rf docs/api/java docs/api/py docs/api/rb

mv build/javadoc docs/api/java
mv build/docs/api/py docs/api/py
mv build/docs/api/rb docs/api/rb
mv bazel-bin/rb/docs.runfiles/selenium/docs/api/rb docs/api/rb

git add -A docs/api

Expand Down
1 change: 1 addition & 0 deletions java/server/src/org/openqa/selenium/grid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ java_binary(
"//java/server/test:__subpackages__",
"//javascript:__subpackages__",
"//py:__pkg__",
"//rb:__pkg__",
],
runtime_deps = [
":grid",
Expand Down
2 changes: 2 additions & 0 deletions javascript/atoms/fragments/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ closure_fragment(
"//javascript/ie-driver:__pkg__",
"//javascript/node/selenium-webdriver/lib/atoms:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
deps = [
"//javascript/atoms:dom",
Expand Down Expand Up @@ -191,6 +192,7 @@ closure_fragment(
"//javascript/chrome-driver:__pkg__",
"//javascript/node/selenium-webdriver/lib/atoms:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
deps = [
"//javascript/atoms:locators",
Expand Down
1 change: 1 addition & 0 deletions javascript/webdriver/atoms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ closure_fragment(
"//javascript/ie-driver:__pkg__",
"//javascript/node/selenium-webdriver/lib/atoms:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
deps = [
":atoms-lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def handle(_fun, dir, args)
copy_sources dir, args[:srcs]
copy_resources dir, args[:resources], build_dir if args[:resources]
require_source build_dir, args[:require]
create_output_dir build_dir, "#{args[:output_dir]}/#{args[:version]}"
Dir.chdir(build_dir) { call_class(args[:klass], args) }
remove_sources args[:srcs]
end
Expand All @@ -24,10 +23,6 @@ def require_source(dir, src)
require File.join(dir, src)
end

def create_output_dir(root_dir, output_dir)
mkdir_p File.join(root_dir, output_dir)
end

def call_class(klass, **args)
Object.const_get(klass).new.call(args)
end
Expand Down
5 changes: 4 additions & 1 deletion rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require:
AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'lib/selenium/webdriver/devtools/**/*'
- 'lib/selenium/devtools/**/*'

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true
Expand Down Expand Up @@ -60,6 +60,7 @@ Metrics/ClassLength:
- 'lib/selenium/webdriver/common/driver.rb'
- 'lib/selenium/webdriver/remote/bridge.rb'
- 'lib/selenium/webdriver/remote/capabilities.rb'
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'

Metrics/CyclomaticComplexity:
Max: 9
Expand Down Expand Up @@ -143,8 +144,10 @@ Style/BlockDelimiters:
Style/CommentedKeyword:
Enabled: false

# __dir__ should be avoided when used with Bazel.
Style/Dir:
Exclude:
- 'selenium-devtools.gemspec'
- 'selenium-webdriver.gemspec'

# Consider documenting all top-level classes and modules
Expand Down
Loading

0 comments on commit c6d4516

Please sign in to comment.