Skip to content

Commit

Permalink
[rb] update mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Mar 15, 2021
1 parent 1a4b347 commit e509e71
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 75 deletions.
1 change: 1 addition & 0 deletions rake_tasks/crazy_fun/mappings/ruby_mappings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def add_all(fun)

fun.add_mapping "rubydocs", RubyDocs.new
fun.add_mapping "rubygem", RubyGem.new
fun.add_mapping "rubydevtoolsgem", RubyGem.new

fun.add_mapping "ruby_class_call", RubyClassCall.new
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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]
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 Down
15 changes: 8 additions & 7 deletions rake_tasks/crazy_fun/mappings/ruby_mappings/ruby_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class RubyGem
def handle(_fun, dir, args)
raise "no :gemspec for rubygem" unless args[:gemspec]

define_clean_task dir, args
define_clean_task dir, args[:name]
define_build_task dir, args
define_release_task dir, args
define_release_task dir, args[:name]

define_gem_install_task dir, args
end
Expand All @@ -18,7 +18,7 @@ def define_build_task(dir, args)
spec_dir = File.dirname(gemspec)

desc "Build #{args[:gemspec]}"
task "//#{dir}:gem:build" => deps do
task "//#{dir}:gem:#{args[:name]}:build" => deps do
require 'rubygems/package'

file = Dir.chdir(spec_dir) do
Expand All @@ -30,16 +30,17 @@ def define_build_task(dir, args)
end
end

def define_clean_task(dir, _args)
def define_clean_task(dir, name)
desc 'Clean rubygem artifacts'
task "//#{dir}:gem:clean" do
task "//#{dir}:gem:#{name}:clean" do
Dir['build/*.gem'].each { |gem| rm(gem) }
end
end

def define_release_task(dir, _args)
def define_release_task(dir, name)
desc 'Build and release the ruby gem to Gemcutter'
task "//#{dir}:gem:release" => %W[//#{dir}:gem:clean //#{dir}:gem:build] do
task "//#{dir}:gem:#{name}:release" =>
%W[//#{dir}:gem:#{name}:clean //#{dir}:gem:#{name}:build] do
gem = Dir['build/*.gem'].first # safe as long as :clean does its job
sh "gem", "push", gem
end
Expand Down
104 changes: 38 additions & 66 deletions rb/build.desc
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
rubygem(
gemspec = "build/rb/selenium-webdriver.gemspec",
name = "webdriver",
deps = [
"//rb:chrome",
"//rb:common",
"//rb:devtools",
"//rb:bidi",
"//rb:edge",
"//rb:firefox",
"//rb:ie",
"//rb:safari",
]
)

rubydevtoolsgem(
gemspec = "build/rb/selenium-devtools.gemspec",
name = "devtools",
deps = [
"//rb:devtools",
]
)

rubydocs(
files = [
"lib/**/*.rb",
Expand Down Expand Up @@ -39,6 +48,7 @@ ruby_library(name = "common",
"lib/selenium-webdriver.rb",
"selenium-webdriver.gemspec",
"Gemfile",
"NOTICE",
"CHANGES",
"README.md"
],
Expand Down Expand Up @@ -80,7 +90,7 @@ ruby_test(name = "chrome",
],
deps = [
":chrome",
":devtools"
":bidi"
]
)

Expand All @@ -96,7 +106,7 @@ ruby_test(name = "remote-chrome",
],
deps = [
":chrome",
":devtools",
":bidi",
":remote"
]
)
Expand All @@ -120,7 +130,7 @@ ruby_test(name = "edge",
],
deps = [
":edge",
":devtools"
":bidi"
]
)

Expand All @@ -136,7 +146,7 @@ ruby_test(name = "remote-edge",
],
deps = [
":edge",
":devtools",
":bidi",
":remote"
]
)
Expand Down Expand Up @@ -172,7 +182,7 @@ ruby_test(name = "firefox-nightly",
],
deps = [
":firefox",
":devtools"
":bidi"
]
)

Expand Down Expand Up @@ -292,23 +302,6 @@ ruby_test(name = "remote-safari-preview",
]
)

ruby_library(name = "devtools",
srcs = [
"lib/selenium/webdriver/devtools/**/*.rb",
"lib/selenium/webdriver/devtools.rb",
],
deps = [
":common",
":cdp-v85",
":cdp-v86",
":cdp-v87",
":cdp-v88",
],
resources = [
{ "../javascript/cdp-support/mutation-listener.js": "rb/lib/selenium/webdriver/atoms/mutationListener.js" }
]
)

