forked from SeleniumHQ/selenium
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.rb
98 lines (84 loc) · 2.01 KB
/
files.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def find_file(file)
puts "Copying #{file}" if $DEBUG
if Rake::Task.task_defined?(file) && Rake::Task[file].out
# Grab the "out" of the task represented by this symbol
file = Rake::Task[file].out.to_s
end
if File.exist?(file)
file
elsif File.exist?("build/#{file}")
"build/#{file}"
else
fl = FileList.new(file).existing!
return fl unless fl.empty?
fl = FileList.new("build/#{file}").existing!
return fl unless fl.empty?
puts "Unable to locate #{file}"
exit -1
end
end
def copy_prebuilt(prebuilt, out)
dir = out.split('/')[0..-2].join('/')
if prebuilt.nil?
mkdir_p dir
File.open(out, 'w') { |f| f.write('') }
elsif File.directory? prebuilt
from = "#{prebuilt}/#{out}".sub(/\/build\//, '/')
if File.exist?(from)
puts "Falling back to copy of: #{from}"
mkdir_p dir
if File.directory? from
cp_r "#{from}/.", out
else
cp_r from, out
end
else
puts "Unable to locate prebuilt copy of #{out}"
end
elsif File.exist?(prebuilt)
puts "Falling back to copy of: #{prebuilt}"
mkdir_p dir
cp prebuilt, out
else
puts "Unable to locate prebuilt copy of #{out}"
end
end
def copy_to_prebuilt(src, prebuilt)
dest = "#{prebuilt}/#{src}".sub(/\/build\//, '/')
if File.directory?(src)
cp_r "#{src}/.", dest
else
if File.exist?(prebuilt)
cp src, prebuilt
else
cp src, dest
end
end
end
private
def copy_resource_(from, to)
return if from.nil?
if from.is_a? Hash
from.each do |key, value|
copy_single_resource_ key, "#{to}/#{value}"
end
elsif from.is_a? Array
from.each do |res|
copy_resource_ res, to
end
else
copy_single_resource_ from, to
end
end
def copy_single_resource_(from, to)
dir = to.sub(/(.*)\/.*?$/, '\1')
mkdir_p dir.to_s
from = find_file(from)
if from.is_a? FileList
from.each do |f|
cp_r f, to.to_s, remove_destination: true
end
else
cp_r from, to.to_s, remove_destination: true
end
end