Skip to content

Commit ac13692

Browse files
committed
Attempt to download the buck PEX if it's required.
1 parent 99e2fd0 commit ac13692

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.buckhash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e1ee24fba4ab6266a60d05582c3608d7

rake-tasks/buck.rb

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
require 'open3'
2+
require 'rake-tasks/checks'
23

34
module Buck
45

6+
def self.download
7+
@@buck_bin ||= (
8+
if File.exist?('.nobuckcheck') && present?('buck')
9+
return "buck"
10+
end
11+
12+
version = File.open('.buckversion').first.chomp
13+
cached_hash = File.open('.buckhash').first.chomp
14+
15+
out = File.expand_path("~/.crazyfun/buck/#{version}/buck.pex")
16+
out_hash = File.exist?(out) ? Digest::MD5.file(out).hexdigest : nil
17+
18+
if cached_hash == out_hash
19+
return "python #{out}"
20+
end
21+
22+
url = "https://github.com/SeleniumHQ/buck/releases/download/buck-release-#{version}/buck.pex"
23+
out_dir = File.dirname out
24+
FileUtils.mkdir_p(out_dir) unless File.exist?(out_dir)
25+
26+
# Cut-and-pasted from rake-tasks/crazy_fun/mappings/java.rb. We duplicate the code here so
27+
# we can delete that file and have this continue working, but once we delete that file, we
28+
# should also stop using this version of ant and just use the ant bundled with jruby.
29+
dir = 'third_party/java/ant'
30+
Dir[File.join(dir, '*.jar')].each { |jar| require jar }
31+
# we set ANT_HOME to avoid JRuby trying to load its own Ant
32+
ENV['ANT_HOME'] = dir
33+
require "ant"
34+
35+
ant.get('src' => url, 'dest' => out, 'verbose' => true)
36+
"python #{out}"
37+
)
38+
end
39+
540
def self.buck_cmd
641
@@buck_cmd ||= (
742
lambda { |command, target, &block|
8-
cmd = "buck #{command} #{target}"
43+
buck = Buck::download
44+
45+
cmd = "#{buck} #{command} #{target}"
46+
47+
puts cmd
48+
949
output = ''
1050
err = ''
1151
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|

0 commit comments

Comments
 (0)