forked from solarwinds/appoptics-apm-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
230 lines (199 loc) · 7.11 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
#!/usr/bin/env rake
require 'rubygems'
require 'fileutils'
require 'open-uri'
require 'bundler/setup'
require 'rake/testtask'
require 'appoptics_apm/test'
Rake::TestTask.new do |t|
t.verbose = false
t.warning = false
t.ruby_opts = []
t.libs << 'test'
# Since we support so many libraries and frameworks, tests
# runs are segmented into gemfiles that have different
# sets and versions of gems (libraries and frameworks).
#
# Here we detect the Gemfile the tests are being run against
# and load the appropriate tests.
#
case AppOpticsAPM::Test.gemfile
when /delayed_job/
require 'delayed/tasks'
t.test_files = FileList['test/queues/delayed_job*_test.rb']
when /rails/
# Pre-load rails to get the major version number
require 'rails'
if Rails::VERSION::MAJOR == 5
t.test_files = FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_test.rb"] +
FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_api_test.rb"]
else
t.test_files = FileList["test/frameworks/rails#{Rails::VERSION::MAJOR}x_test.rb"]
end
when /frameworks/
t.test_files = FileList['test/frameworks/sinatra*_test.rb'] +
FileList['test/frameworks/padrino*_test.rb'] +
FileList['test/frameworks/grape*_test.rb']
when /libraries/
t.test_files = FileList['test/support/*_test.rb'] +
FileList['test/reporter/*_test.rb'] +
FileList['test/instrumentation/*_test.rb'] +
FileList['test/profiling/*_test.rb'] -
['test/instrumentation/twitter-cassandra_test.rb']
when /instrumentation_mocked/
# WebMock is interfering with other tests, so these have to run seperately
t.test_files = FileList['test/mocked/*_test.rb']
when /noop/
t.test_files = FileList['test/noop/*_test.rb']
when /unit/
t.test_files = FileList['test/unit/*_test.rb'] +
FileList['test/unit/*/*_test.rb']
end
if defined?(JRUBY_VERSION)
t.ruby_opts << ['-J-javaagent:/usr/local/tracelytics/tracelyticsagent.jar']
end
end
desc "Run all test suites defined by travis"
task "docker_tests" do
Dir.chdir('test/run_tests')
exec('docker-compose run --service-ports ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh test')
end
desc "Start docker container for testing and debugging"
task "docker" do
Dir.chdir('test/run_tests')
exec('docker-compose run --service-ports ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh bash')
end
desc "Fetch extension dependency files"
task :fetch_ext_deps do
swig_version = %x{swig -version} rescue ''
swig_version = swig_version.scan(/swig version 3.0.\d*/i)
if swig_version.empty?
$stderr.puts '== ERROR ================================================================='
$stderr.puts "Could not find required swig version 3.0.*, found #{swig_version.inspect}"
$stderr.puts 'Please install swig "~ 3.0.8" and try again.'
$stderr.puts '=========================================================================='
raise
end
# The c-lib version is different from the gem version
oboe_version = ENV['OBOE_VERSION'] || 'latest'
oboe_s3_dir = "https://s3-us-west-2.amazonaws.com/rc-files-t2/c-lib/#{oboe_version}"
ext_src_dir = File.expand_path('ext/oboe_metal/src')
# VERSION is used by extconf.rb to download the correct liboboe when installing the gem
remote_file = File.join(oboe_s3_dir, 'VERSION')
local_file = File.join(ext_src_dir, 'VERSION')
puts "fetching #{remote_file} to #{local_file}"
open(remote_file, 'rb') do |rf|
content = rf.read
File.open(local_file, 'wb') { |f| f.puts content }
puts "!!!!!!! C-Lib VERSION: #{content.strip} !!!!!!!!"
end
# oboe and bson header files
FileUtils.mkdir_p(File.join(ext_src_dir, 'bson'))
%w(oboe.h oboe.hpp oboe_debug.h oboe.i bson/bson.h bson/platform_hacks.h).each do |filename|
remote_file = File.join(oboe_s3_dir, 'include', filename)
local_file = File.join(ext_src_dir, filename)
puts "fetching #{remote_file} to #{local_file}"
open(remote_file, 'rb') do |rf|
content = rf.read
File.open(local_file, 'wb') { |f| f.puts content }
end
end
FileUtils.cd(ext_src_dir) do
system('swig -c++ -ruby -module oboe_metal oboe.i')
FileUtils.rm('oboe.i')
end
end
desc "Build the gem's c extension"
task :compile do
if !defined?(JRUBY_VERSION)
puts "== Building the c extension against Ruby #{RUBY_VERSION}"
pwd = Dir.pwd
ext_dir = File.expand_path('ext/oboe_metal')
final_so = File.expand_path('lib/oboe_metal.so')
so_file = File.expand_path('ext/oboe_metal/oboe_metal.so')
Dir.chdir ext_dir
ENV['APPOPTICS_FROM_S3'] = 'true'
cmd = [Gem.ruby, 'extconf.rb']
sh cmd.join(' ')
sh '/usr/bin/env make'
File.delete(final_so) if File.exist?(final_so)
if File.exist?(so_file)
FileUtils.mv(so_file, final_so)
Dir.chdir(pwd)
puts "== Extension built and moved to #{final_so}"
else
Dir.chdir(pwd)
puts '!! Extension failed to build (see above). Have the required binary and header files been fetched?'
puts '!! Try the tasks in this order: clean > fetch_ext_deps > compile.'
end
else
puts '== Nothing to do under JRuby.'
end
end
desc 'Clean up extension build files'
task :clean do
if !defined?(JRUBY_VERSION)
pwd = Dir.pwd
ext_dir = File.expand_path('ext/oboe_metal')
symlinks = [
File.expand_path('lib/oboe_metal.so'),
File.expand_path('ext/oboe_metal/lib/liboboe.so'),
File.expand_path('ext/oboe_metal/lib/liboboe-1.0.so.0')
]
symlinks.each do |symlink|
FileUtils.rm_f symlink
end
Dir.chdir ext_dir
sh '/usr/bin/env make clean' if File.exist? 'Makefile'
Dir.chdir pwd
else
puts '== Nothing to do under JRuby.'
end
end
desc 'Remove all built files and extensions'
task :distclean do
if !defined?(JRUBY_VERSION)
pwd = Dir.pwd
ext_dir = File.expand_path('ext/oboe_metal')
mkmf_log = File.expand_path('ext/oboe_metal/mkmf.log')
symlinks = [
File.expand_path('lib/oboe_metal.so'),
File.expand_path('ext/oboe_metal/lib/liboboe.so'),
File.expand_path('ext/oboe_metal/lib/liboboe-1.0.so.0')
]
if File.exist? mkmf_log
symlinks.each do |symlink|
FileUtils.rm_f symlink
end
Dir.chdir ext_dir
sh '/usr/bin/env make distclean' if File.exist? 'Makefile'
Dir.chdir pwd
else
puts 'Nothing to distclean. (nothing built yet?)'
end
else
puts '== Nothing to do under JRuby.'
end
end
desc "Rebuild the gem's c extension"
task :recompile => [:distclean, :compile]
task :environment do
ENV['APPOPTICS_GEM_VERBOSE'] = 'true'
Bundler.require(:default, :development)
AppOpticsAPM::Config[:tracing_mode] = :always
AppOpticsAPM::Test.load_extras
if AppOpticsAPM::Test.gemfile?(:delayed_job)
require 'delayed/tasks'
end
end
task :console => :environment do
ARGV.clear
if AppOpticsAPM::Test.gemfile?(:delayed_job)
require './test/servers/delayed_job'
end
Pry.start
end
# Used when testing Resque locally
task 'resque:setup' => :environment do
require 'resque/tasks'
end