Skip to content

Commit c6d4516

Browse files
committed
Migrate Ruby bindings from CrazyFun to Bazel
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.
1 parent 25e848a commit c6d4516

File tree

20 files changed

+736
-28
lines changed

20 files changed

+736
-28
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ build --noexperimental_sandbox_default_allow_network
3434
build --test_env=CI
3535
build --test_env=DASHBOARD_URL
3636
build --test_env=DISPLAY
37+
build --test_env=FIREFOX_NIGHTLY_BINARY
3738
build --test_env=GITHUB_ACTIONS
3839
build --test_env=LOCALAPPDATA
3940
build --test_env=MOZ_HEADLESS

.github/workflows/ruby.yml

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
task: ['chrome-test', 'remote-chrome-test']
17+
target: ['chrome-test', 'remote-chrome-test']
1818
steps:
1919
- uses: actions/checkout@v2
2020
- uses: actions/setup-java@v1
@@ -23,10 +23,20 @@ jobs:
2323
- uses: ruby/setup-ruby@v1
2424
with:
2525
ruby-version: 2.5
26+
- uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.cache/bazel-disk
30+
~/.cache/bazel-repo
31+
key: ${{ runner.os }}-bazel-ruby-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
32+
restore-keys: |
33+
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
2634
- uses: ./.github/actions/setup-bazelisk
2735
- uses: ./.github/actions/setup-chrome
2836
- run: Xvfb :99 &
29-
- run: ./go //rb:${{ matrix.task }}
37+
- uses: ./.github/actions/bazel
38+
with:
39+
command: test --test_output=all //rb:${{ matrix.target }}
3040
env:
3141
DISPLAY: :99
3242

@@ -35,7 +45,7 @@ jobs:
3545
strategy:
3646
fail-fast: false
3747
matrix:
38-
task: ['firefox-test', 'remote-firefox-test']
48+
target: ['firefox-test', 'remote-firefox-test']
3949
steps:
4050
- uses: actions/checkout@v2
4151
- uses: actions/setup-java@v1
@@ -44,10 +54,20 @@ jobs:
4454
- uses: ruby/setup-ruby@v1
4555
with:
4656
ruby-version: 2.5
57+
- uses: actions/cache@v2
58+
with:
59+
path: |
60+
~/.cache/bazel-disk
61+
~/.cache/bazel-repo
62+
key: ${{ runner.os }}-bazel-ruby-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
63+
restore-keys: |
64+
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
4765
- uses: ./.github/actions/setup-bazelisk
4866
- uses: ./.github/actions/setup-firefox
4967
- run: Xvfb :99 &
50-
- run: ./go //rb:${{ matrix.task }}
68+
- uses: ./.github/actions/bazel
69+
with:
70+
command: test --test_output=all //rb:${{ matrix.target }}
5171
env:
5272
DISPLAY: :99
5373

@@ -58,7 +78,18 @@ jobs:
5878
- uses: ruby/setup-ruby@v1
5979
with:
6080
ruby-version: 2.5
61-
- run: ./go //rb:docs
81+
- uses: actions/cache@v2
82+
with:
83+
path: |
84+
~/.cache/bazel-disk
85+
~/.cache/bazel-repo
86+
key: ${{ runner.os }}-bazel-ruby-docs-${{ hashFiles('**/BUILD.bazel') }}
87+
restore-keys: |
88+
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
89+
- uses: ./.github/actions/setup-bazelisk
90+
- uses: ./.github/actions/bazel
91+
with:
92+
command: run //rb:docs
6293

6394
lint:
6495
runs-on: ubuntu-latest
@@ -67,7 +98,18 @@ jobs:
6798
- uses: ruby/setup-ruby@v1
6899
with:
69100
ruby-version: 2.5
70-
- run: ./go //rb:lint
101+
- uses: actions/cache@v2
102+
with:
103+
path: |
104+
~/.cache/bazel-disk
105+
~/.cache/bazel-repo
106+
key: ${{ runner.os }}-bazel-ruby-lint-${{ hashFiles('**/BUILD.bazel') }}
107+
restore-keys: |
108+
${{ runner.os }}-bazel-ruby-lint-
109+
- uses: ./.github/actions/setup-bazelisk
110+
- uses: ./.github/actions/bazel
111+
with:
112+
command: run //rb:lint
71113

