Skip to content

Commit

Permalink
JariBakken: Begin work on RubyMappings for crazyfun
Browse files Browse the repository at this point in the history
r8998
  • Loading branch information
jarib committed May 26, 2010
1 parent fa7c864 commit b76f709
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 24 deletions.
19 changes: 10 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ ide_version = "1.0.7-SNAPSHOT"
# First off, create a new CrazyFun object.
crazy_fun = CrazyFun.new

# Secondly, we add the handlers, which are responsible for turning a build
# Secondly, we add the handlers, which are responsible for turning a build
# rule into a (series of) rake tasks. For example if we're looking at a file
# in subdirectory "subdir" contains the line:
#
# java_library(:name => "example", :srcs => ["foo.java"])
#
# we would generate a rake target of "//subdir:example" which would generate
# a Java JAR at "build/subdir/example.jar".
#
# a Java JAR at "build/subdir/example.jar".
#
# If crazy fun doesn't know how to handle a particular output type ("java_library"
# in the example above) then it will throw an exception, stopping the build
JavaMappings.new.add_all(crazy_fun)
JavascriptMappings.new.add_all(crazy_fun)
MozillaMappings.new.add_all(crazy_fun)
RakeMappings.new.add_all(crazy_fun)
RubyMappings.new.add_all(crazy_fun)

# Not every platform supports building every binary needed, so we sometimes
# need to fall back to prebuilt binaries. The prebuilt binaries are stored in
Expand All @@ -59,7 +60,7 @@ end

# Finally, find every file named "build.desc" in the project, and generate
# rake tasks from them. These tasks are normal rake tasks, and can be invoked
# from rake.
# from rake.
crazy_fun.create_tasks(Dir["**/build.desc"])

