forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gecko_sdks.rb
82 lines (66 loc) · 1.81 KB
/
gecko_sdks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'rake-tasks/downloader'
class GeckoSDKs
include ::Rake::DSL if defined?(::Rake::DSL)
def initialize
@sdks = []
yield self if block_given?
@sdks.each do |path, url|
define_rule(path, url)
end
end
def add(path, url)
@sdks << [path, url]
end
private
def define_rule(path, url)
file path do
mkdir_p path
next unless platform_matches?(path)
begin
sdk = Downloader.fetch url
destination = File.dirname path
unpack sdk, destination
# The directory was created - but for the move to replace it,
# it must be erased first.
rm_rf path
mv File.join(destination, "xulrunner-sdk"), path
rescue StandardError, Timeout::Error => ex
# ignore errors - dependant targets will fall back to prebuilts
$stderr.puts "Failed to download the Gecko 2 SDK - manually delete #{path} to retry."
next
ensure
rm_rf path if path && File.exist?(path)
end
end
end
def platform_matches?(path)
case path
when /linux/
Platform.linux?
when /mac/
Platform.mac?
when /win32/
Platform.windows?
else
raise "unknown platform #{path.inspect}"
end
end
def unpack(path, destination)
if Platform.windows?
require 'third_party/jruby/rubyzip.jar' if RUBY_PLATFORM == "java"
require 'zip/zip'
puts "Unzipping: #{File.basename path}"
Zip::ZipFile.open(path) do |zip|
zip.each do |entry|
to = File.join(destination, entry.name)
dirname = File.dirname(to)
FileUtils.mkdir_p dirname unless File.exist? dirname
zip.extract(entry, to)
end
end
else
puts "Unpacking: #{File.basename path}"
sh "tar", "jxf", path, "-C", destination
end
end
end