72114
unit-test:
73115
runs-on: ubuntu-latest
@@ -80,4 +122,15 @@ jobs:
80122
- uses: ruby/setup-ruby@v1
81123
with:
82124
ruby-version: ${{ matrix.ruby }}
83-
- run: ./go //rb:unit-test
125+
- uses: actions/cache@v2
126+
with:
127+
path: |
128+
~/.cache/bazel-disk
129+
~/.cache/bazel-repo
130+
key: ${{ runner.os }}-bazel-ruby-unit-test-${{ matrix.ruby }}-${{ hashFiles('**/BUILD.bazel') }}
131+
restore-keys: |
132+
${{ runner.os }}-bazel-ruby-unit-test-${{ matrix.ruby }}-
133+
- uses: ./.github/actions/setup-bazelisk
134+
- uses: ./.github/actions/bazel
135+
with:
136+
command: test --test_output=all //rb:unit-test

WORKSPACE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,33 @@ k8s_defaults(
253253
load("//common:repositories.bzl", "pin_browsers")
254254

255255
pin_browsers()
256+
257+
http_archive(
258+
name = "coinbase_rules_ruby",
259+
sha256 = "1023905d384a9c2822f33099127d55d151f3f1bd54b9fc8404a7c9cc80f8dba0",
260+
strip_prefix = "rules_ruby-41f5dab4d7c4d0cb96a3b4b8e188861096a36be8",
261+
url = "https://github.com/p0deje/rules_ruby/archive/41f5dab4d7c4d0cb96a3b4b8e188861096a36be8.tar.gz",
262+
)
263+
264+
load(
265+
"@coinbase_rules_ruby//ruby:deps.bzl",
266+
"rules_ruby_dependencies",
267+
"ruby_register_toolchains",
268+
)
269+
270+
rules_ruby_dependencies()
271+
ruby_register_toolchains()
272+
273+
load("@coinbase_rules_ruby//ruby:defs.bzl", "rb_bundle")
274+
275+
rb_bundle(
276+
name = "bundle",
277+
bundler_version = "2.1.4",
278+
gemfile = "//:rb/Gemfile",
279+
srcs = [
280+
"//:rb/lib/selenium/devtools/version.rb",
281+
"//:rb/lib/selenium/webdriver/version.rb",
282+
"//:rb/selenium-devtools.gemspec",
283+
"//:rb/selenium-webdriver.gemspec",
284+
]
285+
)

common/devtools/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ exports_files(
88
visibility = [
99
"//javascript/node/selenium-webdriver:__pkg__",
1010
"//py:__pkg__",
11+
"//rb:__pkg__",
1112
],
1213
)
1314

common/devtools/chromium/v85/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package(
44
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
55
"//javascript/node/selenium-webdriver:__pkg__",
66
"//py:__pkg__",
7+
"//rb:__pkg__",
78
],
89
)
910

common/devtools/chromium/v88/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package(
44
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
55
"//javascript/node/selenium-webdriver:__pkg__",
66
"//py:__pkg__",
7+
"//rb:__pkg__",
78
],
89
)
910

common/devtools/chromium/v89/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package(
44
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
55
"//javascript/node/selenium-webdriver:__pkg__",
66
"//py:__pkg__",
7+
"//rb:__pkg__",
78
],
89
)
910

common/devtools/chromium/v90/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package(
44
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
55
"//javascript/node/selenium-webdriver:__pkg__",
66
"//py:__pkg__",
7+
"//rb:__pkg__",
78
],
89
)
910

