|
1 | 1 | require 'open3'
|
| 2 | +require 'rake-tasks/checks' |
2 | 3 |
|
3 | 4 | module Buck
|
4 | 5 |
|
| 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 | + |
5 | 40 | def self.buck_cmd
|
6 | 41 | @@buck_cmd ||= (
|
7 | 42 | lambda { |command, target, &block|
|
8 |
| - cmd = "buck #{command} #{target}" |
| 43 | + buck = Buck::download |
| 44 | + |
| 45 | + cmd = "#{buck} #{command} #{target}" |
| 46 | + |
| 47 | + puts cmd |
| 48 | + |
9 | 49 | output = ''
|
10 | 50 | err = ''
|
11 | 51 | Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
|
0 commit comments