# Notice that because we're using rake, anything you can do in a normal rake
Expand Down Expand Up @@ -161,7 +162,7 @@ dll(:name => "firefox_dll",
:src => [ "common/src/cpp/webdriver-interactions/**/*", "jobbie/src/cpp/webdriver-firefox/**/*" ],
:solution => "WebDriver.sln",
:out => "Win32/Release/webdriver-firefox.dll",
:deps => [
:deps => [
"//firefox:native_events_xpt",
],
:prebuilt => "firefox/prebuilt")
Expand Down Expand Up @@ -191,12 +192,12 @@ dll(:name => "libwebdriver_firefox_so",
:prebuilt => "firefox/prebuilt",
:out => "linux/Release/libwebdriver-firefox.so")

# There is no official 64 bit gecko SDK. Fall back to trying to use the one on
# system, but be ready for this to fail. I have a Ubuntu machine, so that's
# There is no official 64 bit gecko SDK. Fall back to trying to use the one on
# system, but be ready for this to fail. I have a Ubuntu machine, so that's
# what I'm basing this on. I understand that's a Bad Idea

gecko_devels = FileList.new("/usr/lib/xulrunner-devel-1.9.*/sdk")
local_gecko = gecko_devels.empty? ? "" : gecko_devels.to_a[0] + "/"
local_gecko = gecko_devels.empty? ? "" : gecko_devels.to_a[0] + "/"

dll(:name => "libwebdriver_firefox_so64",
:src => FileList.new('common/src/cpp/webdriver-interactions/*_linux.cpp') + FileList.new('firefox/src/cpp/webdriver-firefox/native_events.cpp'),
Expand Down Expand Up @@ -436,7 +437,7 @@ end
desc 'Install prerequisites for the build. You may need to run this as root or Administrator'
task :setup do
sh "gem install Antwrap yard"

if python?
sh "easy_install virtualenv"
end
Expand Down
22 changes: 17 additions & 5 deletions firefox/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ java_test(name = "test",
"//remote/client:test"
])

ruby_test(
srcs = [
"common/test/rb/spec/**/*_spec.rb",
"firefox/test/rb/spec/**/*_spec.rb"
],
include = [
"firefox/src/rb/lib",
"remote/client/src/rb/lib"
],
driver_name = "firefox"
)

mozilla_xpt(name = "native_events_xpt",
srcs = [ "src/cpp/webdriver-firefox/nsINativeEvents.idl" ])

Expand All @@ -37,31 +49,31 @@ mozilla_xpi(name = "webdriver",
":command_processor_xpt",
":response_handler_xpt"
],
resources = [
resources = [
{ ":firefox_dll" : "platform/WINNT_x86-msvc/components/webdriver-firefox.dll" },
{ ":libwebdriver_firefox_so" : "platform/Linux_x86-gcc3/components/libwebdriver-firefox.so" },
{ ":libwebdriver_firefox_so64" : "platform/Linux_x86_64-gcc3/components/libwebdriver-firefox.so" }
],
chrome = "src/extension/chrome.manifest",
install = "src/extension/install.rdf")

# Temporary rules while we migrate
rake_task(name = "firefox_dll",
task_name = "firefox_dll",
out = "build/Win32/Release/webdriver-firefox.dll")

rake_task(name = "libwebdriver_firefox_so",
task_name = "libwebdriver_firefox_so",
out = "build/linux/Release/libwebdriver-firefox.so")

rake_task(name = "libwebdriver_firefox_so64",
task_name = "libwebdriver_firefox_so64",
out = "build/linux64/Release/libwebdriver-firefox.so")

rake_task(name = "libnoblur_so_64",
task_name = "libnoblur_so_64",
out = "build/linux64/Release/x_ignore_nofocus.so")

rake_task(name = "libnoblur_so",
task_name = "libnoblur_so",
out = "build/linux/Release/x_ignore_nofocus.so")
2 changes: 1 addition & 1 deletion go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

java -jar third_party/jruby/jruby-complete-1.5.0.RC2.jar -r third_party/jruby/antwrap.jar -S rake $*
java -Djruby.launch.inproc=false -jar third_party/jruby/jruby-complete-1.5.0.RC2.jar -r third_party/jruby/antwrap.jar -S rake $*
2 changes: 1 addition & 1 deletion go.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
java -jar third_party\jruby\jruby-complete-1.5.0.RC2.jar -r third_party\jruby\antwrap.jar -S rake %*
java -Djruby.launch.inproc=false -jar third_party\jruby\jruby-complete-1.5.0.RC2.jar -r third_party\jruby\antwrap.jar -S rake %*
118 changes: 110 additions & 8 deletions rake-tasks/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,113 @@
class RubyMappings

def add_all(fun)
fun.add_mapping "ruby_test", CheckArgs.new
fun.add_mapping "ruby_test", AddDefaults.new
fun.add_mapping "ruby_test", JRubyTest.new # this probably needs //common:test as a dependency
fun.add_mapping "ruby_test", MRITest.new

# TODO: fun.add_mapping("rubygem", RubyGem.new)
# TODO: fun.add_mapping("rubydocs", RubyDocs.new)
end

class RubyTasks < Tasks
def task_name(dir, name)
super dir, "ruby:#{name}"
end
end

class CheckArgs
def handle(fun, dir, args)
raise "no :srcs specified for #{dir}" unless args.has_key? :srcs
raise "no :driver_name specified for #{dir}" unless args.has_key? :driver_name
end
end

class AddDefaults
def handle(fun, dir, args)
args[:include] = [".", "common/src/rb/lib", "common/test/rb/lib"] + Array(args[:include])
args[:command] = args[:command] || "spec"
args[:require] = Array(args[:require])

# move?
args[:srcs] = args[:srcs].map { |str| Dir[str] }.flatten
end
end

class JRubyTest < RubyTasks
def handle(fun, dir, args)
require = ["third_party/jruby/json-jruby.jar"] + Array(args[:require])

desc "Run ruby tests for #{dir} (jruby)"
task task_name(dir, "test:jruby") do
ENV['WD_SPEC_DRIVER'] = args[:driver_name] # TODO: get rid of ENV

jruby :include => args[:include],
:require => require,
:command => args[:command],
:files => args[:srcs]
end
end
end

class MRITest < RubyTasks
def handle(fun, dir, args)
desc "Run ruby tests for #{dir} (mri)"
task task_name(dir, "test:mri") do
ENV['WD_SPEC_DRIVER'] = args[:driver_name] # TODO: get rid of this

ruby :include => args[:include],
:require => args[:require],
:command => args[:command],
:files => args[:srcs]
end
end
end

end # RubyMappings

class RubyRunner
def self.run(impl, opts)
cmd = []

case impl.to_sym
when :jruby
cmd << "java"
cmd << "-Djava.awt.headless=true" if opts[:headless]
cmd << "-jar" << "third_party/jruby/jruby-complete-1.5.0.RC2.jar"
else
cmd << impl.to_s
end

if opts.has_key? :include
cmd << "-I"
cmd << Array(opts[:include]).join(File::PATH_SEPARATOR)
end

Array(opts[:require]).each do |f|
cmd << "-r#{f}"
end

cmd << "-S" << opts[:command] if opts.has_key? :command
cmd += Array(opts[:files]) if opts.has_key? :files

sh(*cmd)
end
end

def jruby(opts)
RubyRunner.run :jruby, opts
end


def ruby(opts)
# if we're running on jruby, -Djruby.launch.inproc=false needs to be set for this to work.
# otherwise sh("ruby", ...) will reuse the current JVM
RubyRunner.run :ruby, opts
end



task :test_remote_rb => [:test_common, :remote_server] do
ENV['WD_SPEC_DRIVER'] = 'remote'
jruby :include => [".", "common/src/rb/lib", "remote/client/src/rb/lib", "common/test/rb/lib"],
Expand All @@ -23,14 +133,6 @@
:files => Dir['common/test/rb/spec/**/*spec.rb']
end

task :test_firefox_rb => :test_common do
ENV['WD_SPEC_DRIVER'] = 'firefox'
jruby :include => [".", "common/src/rb/lib", "firefox/src/rb/lib", "remote/client/src/rb/lib", "common/test/rb/lib"],
:require => ["third_party/jruby/json-jruby.jar"],
:command => '-S spec',
:files => Dir['{common,firefox}/test/rb/spec/**/*spec.rb']
end

#
# remote
#
Expand Down

0 comments on commit b76f709

Please sign in to comment.