29
29
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
30
# POSSIBILITY OF SUCH DAMAGE.
31
31
32
-
33
32
# Load config if present
34
33
35
34
config_path_ = ::File . expand_path ( 'rakefile_config.rb' , ::File . dirname ( __FILE__ ) )
36
- load ( config_path_ ) if ::File . exists? ( config_path_ )
37
- RAKEFILE_CONFIG = { } unless defined? ( ::RAKEFILE_CONFIG )
38
-
35
+ load ( config_path_ ) if ::File . exist? ( config_path_ )
36
+ RAKEFILE_CONFIG = { } . freeze unless defined? ( ::RAKEFILE_CONFIG )
39
37
40
38
# Gemspec
41
39
@@ -44,7 +42,6 @@ gemspec_ = eval(::File.read(::Dir.glob('*.gemspec').first))
44
42
release_gemspec_ = eval ( ::File . read ( ::Dir . glob ( '*.gemspec' ) . first ) )
45
43
release_gemspec_ . version = gemspec_ . version . to_s . sub ( /\. nonrelease$/ , '' )
46
44
47
-
48
45
# Platform info
49
46
50
47
dlext_ = ::RbConfig ::CONFIG [ 'DLEXT' ]
@@ -74,14 +71,12 @@ platform_suffix_ =
74
71
else 'unknown'
75
72
end
76
73
77
-
78
74
# Directories
79
75
80
76
doc_directory_ = ::RAKEFILE_CONFIG [ :doc_directory ] || 'doc'
81
77
pkg_directory_ = ::RAKEFILE_CONFIG [ :pkg_directory ] || 'pkg'
82
78
tmp_directory_ = ::RAKEFILE_CONFIG [ :tmp_directory ] || 'tmp'
83
79
84
-
85
80
# Build tasks
86
81
87
82
internal_ext_info_ = gemspec_ . extensions . map do |extconf_path_ |
@@ -95,7 +90,7 @@ internal_ext_info_ = gemspec_.extensions.map do |extconf_path_|
95
90
obj_glob : "#{ source_dir_ } /*.{o,dSYM}" ,
96
91
suffix_makefile_path : "#{ source_dir_ } /Makefile_#{ platform_suffix_ } " ,
97
92
built_lib_path : "#{ source_dir_ } /#{ name_ } .#{ dlext_ } " ,
98
- staged_lib_path : "#{ source_dir_ } /#{ name_ } _#{ platform_suffix_ } .#{ dlext_ } " ,
93
+ staged_lib_path : "#{ source_dir_ } /#{ name_ } _#{ platform_suffix_ } .#{ dlext_ } "
99
94
}
100
95
end
101
96
internal_ext_info_ = [ ] if platform_ == :jruby
@@ -118,51 +113,60 @@ internal_ext_info_.each do |info_|
118
113
end
119
114
end
120
115
121
- task build_ext : internal_ext_info_ . map { |info_ | info_ [ :staged_lib_path ] } do
116
+ task build_ext : internal_ext_info_ . map { |info_ | info_ [ :staged_lib_path ] } do
122
117
internal_ext_info_ . each do |info_ |
123
118
target_prefix_ = target_name_ = nil
124
119
::Dir . chdir ( info_ [ :source_dir ] ) do
125
120
ruby 'extconf.rb'
126
121
::File . open ( 'Makefile' ) do |file_ |
127
122
file_ . each do |line_ |
128
123
if line_ =~ /^target_prefix\s *=\s *(\S +)\s /
129
- target_prefix_ = $1
124
+ target_prefix_ = Regexp . last_match ( 1 )
130
125
elsif line_ =~ /^TARGET\s *=\s *(\S +)\s /
131
- target_name_ = $1
126
+ target_name_ = Regexp . last_match ( 1 )
132
127
end
133
128
end
134
129
end
135
130
rm 'Makefile'
136
131
end
137
- raise "Could not find target_prefix in makefile for #{ info_ [ :name ] } " unless target_prefix_
138
- raise "Could not find TARGET in makefile for #{ info_ [ :name ] } " unless target_name_
132
+ unless target_prefix_
133
+ raise "Could not find target_prefix in makefile for #{ info_ [ :name ] } "
134
+ end
135
+ unless target_name_
136
+ raise "Could not find TARGET in makefile for #{ info_ [ :name ] } "
137
+ end
138
+
139
139
cp info_ [ :staged_lib_path ] , "lib#{ target_prefix_ } /#{ target_name_ } .#{ dlext_ } "
140
140
end
141
141
end
142
142
143
-
144
143
# Clean task
145
144
146
145
clean_files_ = [ doc_directory_ , pkg_directory_ , tmp_directory_ ] +
147
- ::Dir . glob ( 'ext/**/Makefile*' ) +
148
- ::Dir . glob ( 'ext/**/*.{o,class,log,dSYM}' ) +
149
- ::Dir . glob ( " **/*.{bundle,so,dll,rbc,jar}" ) +
150
- ::Dir . glob ( '**/.rbx' ) +
151
- ( ::RAKEFILE_CONFIG [ :extra_clean_files ] || [ ] )
146
+ ::Dir . glob ( 'ext/**/Makefile*' ) +
147
+ ::Dir . glob ( 'ext/**/*.{o,class,log,dSYM}' ) +
148
+ ::Dir . glob ( ' **/*.{bundle,so,dll,rbc,jar}' ) +
149
+ ::Dir . glob ( '**/.rbx' ) +
150
+ ( ::RAKEFILE_CONFIG [ :extra_clean_files ] || [ ] )
152
151
task :clean do
153
- clean_files_ . each { |path_ | rm_rf path_ }
152
+ clean_files_ . each { |path_ | rm_rf path_ }
154
153
end
155
154
156
-
157
155
# RDoc tasks
158
156
159
157
task build_rdoc : "#{ doc_directory_ } /index.html"
160
- all_rdoc_files_ = ::Dir . glob ( " lib/**/*.rb" ) + gemspec_ . extra_rdoc_files
158
+ all_rdoc_files_ = ::Dir . glob ( ' lib/**/*.rb' ) + gemspec_ . extra_rdoc_files
161
159
main_rdoc_file_ = ::RAKEFILE_CONFIG [ :main_rdoc_file ]
162
- main_rdoc_file_ = 'README.rdoc' if !main_rdoc_file_ && ::File . readable? ( 'README.rdoc' )
163
- main_rdoc_file_ = ::Dir . glob ( "*.rdoc" ) . first unless main_rdoc_file_
160
+ if !main_rdoc_file_ && ::File . readable? ( 'README.rdoc' )
161
+ main_rdoc_file_ = 'README.rdoc'
162
+ end
163
+ main_rdoc_file_ ||= ::Dir . glob ( '*.rdoc' ) . first
164
164
file "#{ doc_directory_ } /index.html" => all_rdoc_files_ do
165
- rm_r doc_directory_ rescue nil
165
+ begin
166
+ rm_r doc_directory_
167
+ rescue StandardError
168
+ nil
169
+ end
166
170
args_ = [ ]
167
171
args_ << '-o' << doc_directory_
168
172
args_ << '--main' << main_rdoc_file_ if main_rdoc_file_
@@ -174,7 +178,6 @@ file "#{doc_directory_}/index.html" => all_rdoc_files_ do
174
178
::RDoc ::RDoc . new . document ( args_ + all_rdoc_files_ )
175
179
end
176
180
177
-
178
181
# Gem release tasks
179
182
180
183
task :build_other
@@ -197,23 +200,21 @@ task release_gem: :build_release do
197
200
end
198
201
end
199
202
200
-
201
203
# Unit test task
202
204
203
- task test : [ : build_ext, : build_other] do
204
- $: . unshift ( ::File . expand_path ( 'lib' , ::File . dirname ( __FILE__ ) ) )
205
- if ::ENV [ 'TESTCASE' ]
206
- test_files_ = ::Dir . glob ( "test/#{ ::ENV [ 'TESTCASE' ] } .rb" )
207
- else
208
- test_files_ = ::Dir . glob ( " test/**/tc_*.rb" )
209
- end
205
+ task test : %i[ build_ext build_other ] do
206
+ $LOAD_PATH . unshift ( ::File . expand_path ( 'lib' , ::File . dirname ( __FILE__ ) ) )
207
+ test_files_ = if ::ENV [ 'TESTCASE' ]
208
+ ::Dir . glob ( "test/#{ ::ENV [ 'TESTCASE' ] } .rb" )
209
+ else
210
+ ::Dir . glob ( ' test/**/tc_*.rb' )
211
+ end
210
212
test_files_ . each do |path_ |
211
213
load path_
212
214
puts "Loaded testcase #{ path_ } "
213
215
end
214
216
end
215
217
216
-
217
218
# Default task
218
219
219
- task default : [ : clean, : test]
220
+ task default : %i[ clean test ]
0 commit comments