ruby_test(name = "unit",
srcs = [
"spec/unit/selenium/webdriver/**/*_spec.rb",
Expand All @@ -327,67 +320,46 @@ ruby_test(name = "unit",
]
)

ruby_class_call(name = "cdp-v85",
klass = "Selenium::WebDriver::Support::CDPClientGenerator",
require = "rb/lib/selenium/webdriver/support/cdp_client_generator",
output_dir = "rb/lib/selenium/webdriver/devtools/v85",
version = "v85",
ruby_library(name = "bidi",
srcs = [
"lib/selenium/webdriver/support/cdp",
"lib/selenium/webdriver/support/cdp/**/*",
"lib/selenium/webdriver/support/cdp_client_generator.rb"
"lib/selenium/webdriver/devtools/**/*.rb",
"lib/selenium/webdriver/devtools.rb",
],
resources = [
{ "//common/devtools/chromium/v85:browser_protocol": "rb/lib/selenium/webdriver/support/cdp/browser_protocol.json" },
{ "//common/devtools/chromium/v85:js_protocol": "rb/lib/selenium/webdriver/support/cdp/js_protocol.json" }
]
)

ruby_class_call(name = "cdp-v86",
klass = "Selenium::WebDriver::Support::CDPClientGenerator",
require = "rb/lib/selenium/webdriver/support/cdp_client_generator",
output_dir = "rb/lib/selenium/webdriver/devtools/v86",
version = "v86",
srcs = [
"lib/selenium/webdriver/support/cdp",
"lib/selenium/webdriver/support/cdp/**/*",
"lib/selenium/webdriver/support/cdp_client_generator.rb"
deps = [
":common",
":devtools"
],
resources = [
{ "//common/devtools/chromium/v86:browser_protocol": "rb/lib/selenium/webdriver/support/cdp/browser_protocol.json" },
{ "//common/devtools/chromium/v86:js_protocol": "rb/lib/selenium/webdriver/support/cdp/js_protocol.json" }
{ "../javascript/cdp-support/mutation-listener.js": "rb/lib/selenium/webdriver/atoms/mutationListener.js" }
]
)

ruby_class_call(name = "cdp-v87",
klass = "Selenium::WebDriver::Support::CDPClientGenerator",
require = "rb/lib/selenium/webdriver/support/cdp_client_generator",
output_dir = "rb/lib/selenium/webdriver/devtools/v87",
version = "v87",
ruby_library(name = "devtools",
srcs = [
"lib/selenium/webdriver/support/cdp",
"lib/selenium/webdriver/support/cdp/**/*",
"lib/selenium/webdriver/support/cdp_client_generator.rb"
"selenium-devtools.gemspec",
"lib/selenium/devtools/version.rb",
"NOTICE",
"CHANGES",
"README.md"
],
resources = [
{ "//common/devtools/chromium/v87:browser_protocol": "rb/lib/selenium/webdriver/support/cdp/browser_protocol.json" },
{ "//common/devtools/chromium/v87:js_protocol": "rb/lib/selenium/webdriver/support/cdp/js_protocol.json" }
]
deps = [
":cdp"
]
)

ruby_class_call(name = "cdp-v88",
ruby_class_call(name = "cdp",
klass = "Selenium::WebDriver::Support::CDPClientGenerator",
require = "rb/lib/selenium/webdriver/support/cdp_client_generator",
output_dir = "rb/lib/selenium/webdriver/devtools/v88",
version = "v88",
output_dir = "rb/lib/selenium/devtools",
version = "v89",
srcs = [
"lib/selenium/webdriver/support/cdp",
"lib/selenium/webdriver/support/cdp/**/*",
"lib/selenium/webdriver/support/cdp_client_generator.rb"
"lib/selenium/webdriver/support/cdp_client_generator.rb",
],
resources = [
{ "//common/devtools/chromium/v88:browser_protocol": "rb/lib/selenium/webdriver/support/cdp/browser_protocol.json" },
{ "//common/devtools/chromium/v88:js_protocol": "rb/lib/selenium/webdriver/support/cdp/js_protocol.json" }
{ "//common/devtools/chromium/v89:browser_protocol": "rb/lib/selenium/webdriver/support/cdp/browser_protocol.json" },
{ "//common/devtools/chromium/v89:js_protocol": "rb/lib/selenium/webdriver/support/cdp/js_protocol.json" }
]
)

Expand Down
8 changes: 7 additions & 1 deletion rb/lib/selenium/webdriver/support/cdp_client_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def call(output_dir:, version:, **)
js_protocol = JSON.parse(File.read(JS_PROTOCOL_PATH), symbolize_names: true)
browser_protocol[:domains].each(&method(:process_domain))
js_protocol[:domains].each(&method(:process_domain))
require_file
end

def process_domain(domain)
result = @template.result_with_hash(domain: domain, version: @version.upcase, h: self)
filename = File.join(@output_dir, "#{snake_case(domain[:domain])}.rb")
filename = File.join("#{@output_dir}/#{@version}", "#{snake_case(domain[:domain])}.rb")
File.write(filename, remove_empty_lines(result))
end

Expand Down Expand Up @@ -74,6 +75,11 @@ def kwargs(parameters)
def remove_empty_lines(string)
string.split("\n").reject { |l| l =~ /^\s+$/ }.join("\n")
end

def require_file
require_all = "Dir.glob('#{@version}/devtools/*', &method(:require))"
File.open("#{@output_dir}/#{@version}.rb", 'w') { |file| file.write(require_all) }
end
end
end
end
Expand Down

0 comments on commit e509e71

Please sign in to comment.