Skip to content

Commit

Permalink
Attempt to download the buck PEX if it's required.
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Apr 25, 2016
1 parent 99e2fd0 commit ac13692
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions .buckhash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e1ee24fba4ab6266a60d05582c3608d7
42 changes: 41 additions & 1 deletion rake-tasks/buck.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
require 'open3'
require 'rake-tasks/checks'

module Buck

def self.download
@@buck_bin ||= (
if File.exist?('.nobuckcheck') && present?('buck')
return "buck"
end

version = File.open('.buckversion').first.chomp
cached_hash = File.open('.buckhash').first.chomp

out = File.expand_path("~/.crazyfun/buck/#{version}/buck.pex")
out_hash = File.exist?(out) ? Digest::MD5.file(out).hexdigest : nil

if cached_hash == out_hash
return "python #{out}"
end

url = "https://github.com/SeleniumHQ/buck/releases/download/buck-release-#{version}/buck.pex"
out_dir = File.dirname out
FileUtils.mkdir_p(out_dir) unless File.exist?(out_dir)

# Cut-and-pasted from rake-tasks/crazy_fun/mappings/java.rb. We duplicate the code here so
# we can delete that file and have this continue working, but once we delete that file, we
# should also stop using this version of ant and just use the ant bundled with jruby.
dir = 'third_party/java/ant'
Dir[File.join(dir, '*.jar')].each { |jar| require jar }
# we set ANT_HOME to avoid JRuby trying to load its own Ant
ENV['ANT_HOME'] = dir
require "ant"

ant.get('src' => url, 'dest' => out, 'verbose' => true)
"python #{out}"
)
end

def self.buck_cmd
@@buck_cmd ||= (
lambda { |command, target, &block|
cmd = "buck #{command} #{target}"
buck = Buck::download

cmd = "#{buck} #{command} #{target}"

puts cmd

output = ''
err = ''
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
Expand Down

0 comments on commit ac13692

Please sign in to comment.