common/devtools/chromium/v91/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package(
44
"//java/client/src/org/openqa/selenium/devtools:__subpackages__",
55
"//javascript/node/selenium-webdriver:__pkg__",
66
"//py:__pkg__",
7+
"//rb:__pkg__",
78
],
89
)
910

generate_api_docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rm -rf docs/api/java docs/api/py docs/api/rb
2020

2121
mv build/javadoc docs/api/java
2222
mv build/docs/api/py docs/api/py
23-
mv build/docs/api/rb docs/api/rb
23+
mv bazel-bin/rb/docs.runfiles/selenium/docs/api/rb docs/api/rb
2424

2525
git add -A docs/api
2626

java/server/src/org/openqa/selenium/grid/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ java_binary(
100100
"//java/server/test:__subpackages__",
101101
"//javascript:__subpackages__",
102102
"//py:__pkg__",
103+
"//rb:__pkg__",
103104
],
104105
runtime_deps = [
105106
":grid",

javascript/atoms/fragments/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ closure_fragment(
113113
"//javascript/ie-driver:__pkg__",
114114
"//javascript/node/selenium-webdriver/lib/atoms:__pkg__",
115115
"//py:__pkg__",
116+
"//rb:__pkg__",
116117
],
117118
deps = [
118119
"//javascript/atoms:dom",
@@ -191,6 +192,7 @@ closure_fragment(
191192
"//javascript/chrome-driver:__pkg__",
192193
"//javascript/node/selenium-webdriver/lib/atoms:__pkg__",
193194
"//py:__pkg__",
195+
"//rb:__pkg__",
194196
],
195197
deps = [
196198
"//javascript/atoms:locators",

javascript/webdriver/atoms/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ closure_fragment(
9191
"//javascript/ie-driver:__pkg__",
9292
"//javascript/node/selenium-webdriver/lib/atoms:__pkg__",
9393
"//py:__pkg__",
94+
"//rb:__pkg__",
9495
],
9596
deps = [
9697
":atoms-lib",

rake_tasks/crazy_fun/mappings/ruby_mappings/ruby_class_call.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def handle(_fun, dir, args)
1111
copy_sources dir, args[:srcs]
1212
copy_resources dir, args[:resources], build_dir if args[:resources]
1313
require_source build_dir, args[:require]
14-
create_output_dir build_dir, "#{args[:output_dir]}/#{args[:version]}"
1514
Dir.chdir(build_dir) { call_class(args[:klass], args) }
1615
remove_sources args[:srcs]
1716
end
@@ -24,10 +23,6 @@ def require_source(dir, src)
2423
require File.join(dir, src)
2524
end
2625

27-
def create_output_dir(root_dir, output_dir)
28-
mkdir_p File.join(root_dir, output_dir)
29-
end
30-
3126
def call_class(klass, **args)
3227
Object.const_get(klass).new.call(args)
3328
end

rb/.rubocop.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require:
55
AllCops:
66
TargetRubyVersion: 2.5
77
Exclude:
8-
- 'lib/selenium/webdriver/devtools/**/*'
8+
- 'lib/selenium/devtools/**/*'
99

1010
Layout/EmptyLinesAroundAttributeAccessor:
1111
Enabled: true
@@ -60,6 +60,7 @@ Metrics/ClassLength:
6060
- 'lib/selenium/webdriver/common/driver.rb'
6161
- 'lib/selenium/webdriver/remote/bridge.rb'
6262
- 'lib/selenium/webdriver/remote/capabilities.rb'
63+
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'
6364

6465
Metrics/CyclomaticComplexity:
6566
Max: 9
@@ -143,8 +144,10 @@ Style/BlockDelimiters:
143144
Style/CommentedKeyword:
144145
Enabled: false
145146

147+
# __dir__ should be avoided when used with Bazel.
146148
Style/Dir:
147149
Exclude:
150+
- 'selenium-devtools.gemspec'
148151
- 'selenium-webdriver.gemspec'
149152

150153
# Consider documenting all top-level classes and modules

0 commit comments

Comments
 (0)