1
1
$: << File . join ( __dir__ , 'lib' )
2
- require 'appmap/version'
3
- GEM_VERSION = AppMap ::VERSION
4
-
5
- # Make sure the local version is not behind the one on
6
- # rubygems.org (it's ok if they're the same).
7
- #
8
- # If it is behind, the fixture images won't get updated with the gem
9
- # built from the local source, so you'll wind up testing the rubygems
10
- # version instead.
11
- unless ENV [ 'SKIP_VERSION_CHECK' ]
12
- require 'json'
13
- require 'net/http'
14
- rubygems_version = JSON . parse ( Net ::HTTP . get ( URI . parse ( 'https://rubygems.org/api/v1/gems/appmap.json' ) ) ) [ 'version' ]
15
- if Gem ::Version . new ( GEM_VERSION ) < Gem ::Version . new ( rubygems_version )
16
- raise "#{ GEM_VERSION } < #{ rubygems_version } . Rebase to avoid build issues."
17
- end
18
- end
19
2
3
+ require 'rspec/core/rake_task'
20
4
require 'rake/testtask'
21
5
require 'rdoc/task'
22
-
23
- require 'open3'
24
6
require 'rake/extensiontask'
25
7
26
8
desc 'build the native extension'
27
9
Rake ::ExtensionTask . new ( "appmap" ) do |ext |
28
10
ext . lib_dir = "lib/appmap"
29
11
end
30
12
31
- RUBY_VERSIONS = %w[ 2.6 2.7 3.0 3.1 ] . select do |version |
32
- travis_ruby_version = ENV [ 'TRAVIS_RUBY_VERSION' ]
33
- next true unless travis_ruby_version
34
-
35
- if travis_ruby_version . index ( version ) == 0
36
- warn "Testing Ruby version #{ version } , since it matches TRAVIS_RUBY_VERSION=#{ travis_ruby_version } "
37
- next true
38
- end
39
-
40
- false
41
- end
42
- FIXTURE_APPS = [ :rack_users_app , :rails6_users_app , :rails5_users_app , :rails7_users_app => { :ruby_version => '>= 2.7' } ]
43
-
44
- def run_cmd ( *cmd )
45
- $stderr. puts "Running: #{ cmd } "
46
- out , s = Open3 . capture2e ( *cmd )
47
- unless s . success?
48
- $stderr. puts <<-END
49
- Command failed:
50
- <<< Output:
51
- #{ out }
52
- >>> End of output
53
- END
54
- raise 'Docker build failed'
55
- end
56
- end
57
-
58
- def build_base_image ( ruby_version )
59
- run_cmd "docker build" \
60
- " --build-arg RUBY_VERSION=#{ ruby_version } " \
61
- " --build-arg GEM_VERSION=#{ GEM_VERSION } " \
62
- " -t appmap:#{ GEM_VERSION } -f Dockerfile.appmap ."
63
- end
64
-
65
- def build_app_image ( app , ruby_version )
66
- Dir . chdir "spec/fixtures/#{ app } " do
67
- env = { "RUBY_VERSION" => ruby_version , "GEM_VERSION" => GEM_VERSION }
68
- run_cmd ( env ,
69
- "docker-compose build" \
70
- " --build-arg RUBY_VERSION=#{ ruby_version } " \
71
- " --build-arg GEM_VERSION=#{ GEM_VERSION } " )
72
- end
73
- end
74
-
75
13
desc 'Install non-Ruby dependencies'
76
14
task :install do
77
15
system 'yarn install' or raise 'yarn install failed'
78
16
end
79
17
80
- namespace :build do
81
- namespace :base do
82
- RUBY_VERSIONS . each do |ruby_version |
83
- desc ruby_version
84
- task ruby_version do
85
- run_system = -> ( cmd ) { system ( cmd ) or raise "Command failed: #{ cmd } " }
86
-
87
- run_system . call 'mkdir -p pkg'
88
- run_system . call "gem build appmap.gemspec --output pkg/appmap-#{ GEM_VERSION } .gem"
89
- build_base_image ( ruby_version )
90
- end . tap do |t |
91
- desc "Build all images"
92
- task all : t
93
- end
94
- end
95
- end
96
-
97
- namespace :fixtures do
98
- RUBY_VERSIONS . each do |ruby_version |
99
- namespace ruby_version do
100
- desc "build:fixtures:#{ ruby_version } "
101
- FIXTURE_APPS . each do |app_spec |
102
- app = if app_spec . instance_of? ( Hash )
103
- app_spec = app_spec . flatten
104
- version_rqt = Gem ::Requirement . create ( app_spec [ 1 ] [ :ruby_version ] )
105
- next unless version_rqt =~ ( Gem ::Version . new ( ruby_version ) )
106
- app = app_spec [ 0 ]
107
- else
108
- app = app_spec
109
- end . to_s
110
-
111
-
112
- desc app
113
- task app => [ "base:#{ ruby_version } " ] do
114
- build_app_image ( app , ruby_version )
115
- end . tap do |t |
116
- desc "Build all fixture images for #{ ruby_version } "
117
- task all : t
118
- end
119
- end
120
- end
121
-
122
- desc "Build all fixture images"
123
- task all : [ "#{ ruby_version } :all" ]
124
- end
125
- end
126
-
127
- task all : [ "fixtures:all" ]
128
- end
129
-
130
- def run_specs ( ruby_version , task_args )
131
- require 'rspec/core/rake_task'
132
- require 'climate_control'
133
- # Define an rspec rake task for the specified Ruby version. It's hidden (i.e. doesn't have a
134
- # description), because it's not intended to be invoked directly
135
- RSpec ::Core ::RakeTask . new ( "rspec_#{ ruby_version } " , [ :specs ] ) do |task , args |
136
- task . exclude_pattern = 'spec/fixtures/**/*_spec.rb'
137
- task . rspec_opts = '-f doc'
138
- if args . count > 0
139
- # There doesn't appear to be a value for +pattern+ that will
140
- # cause it to be ignored. Setting it to '' or +nil+ causes an
141
- # empty argument to get passed to rspec, which confuses it.
142
- task . pattern = 'never match this'
143
- task . rspec_opts += " " + args . to_a . join ( ' ' )
144
- end
145
- end
146
-
147
- # Set up the environment, then execute the rspec task we
148
- # created above.
149
- ClimateControl . modify ( RUBY_VERSION : ruby_version ) do
150
- Rake ::Task [ "rspec_#{ ruby_version } " ] . execute ( task_args )
151
- end
152
- end
153
-
154
- namespace :spec do
155
- RUBY_VERSIONS . each do |ruby_version |
156
- desc ruby_version
157
- task ruby_version , [ :specs ] => [ "install" , "compile" , "build:fixtures:#{ ruby_version } :all" ] do |_ , task_args |
158
- run_specs ( ruby_version , task_args )
159
- end . tap do |t |
160
- desc "Run all specs"
161
- task :all , [ :specs ] => t
162
- end
18
+ RSpec ::Core ::RakeTask . new spec : %i[ compile install ] do |task , args |
19
+ task . exclude_pattern = 'spec/fixtures/**/*_spec.rb'
20
+ task . rspec_opts = '-f doc'
21
+ if args . count > 0
22
+ # There doesn't appear to be a value for +pattern+ that will
23
+ # cause it to be ignored. Setting it to '' or +nil+ causes an
24
+ # empty argument to get passed to rspec, which confuses it.
25
+ task . pattern = 'never match this'
26
+ task . rspec_opts += [ nil , *args ] . join ( ' ' )
163
27
end
164
28
end
165
29
@@ -169,14 +33,12 @@ Rake::RDocTask.new do |rd|
169
33
rd . title = 'AppMap'
170
34
end
171
35
172
- Rake ::TestTask . new ( minitest : ' compile' ) do |t |
36
+ Rake ::TestTask . new ( minitest : : compile) do |t |
173
37
t . libs << 'test'
174
38
t . libs << 'lib'
175
39
t . test_files = FileList [ 'test/*_test.rb' ]
176
40
end
177
41
178
- task spec : %i[ spec:all ]
179
-
180
- task test : %i[ spec:all minitest ]
42
+ task test : %i[ spec minitest ]
181
43
182
44
task default : :test
0 commit comments