Skip to content

Commit

Permalink
Start migrating CrazyFun to use bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 13, 2019
1 parent 16cb1fd commit f1b87b6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
20 changes: 7 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$LOAD_PATH.unshift File.expand_path(".")

require 'rake'
require 'rake-tasks/bazel'
require 'rake-tasks/files'
require 'net/telnet'
require 'stringio'
Expand Down Expand Up @@ -71,14 +72,10 @@ crazy_fun = CrazyFun.new
#
# 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
ExportMappings.new.add_all(crazy_fun)
FolderMappings.new.add_all(crazy_fun)
GccMappings.new.add_all(crazy_fun)
JavascriptMappings.new.add_all(crazy_fun)
JRubyMappings.new.add_all(crazy_fun)
PythonMappings.new.add_all(crazy_fun)
RakeMappings.new.add_all(crazy_fun)
RenameMappings.new.add_all(crazy_fun)
RubyMappings.new.add_all(crazy_fun)
VisualStudioMappings.new.add_all(crazy_fun)

Expand All @@ -88,7 +85,7 @@ VisualStudioMappings.new.add_all(crazy_fun)
# need to fall back to prebuilt binaries. The prebuilt binaries are stored in
# a directory structure identical to that used in the "build" folder, but
# rooted at one of the following locations:
["cpp/prebuilt", "javascript/firefox-driver/prebuilt"].each do |pre|
["cpp/prebuilt"].each do |pre|
crazy_fun.prebuilt_roots << pre
end

Expand All @@ -97,15 +94,12 @@ end
# from rake.
crazy_fun.create_tasks(Dir["common/**/build.desc"])
crazy_fun.create_tasks(Dir["cpp/**/build.desc"])
crazy_fun.create_tasks(Dir["javascript/**/build.desc"])
crazy_fun.create_tasks(Dir["py/**/build.desc"])
crazy_fun.create_tasks(Dir["rake-tasks/**/build.desc"])
crazy_fun.create_tasks(Dir["rb/**/build.desc"])
crazy_fun.create_tasks(Dir["third_party/**/build.desc"])

# Buck integration. Loaded after CrazyFun has initialized all the tasks it'll handle.
# This is because the buck integration creates a rule for "//.*"
require 'rake-tasks/buck'
# If it looks like a bazel target, build it with bazel
rule /\/\/.*/ do |task|
task.out = Bazel::execute("build", task.name)
end

# Spoof tasks to get CI working with buck
task '//java/client/test/org/openqa/selenium/environment/webserver:webserver:uber' => [
Expand Down Expand Up @@ -553,7 +547,7 @@ namespace :node do
task :build do
sh "bazel build //javascript/node/selenium-webdriver"
end

task :'dry-run' => [
"node:build",
] do
Expand Down
53 changes: 53 additions & 0 deletions rake-tasks/bazel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'pp'
require 'open3'
require "rake/task"

module Bazel
def self.execute(kind, target, &block)
verbose = Rake::FileUtilsExt.verbose_flag
outs = []

cmd = %w(bazel) + [kind, target]
cmd_out = ""
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
Thread.new do
while (line = stdouts.gets)
if line.chomp =~ /\s+(bazel-bin\/.+)/
outs << $1
end
cmd_out << line
STDOUT.print line if verbose
end
end

stdin.close

raise "#{cmd.join(' ')} failed with exit code: #{wait.value.exitstatus}" unless wait.value.success?

block.call(cmd_out) if block

if outs.length
puts "#{target} -> #{outs[0]}"
end
outs[0] if outs.length
end
end

class BazelTask < Rake::Task
def needed?
true
end

def invoke(*args, &block)
self.out = Bazel::execute(@verbose, "build", name, &block)

block.call(cmd_out) if block
end
end
end

module Rake::DSL
def bazel(*args, &block)
Bazel::BazelTask.define_task(*args, &block)
end
end
17 changes: 0 additions & 17 deletions rake-tasks/buck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,3 @@ def buck(*args, &block)
end
end
end


rule /\/\/.*/ do |task|
# Task is a FileTask, but that's not what we need. Instead, just delegate down to buck in all
# cases where the rule was not created by CrazyFun. Rules created by the "rule" method will
# be a FileTask, whereas those created by CrazyFun are normal rake Tasks.

buck_file = task.name[/\/\/([^:]+)/, 1] + "/BUCK"

if task.class == Rake::FileTask && !task.out && File.exists?(buck_file)
task.enhance do
Buck.buck_cmd('build', ['--deep', task.name])
end

Buck::enhance_task(task)
end
end

0 comments on commit f1b87b6

Please sign in to comment.