Skip to content

Commit f1b87b6

Browse files
committed
Start migrating CrazyFun to use bazel
1 parent 16cb1fd commit f1b87b6

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

Rakefile

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$LOAD_PATH.unshift File.expand_path(".")
44

55
require 'rake'
6+
require 'rake-tasks/bazel'
67
require 'rake-tasks/files'
78
require 'net/telnet'
89
require 'stringio'
@@ -71,14 +72,10 @@ crazy_fun = CrazyFun.new
7172
#
7273
# If crazy fun doesn't know how to handle a particular output type ("java_library"
7374
# in the example above) then it will throw an exception, stopping the build
74-
ExportMappings.new.add_all(crazy_fun)
75-
FolderMappings.new.add_all(crazy_fun)
7675
GccMappings.new.add_all(crazy_fun)
77-
JavascriptMappings.new.add_all(crazy_fun)
7876
JRubyMappings.new.add_all(crazy_fun)
7977
PythonMappings.new.add_all(crazy_fun)
8078
RakeMappings.new.add_all(crazy_fun)
81-
RenameMappings.new.add_all(crazy_fun)
8279
RubyMappings.new.add_all(crazy_fun)
8380
VisualStudioMappings.new.add_all(crazy_fun)
8481

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

@@ -97,15 +94,12 @@ end
9794
# from rake.
9895
crazy_fun.create_tasks(Dir["common/**/build.desc"])
9996
crazy_fun.create_tasks(Dir["cpp/**/build.desc"])
100-
crazy_fun.create_tasks(Dir["javascript/**/build.desc"])
101-
crazy_fun.create_tasks(Dir["py/**/build.desc"])
102-
crazy_fun.create_tasks(Dir["rake-tasks/**/build.desc"])
10397
crazy_fun.create_tasks(Dir["rb/**/build.desc"])
104-
crazy_fun.create_tasks(Dir["third_party/**/build.desc"])
10598

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

110104
# Spoof tasks to get CI working with buck
111105
task '//java/client/test/org/openqa/selenium/environment/webserver:webserver:uber' => [
@@ -553,7 +547,7 @@ namespace :node do
553547
task :build do
554548
sh "bazel build //javascript/node/selenium-webdriver"
555549
end
556-
550+
557551
task :'dry-run' => [
558552
"node:build",
559553
] do

rake-tasks/bazel.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'pp'
2+
require 'open3'
3+
require "rake/task"
4+
5+
module Bazel
6+
def self.execute(kind, target, &block)
7+
verbose = Rake::FileUtilsExt.verbose_flag
8+
outs = []
9+
10+
cmd = %w(bazel) + [kind, target]
11+
cmd_out = ""
12+
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
13+
Thread.new do
14+
while (line = stdouts.gets)
15+
if line.chomp =~ /\s+(bazel-bin\/.+)/
16+
outs << $1
17+
end
18+
cmd_out << line
19+
STDOUT.print line if verbose
20+
end
21+
end
22+
23+
stdin.close
24+
25+
raise "#{cmd.join(' ')} failed with exit code: #{wait.value.exitstatus}" unless wait.value.success?
26+
27+
block.call(cmd_out) if block
28+
29+
if outs.length
30+
puts "#{target} -> #{outs[0]}"
31+
end
32+
outs[0] if outs.length
33+
end
34+
end
35+
36+
class BazelTask < Rake::Task
37+
def needed?
38+
true
39+
end
40+
41+
def invoke(*args, &block)
42+
self.out = Bazel::execute(@verbose, "build", name, &block)
43+
44+
block.call(cmd_out) if block
45+
end
46+
end
47+
end
48+
49+
module Rake::DSL
50+
def bazel(*args, &block)
51+
Bazel::BazelTask.define_task(*args, &block)
52+
end
53+
end

rake-tasks/buck.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,3 @@ def buck(*args, &block)
213213
end
214214
end
215215
end
216-
217-
218-
rule /\/\/.*/ do |task|
219-
# Task is a FileTask, but that's not what we need. Instead, just delegate down to buck in all
220-
# cases where the rule was not created by CrazyFun. Rules created by the "rule" method will
221-
# be a FileTask, whereas those created by CrazyFun are normal rake Tasks.
222-
223-
buck_file = task.name[/\/\/([^:]+)/, 1] + "/BUCK"
224-
225-
if task.class == Rake::FileTask && !task.out && File.exists?(buck_file)
226-
task.enhance do
227-
Buck.buck_cmd('build', ['--deep', task.name])
228-
end
229-
230-
Buck::enhance_task(task)
231-
end
232-
end

0 commit comments

Comments
 (0)