forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
253 lines (215 loc) · 7.25 KB
/
Rakefile
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
require 'rubygems'
require 'rake'
require 'rake/testtask'
Rake.application.options.trace = true
namespace :test do
desc "Runs EVM vmdb specs"
task :vmdb do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup', 'spec:evm:backend'].each { |t| Rake::Task[t].invoke }
end
desc "Run EVM migration specs"
task :migrations do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup_migrations', 'spec:evm:migrations:up', 'evm:test:complete_migrations:up', 'spec:evm:migrations:down', 'evm:test:complete_migrations:down'].each { |t| Rake::Task[t].invoke }
end
desc "Run EVM replication specs"
task :replication do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup_replication', 'spec:evm:replication'].each { |t| Rake::Task[t].invoke }
end
desc "Run EVM automation specs"
task :automation do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup', 'spec:evm:automation'].each { |t| Rake::Task[t].invoke }
end
desc "Run metric_fu metrics"
task :run_metrics do
ENV['RAILS_ENV'] = 'metric_fu'
['test:load_vmdb_tasks', 'evm:test:metrics'].each { |t| Rake::Task[t].invoke }
end
desc "Run brakeman static analysis"
task :brakeman do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'brakeman:run'].each { |t| Rake::Task[t].invoke }
end
desc "Runs EVM lib tests in a single block"
task :lib do
['test:load_lib_tasks', :spec, :test].each { |t| Rake::Task[t].invoke }
end
task :load_vmdb_tasks do
load_tasks('vmdb')
end
task :load_lib_tasks do
load_tasks('lib')
end
def load_tasks(dir)
update_bundle(dir)
load_rakefile(dir)
end
def load_rakefile(dir)
Dir.chdir(File.join(File.dirname(__FILE__), dir))
$:.push(File.expand_path(File.join(__FILE__, dir)))
load 'Rakefile'
end
def update_bundle(dir)
Dir.chdir(File.join(File.dirname(__FILE__), dir))
system('bundle check')
system('bundle update') if $? != 0
end
end
namespace :build do
desc "Upload the build files to an imagefactory instance"
task :upload do
raise "must set ENV['SCP_USER_HOST'], such as root@your_host" if ENV['SCP_USER_HOST'].nil?
build_dir = File.join(File.dirname(__FILE__), 'build')
`ssh #{ENV['SCP_USER_HOST']} "rm -rf ~/manageiq"`
`scp -qr #{build_dir} #{ENV['SCP_USER_HOST']}:~/manageiq`
end
namespace :shared_objects do
desc "Clean built shared objects and artifacts."
task :clean do
require 'fileutils'
require 'pathname'
base = Pathname.new(File.dirname(__FILE__)).freeze
artifacts_dirs = %w(
lib/disk/modules/MiqBlockDevOps
lib/disk/modules/MiqLargeFileLinux.d
lib/SlpLib/SlpLib_raw/
lib/NetappManageabilityAPI/NmaCore/NmaCore_raw
lib/VixDiskLib/VixDiskLib_raw/v1_2/
lib/VixDiskLib/VixDiskLib_raw/v5_0/
lib/VixDiskLib/VixDiskLib_raw/v5_1/
)
artifacts_dirs.each do |dir|
dir = base.join(dir)
patterns = %w(*.log *.o *.out Makefile)
patterns.each do |p|
Dir.glob(dir.join(p)) do |f|
puts "** Removing #{f}"
FileUtils.rm_f(f)
end
end
end
so_dirs = %w(
lib/disk/modules/
lib/SlpLib/lib/
lib/NetappManageabilityAPI/NmaCore/
lib/VixDiskLib/lib/
)
so_dirs.each do |dir|
dir = base.join(dir)
patterns = %w(**/*.so **/*.bundle)
patterns.each do |p|
Dir.glob(dir.join(p)) do |f|
puts "** Removing #{f}"
FileUtils.rm_f(f)
end
end
end
end
end
desc "Build shared objects"
task :shared_objects do
def build_shared_objects(so_name, make_dir, install_dir, extconf_params = nil)
if File.exist?(install_dir.join(so_name))
puts "** Skipping build of #{so_name} since it is already built."
return
end
puts "** Building #{so_name}..."
Dir.chdir(make_dir) do
`ruby extconf.rb #{extconf_params}`
`make`
FileUtils.mkdir_p(install_dir)
FileUtils.mv(so_name, install_dir)
end
puts "** Building #{so_name}...complete"
end
require 'fileutils'
require 'pathname'
require 'platform'
base = Pathname.new(File.dirname(__FILE__)).freeze
platform = RUBY_PLATFORM.match(/(.+?)[0-9\.]*$/)[1] # => "x86_64-linux" or "x86_64-darwin"
arch = platform.split("-").first # => "x86_64"
#
# MiqBlockDevOps
#
if Platform::IMPL == :linux && arch == "x86_64"
build_shared_objects(
"MiqBlockDevOps.so",
base.join("lib/disk/modules/MiqBlockDevOps/"),
base.join("lib/disk/modules/")
)
else
puts "** Skipping build of MiqBlockDevOps.so since it is only built on x86_64-linux."
end
#
# MiqLargeFileLinux
#
if Platform::IMPL == :linux && arch == "x86"
build_shared_objects(
"MiqLargeFileLinux.so",
base.join("lib/disk/modules/MiqLargeFileLinux.d/"),
base.join("lib/disk/modules/ruby#{RUBY_VERSION}/")
)
else
puts "** Skipping build of MiqLargeFileLinux.so since it is only built on x86-linux."
end
#
# SlpLib
#
if Platform::IMPL == :macosx
include_file = "/usr/local/include/slp.h"
lib_file = "/usr/local/lib/libslp.dylib"
so_name = "SlpLib_raw.bundle"
else # RHEL, Fedora
include_file = "/usr/include/slp.h"
lib_file = "/usr/lib64/libslp.so"
so_name = "SlpLib_raw.so"
end
if File.exist?(include_file) && File.exist?(lib_file)
build_shared_objects(
so_name,
base.join("lib/SlpLib/SlpLib_raw/"),
base.join("lib/SlpLib/lib/#{platform}/")
)
else
puts "** Skipping build of #{so_name} due to missing header or library."
end
#
# NmaCore
#
if Dir.exist?("/usr/include/netapp") && Dir.exist?("/usr/lib64/netapp")
build_shared_objects(
"NmaCore_raw.so",
base.join("lib/NetappManageabilityAPI/NmaCore/NmaCore_raw/"),
base.join("lib/NetappManageabilityAPI/NmaCore/#{platform}/ruby#{RUBY_VERSION}/")
)
else
puts "** Skipping build of NmaCore_raw.so due to missing header or library."
end
#
# VixDiskLib
#
{ # VDL version => library version
"5.1" => "5.1.0",
"5.0" => "5.0.0",
"1.2" => "1.1.2"
}.each do |vdl_version, lib_version|
vdl_version_underscore = vdl_version.gsub(".", "_")
include_dir = Pathname.new(ENV["VDL_#{vdl_version_underscore}_INCLUDE"] || "/usr/lib/vmware-vix-disklib/include")
lib_dir = Pathname.new(ENV["VDL_#{vdl_version_underscore}_LIB"] || "/usr/lib/vmware-vix-disklib/lib64")
so_name = "VixDiskLib_raw.#{vdl_version}.so"
if Dir.exist?(include_dir) && Dir.exist?(lib_dir) && File.exist?(lib_dir.join("libvixDiskLib.so.#{lib_version}"))
build_shared_objects(
so_name,
base.join("lib/VixDiskLib/VixDiskLib_raw/v#{vdl_version_underscore}/"),
base.join("lib/VixDiskLib/lib/#{platform}/ruby#{RUBY_VERSION}/"),
"--with-vixDiskLib-include #{include_dir} --with-vixDiskLib-lib #{lib_dir}"
)
else
puts "** Skipping build of #{so_name} due to missing header or library."
end
end
end
end