rake-builder 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +8 -5
- data/examples/05_tests/Rakefile +3 -3
- data/examples/05_tests/include/units.h +2 -2
- data/lib/compiler.rb +25 -30
- data/lib/rake/builder.rb +135 -136
- data/lib/rake/builder/installer.rb +37 -0
- data/lib/rake/{local_config.rb → builder/local_config.rb} +13 -14
- data/lib/rake/builder/logger/formatter.rb +7 -1
- data/lib/rake/builder/presenters/makefile/builder_presenter.rb +66 -33
- data/lib/rake/builder/presenters/makefile_am/builder_presenter.rb +4 -4
- data/lib/rake/builder/qt_builder.rb +3 -8
- data/lib/rake/builder/task_definers/builder_task_definer.rb +1 -4
- data/lib/rake/builder/version.rb +1 -1
- data/lib/rake/{microsecond.rb → microsecond_task.rb} +22 -27
- data/lib/rake/once_task.rb +2 -7
- data/lib/rake/path.rb +1 -6
- data/spec/gather_rspec_coverage.rb +2 -0
- data/spec/spec_helper.rb +13 -98
- data/spec/unit/compiler_spec.rb +129 -0
- data/spec/unit/rake/builder/autoconf/version_spec.rb +62 -5
- data/spec/unit/rake/builder/configure_ac_spec.rb +53 -0
- data/spec/unit/rake/builder/install_spec.rb +101 -0
- data/spec/unit/rake/builder/local_config_spec.rb +53 -0
- data/spec/unit/rake/builder/logger/formatter_spec.rb +20 -0
- data/spec/unit/rake/builder/presenters/makefile/builder_presenter_spec.rb +163 -0
- data/spec/unit/rake/builder/presenters/makefile_am/builder_presenter_spec.rb +4 -2
- data/spec/unit/rake/builder/task_definers/builder_task_definer_spec.rb +6 -0
- data/spec/unit/rake/builder_spec.rb +391 -16
- data/spec/unit/rake/microsecond_task_spec.rb +63 -0
- metadata +39 -55
- data/examples/01_hello_world_cpp/vendor/bundle/gems/coderay-1.0.8/Rakefile +0 -35
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/Rakefile +0 -412
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/fbuffer/fbuffer.h +0 -185
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/generator/generator.c +0 -1427
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/generator/generator.h +0 -149
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/parser/parser.c +0 -2204
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/parser/parser.h +0 -77
- data/examples/01_hello_world_cpp/vendor/bundle/gems/method_source-0.8.1/Rakefile +0 -79
- data/examples/01_hello_world_cpp/vendor/bundle/gems/pry-0.9.11.3/Rakefile +0 -136
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/Rakefile +0 -374
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/a.c +0 -6
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/b.c +0 -6
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/main.c +0 -11
- data/examples/01_hello_world_cpp/vendor/bundle/gems/slop-3.4.3/Rakefile +0 -29
- data/lib/rake/file_task_alias.rb +0 -24
- data/spec/c_project/main.c +0 -12
- data/spec/c_project/main.h +0 -6
- data/spec/c_project_spec.rb +0 -41
- data/spec/cpp_project/main.cpp +0 -12
- data/spec/cpp_project/main.h +0 -8
- data/spec/cpp_project_spec.rb +0 -203
- data/spec/generated_files_spec.rb +0 -65
- data/spec/libraries_spec.rb +0 -35
- data/spec/local_config_spec.rb +0 -95
- data/spec/logger_spec.rb +0 -25
- data/spec/microsecond_task_spec.rb +0 -32
- data/spec/objective_c_project/main.h +0 -1
- data/spec/objective_c_project/main.m +0 -18
- data/spec/objective_c_project_spec.rb +0 -72
- data/spec/paths_spec.rb +0 -19
- data/spec/project_spec.rb +0 -20
- data/spec/target_spec.rb +0 -48
data/Rakefile
CHANGED
@@ -4,17 +4,20 @@ require 'rspec/core/rake_task'
|
|
4
4
|
|
5
5
|
task :default => :spec
|
6
6
|
|
7
|
-
RSpec::Core::RakeTask.new do |
|
7
|
+
RSpec::Core::RakeTask.new do |t|
|
8
8
|
t.pattern = 'spec/**/*_spec.rb'
|
9
9
|
end
|
10
10
|
|
11
11
|
if RUBY_VERSION < '1.9'
|
12
|
-
|
13
|
-
RSpec::Core::RakeTask.new( 'spec:rcov' ) do |t|
|
12
|
+
RSpec::Core::RakeTask.new('spec:rcov') do |t|
|
14
13
|
t.pattern = 'spec/**/*_spec.rb'
|
15
14
|
t.rcov = true
|
16
|
-
t.rcov_opts = [
|
15
|
+
t.rcov_opts = ['--exclude', 'spec/,/gems/']
|
16
|
+
end
|
17
|
+
else
|
18
|
+
desc 'Run specs and create coverage output'
|
19
|
+
RSpec::Core::RakeTask.new('spec:coverage') do |t|
|
20
|
+
t.pattern = ['spec/gather_rspec_coverage.rb', 'spec/**/*_spec.rb']
|
17
21
|
end
|
18
|
-
|
19
22
|
end
|
20
23
|
|
data/examples/05_tests/Rakefile
CHANGED
@@ -5,15 +5,15 @@ require 'rake/builder'
|
|
5
5
|
Rake::Builder.new do |builder|
|
6
6
|
builder.target = 'unit'
|
7
7
|
builder.source_search_paths = [ 'src' ]
|
8
|
-
builder.
|
8
|
+
builder.installable_headers = [ 'include' ]
|
9
9
|
end
|
10
10
|
|
11
11
|
Rake::Builder.new do |builder|
|
12
12
|
builder.task_namespace = 'test'
|
13
13
|
builder.target = 'test_unit'
|
14
14
|
builder.source_search_paths = [ 'test', 'src/units.*' ]
|
15
|
-
builder.
|
15
|
+
builder.installable_headers = [ 'include' ]
|
16
16
|
builder.objects_path = 'test'
|
17
|
-
builder.compilation_options = '-DDEBUG'
|
17
|
+
builder.compilation_options = [ '-DDEBUG' ]
|
18
18
|
end
|
19
19
|
|
data/lib/compiler.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
|
2
1
|
module Compiler
|
3
|
-
|
4
2
|
class Base
|
5
|
-
EXTRA_PATHS = [
|
3
|
+
EXTRA_PATHS = ['/opt/local/include']
|
6
4
|
|
7
|
-
def self.for(
|
8
|
-
COMPILERS[
|
5
|
+
def self.for(compiler)
|
6
|
+
COMPILERS[compiler].new
|
9
7
|
end
|
10
8
|
|
11
9
|
def initialize
|
12
10
|
@paths = {}
|
13
11
|
end
|
14
12
|
|
15
|
-
def include_paths(
|
13
|
+
def include_paths(headers)
|
16
14
|
paths = []
|
17
|
-
headers.each do |
|
18
|
-
path = find_header(
|
19
|
-
raise "Can't find header '#{
|
15
|
+
headers.each do |header|
|
16
|
+
path = find_header(header)
|
17
|
+
raise "Can't find header '#{header}' in any known include path" if path.nil?
|
20
18
|
paths << path
|
21
19
|
end
|
22
20
|
paths.uniq
|
@@ -24,29 +22,27 @@ module Compiler
|
|
24
22
|
|
25
23
|
private
|
26
24
|
|
27
|
-
def find_header(
|
28
|
-
EXTRA_PATHS.each do |
|
29
|
-
if File.exist?(
|
25
|
+
def find_header(header)
|
26
|
+
EXTRA_PATHS.each do |path|
|
27
|
+
if File.exist?("#{path}/#{header}")
|
30
28
|
return path
|
31
29
|
end
|
32
30
|
end
|
33
31
|
nil
|
34
32
|
end
|
35
|
-
|
36
33
|
end
|
37
34
|
|
38
35
|
class GCC < Base
|
39
|
-
|
40
|
-
|
41
|
-
"/Library/Frameworks/#{ framework }.framework/Versions/#{ qt_major }/Headers"
|
36
|
+
def self.framework_path(framework, qt_major)
|
37
|
+
"/Library/Frameworks/#{framework}.framework/Versions/#{qt_major}/Headers"
|
42
38
|
end
|
43
39
|
|
44
|
-
def default_include_paths(
|
45
|
-
return @paths[
|
40
|
+
def default_include_paths(language)
|
41
|
+
return @paths[language] if @paths[language]
|
46
42
|
|
47
43
|
paths = []
|
48
44
|
# Below is the recommended(!) way of getting standard search paths from GCC
|
49
|
-
output = `echo | LANG=C gcc -v -x #{
|
45
|
+
output = `echo | LANG=C gcc -v -x #{language} -E - 2>&1 1>/dev/null`
|
50
46
|
collecting = false
|
51
47
|
output.each_line do | line |
|
52
48
|
case
|
@@ -61,24 +57,23 @@ module Compiler
|
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
64
|
-
@paths[
|
60
|
+
@paths[language] = paths
|
65
61
|
end
|
66
62
|
|
67
|
-
def missing_headers(
|
68
|
-
include_path = include_paths.map { |
|
69
|
-
command = "makedepend -f- -- #{
|
70
|
-
output = `#{
|
63
|
+
def missing_headers(include_paths, source_files)
|
64
|
+
include_path = include_paths.map { |path| "-I#{path}"}.join(' ')
|
65
|
+
command = "makedepend -f- -- #{include_path} -- #{source_files.join(' ')} 2>&1 1>/dev/null"
|
66
|
+
output = `#{command}`
|
71
67
|
missing = []
|
72
|
-
output.each_line do |
|
73
|
-
match = line.match(
|
74
|
-
missing << match[
|
68
|
+
output.each_line do |line|
|
69
|
+
match = line.match(/cannot find include file "([^"]*)"/m)
|
70
|
+
missing << match[1] if match
|
75
71
|
end
|
76
72
|
|
77
73
|
missing
|
78
74
|
end
|
79
|
-
|
80
75
|
end
|
81
76
|
|
82
|
-
COMPILERS = {
|
83
|
-
|
77
|
+
COMPILERS = {:gcc => GCC}
|
84
78
|
end
|
79
|
+
|
data/lib/rake/builder.rb
CHANGED
@@ -4,6 +4,8 @@ require 'rake'
|
|
4
4
|
require 'rake/builder/autoconf/version'
|
5
5
|
require 'rake/builder/configure_ac'
|
6
6
|
require 'rake/builder/error'
|
7
|
+
require 'rake/builder/installer'
|
8
|
+
require 'rake/builder/local_config'
|
7
9
|
require 'rake/builder/logger/formatter'
|
8
10
|
require 'rake/builder/presenters/makefile/builder_presenter'
|
9
11
|
require 'rake/builder/presenters/makefile_am/builder_presenter'
|
@@ -11,7 +13,7 @@ require 'rake/builder/presenters/makefile_am/builder_collection_presenter'
|
|
11
13
|
require 'rake/builder/task_definers/builder_task_definer'
|
12
14
|
require 'rake/builder/task_definers/builder_collection_task_definer'
|
13
15
|
require 'rake/path'
|
14
|
-
require 'rake/
|
16
|
+
require 'rake/microsecond_task'
|
15
17
|
require 'rake/once_task'
|
16
18
|
require 'compiler'
|
17
19
|
|
@@ -112,12 +114,12 @@ module Rake
|
|
112
114
|
attr_accessor :installable_headers
|
113
115
|
|
114
116
|
def header_search_paths
|
115
|
-
warn 'Deprecation notice: Rake::Builder#header_search_paths has
|
117
|
+
warn 'Deprecation notice: Rake::Builder#header_search_paths has been replaced by Rake::Builder#installable_headers'
|
116
118
|
installable_headers
|
117
119
|
end
|
118
120
|
|
119
121
|
def header_search_paths=(paths)
|
120
|
-
warn 'Deprecation notice: Rake::Builder#header_search_paths has
|
122
|
+
warn 'Deprecation notice: Rake::Builder#header_search_paths has been replaced by Rake::Builder#installable_headers'
|
121
123
|
installable_headers = paths
|
122
124
|
end
|
123
125
|
|
@@ -187,6 +189,7 @@ module Rake
|
|
187
189
|
Rake::Builder::BuilderCollectionTaskDefiner.new.run
|
188
190
|
|
189
191
|
def initialize(&block)
|
192
|
+
raise 'No block given' if block.nil?
|
190
193
|
save_rakefile_info(block)
|
191
194
|
set_defaults
|
192
195
|
block.call(self)
|
@@ -195,14 +198,12 @@ module Rake
|
|
195
198
|
self.class.instances << self
|
196
199
|
end
|
197
200
|
|
198
|
-
|
199
|
-
|
200
|
-
puts shell(command, Logger::INFO)
|
201
|
-
end
|
201
|
+
################################################
|
202
|
+
# main actions
|
202
203
|
|
203
204
|
def build
|
204
205
|
logger.debug "Building '#{target}'"
|
205
|
-
|
206
|
+
File.unlink(target) if File.exist?(target)
|
206
207
|
build_commands.each do |command|
|
207
208
|
stdout, stderr = shell(command)
|
208
209
|
raise BuildFailure.new("Error: command '#{command}' failed: #{stderr} #{stdout}") if not $?.success?
|
@@ -210,14 +211,40 @@ module Rake
|
|
210
211
|
raise BuildFailure.new("'#{target}' not created") if not File.exist?(target)
|
211
212
|
end
|
212
213
|
|
213
|
-
def
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
214
|
+
def run
|
215
|
+
old_dir = Dir.pwd
|
216
|
+
Dir.chdir rakefile_path
|
217
|
+
command = File.join('.', target)
|
218
|
+
begin
|
219
|
+
output, error = shell(command, ::Logger::INFO)
|
220
|
+
$stdout.print output
|
221
|
+
$stderr.print error
|
222
|
+
raise Exception.new("Running #{command} failed with status #{$?.exitstatus}") if not $?.success?
|
223
|
+
ensure
|
224
|
+
Dir.chdir old_dir
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def clean
|
229
|
+
generated_files.each do |file|
|
230
|
+
File.unlink(file) if File.exist?(file)
|
231
|
+
end
|
219
232
|
end
|
220
233
|
|
234
|
+
def install
|
235
|
+
destination = File.join(install_path, target_basename)
|
236
|
+
Rake::Builder::Installer.new.install target, destination
|
237
|
+
install_headers if target_type == :static_library
|
238
|
+
end
|
239
|
+
|
240
|
+
def uninstall
|
241
|
+
destination = File.join(install_path, target_basename)
|
242
|
+
Rake::Builder::Installer.new.uninstall destination
|
243
|
+
end
|
244
|
+
|
245
|
+
################################################
|
246
|
+
# helpers invoked by tasks
|
247
|
+
|
221
248
|
def create_makedepend_file
|
222
249
|
logger.debug 'Creating makedepend file'
|
223
250
|
system('which makedepend >/dev/null')
|
@@ -226,74 +253,80 @@ module Rake
|
|
226
253
|
shell command
|
227
254
|
end
|
228
255
|
|
229
|
-
def load_local_config
|
230
|
-
config = Rake::LocalConfig.new(local_config)
|
231
|
-
config.load
|
232
|
-
@include_paths += Rake::Path.expand_all_with_root(config.include_paths, rakefile_path)
|
233
|
-
@compilation_options += config.compilation_options
|
234
|
-
end
|
235
|
-
|
236
256
|
def load_makedepend
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
257
|
+
content = File.read(makedepend_file)
|
258
|
+
# Replace old-style files with full paths
|
259
|
+
if content =~ %r(^/)
|
260
|
+
create_makedepend_file
|
261
|
+
return load_makedepend
|
262
|
+
end
|
263
|
+
|
264
|
+
# makedepend assumes each .o files will be in the same path as its source
|
265
|
+
real_object_path = source_files.inject({}) do |a, source|
|
266
|
+
source_path_object = source.gsub('.' + source_file_extension, '.o')
|
267
|
+
correct_path_object = object_path(source)
|
268
|
+
a[source_path_object] = correct_path_object
|
269
|
+
a
|
241
270
|
end
|
242
271
|
|
243
272
|
object_header_dependencies = Hash.new { |h, v| h[v] = [] }
|
244
|
-
|
273
|
+
content.each_line do |line|
|
245
274
|
next if line !~ /:\s/
|
246
|
-
|
275
|
+
source_path_object = $`
|
247
276
|
header_files = $'.chomp
|
248
|
-
|
249
|
-
|
250
|
-
object_header_dependencies[object_file] += header_files.split(' ')
|
277
|
+
object_path_name = real_object_path[source_path_object]
|
278
|
+
object_header_dependencies[object_path_name] += header_files.split(' ')
|
251
279
|
end
|
280
|
+
|
252
281
|
object_header_dependencies
|
253
282
|
end
|
254
283
|
|
255
|
-
def
|
256
|
-
|
257
|
-
system "rm -f #{file}"
|
258
|
-
end
|
284
|
+
def generated_headers
|
285
|
+
[]
|
259
286
|
end
|
260
287
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
288
|
+
# Raises an error if there are missing headers
|
289
|
+
def ensure_headers
|
290
|
+
missing = missing_headers
|
291
|
+
return if missing.size == 0
|
292
|
+
|
293
|
+
message = "Compilation cannot proceed as the following header files are missing:\n" + missing.join("\n")
|
294
|
+
raise Error.new(message)
|
265
295
|
end
|
266
296
|
|
267
|
-
def
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
297
|
+
def load_local_config
|
298
|
+
config = Rake::Builder::LocalConfig.new(local_config)
|
299
|
+
config.load
|
300
|
+
@include_paths += config.include_paths
|
301
|
+
@compilation_options += config.compilation_options
|
302
|
+
end
|
303
|
+
|
304
|
+
def create_local_config
|
305
|
+
logger.debug "Creating file '#{local_config}'"
|
306
|
+
added_includes = compiler_data.include_paths(missing_headers)
|
307
|
+
config = Rake::Builder::LocalConfig.new(local_config)
|
308
|
+
config.include_paths = added_includes
|
309
|
+
config.save
|
278
310
|
end
|
279
311
|
|
280
312
|
def compile(source, object)
|
281
|
-
logger.add(Logger::DEBUG, "Compiling '#{source}'")
|
313
|
+
logger.add(::Logger::DEBUG, "Compiling '#{source}'")
|
282
314
|
command = "#{compiler} -c #{compiler_flags} -o #{object} #{source}"
|
283
315
|
stdout, stderr = shell(command)
|
284
316
|
raise BuildFailure.new("Error: command '#{command}' failed: #{stderr} #{stdout}") if not $?.success?
|
285
317
|
end
|
286
318
|
|
287
|
-
|
288
|
-
|
289
|
-
return @source_files if @source_files
|
290
|
-
@source_files = find_files( @source_search_paths, @source_file_extension ).uniq.sort
|
291
|
-
end
|
319
|
+
################################################
|
320
|
+
# public attributes
|
292
321
|
|
293
322
|
def is_library?
|
294
323
|
[:static_library, :shared_library].include?(target_type)
|
295
324
|
end
|
296
325
|
|
326
|
+
def target_basename
|
327
|
+
File.basename(@target)
|
328
|
+
end
|
329
|
+
|
297
330
|
def primary_name
|
298
331
|
Rake::Path.relative_path(target, rakefile_path, :initial_dot_slash => false)
|
299
332
|
end
|
@@ -302,8 +335,15 @@ module Rake
|
|
302
335
|
primary_name.gsub(%r(\.), '_')
|
303
336
|
end
|
304
337
|
|
305
|
-
|
306
|
-
|
338
|
+
# Source files found in source_search_paths
|
339
|
+
def source_files
|
340
|
+
return @source_files if @source_files
|
341
|
+
|
342
|
+
old_dir = Dir.pwd
|
343
|
+
Dir.chdir @rakefile_path
|
344
|
+
@source_files = Rake::Path.find_files(@source_search_paths, source_file_extension).uniq.sort
|
345
|
+
Dir.chdir old_dir
|
346
|
+
@source_files
|
307
347
|
end
|
308
348
|
|
309
349
|
def object_files
|
@@ -312,7 +352,7 @@ module Rake
|
|
312
352
|
|
313
353
|
def object_path(source_path_name)
|
314
354
|
o_name = File.basename(source_path_name).gsub('.' + source_file_extension, '.o')
|
315
|
-
|
355
|
+
File.join(objects_path, o_name)
|
316
356
|
end
|
317
357
|
|
318
358
|
def compiler_flags
|
@@ -323,12 +363,14 @@ module Rake
|
|
323
363
|
flags
|
324
364
|
end
|
325
365
|
|
326
|
-
def
|
327
|
-
|
366
|
+
def link_flags
|
367
|
+
flags = [ @linker_options, library_paths_list, library_dependencies_list ]
|
368
|
+
flags << architecture_option if RUBY_PLATFORM =~ /darwin/i
|
369
|
+
flags.join( " " )
|
328
370
|
end
|
329
371
|
|
330
|
-
def
|
331
|
-
|
372
|
+
def library_dependencies_list
|
373
|
+
@library_dependencies.map { |lib| "-l#{lib}" }.join(' ')
|
332
374
|
end
|
333
375
|
|
334
376
|
def makefile_name
|
@@ -340,25 +382,6 @@ module Rake
|
|
340
382
|
"Makefile#{ extension }"
|
341
383
|
end
|
342
384
|
|
343
|
-
def generated_headers
|
344
|
-
[]
|
345
|
-
end
|
346
|
-
|
347
|
-
# Raises an error if there are missing headers
|
348
|
-
def ensure_headers
|
349
|
-
missing = missing_headers
|
350
|
-
return if missing.size == 0
|
351
|
-
|
352
|
-
message = "Compilation cannot proceed as the following header files are missing:\n" + missing.join("\n")
|
353
|
-
raise Error.new(message)
|
354
|
-
end
|
355
|
-
|
356
|
-
def link_flags
|
357
|
-
flags = [ @linker_options, library_paths_list, library_dependencies_list ]
|
358
|
-
flags << architecture_option if RUBY_PLATFORM =~ /darwin/i
|
359
|
-
flags.join( " " )
|
360
|
-
end
|
361
|
-
|
362
385
|
private
|
363
386
|
|
364
387
|
# Lists headers referenced by the project's files or includes
|
@@ -373,21 +396,21 @@ module Rake
|
|
373
396
|
def set_defaults
|
374
397
|
@architecture = 'i386'
|
375
398
|
@compiler_data = Compiler::Base.for(:gcc)
|
376
|
-
@logger = Logger.new(STDOUT)
|
377
|
-
@logger.level = Logger::UNKNOWN
|
378
|
-
@logger.formatter = Formatter.new
|
399
|
+
@logger = ::Logger.new(STDOUT)
|
400
|
+
@logger.level = ::Logger::UNKNOWN
|
401
|
+
@logger.formatter = Rake::Builder::Logger::Formatter.new
|
379
402
|
@programming_language = 'c++'
|
380
403
|
@header_file_extension = 'h'
|
381
|
-
@objects_path =
|
404
|
+
@objects_path = '.'
|
382
405
|
@library_paths = []
|
383
406
|
@library_dependencies = []
|
384
407
|
@target_prerequisites = []
|
385
|
-
@source_search_paths = [
|
386
|
-
@target = 'a.out'
|
408
|
+
@source_search_paths = ['.']
|
409
|
+
@target = './a.out'
|
387
410
|
@generated_files = []
|
388
411
|
@compilation_options = []
|
389
|
-
@include_paths = [
|
390
|
-
@installable_headers
|
412
|
+
@include_paths = ['./include']
|
413
|
+
@installable_headers ||= []
|
391
414
|
end
|
392
415
|
|
393
416
|
def configure
|
@@ -402,34 +425,26 @@ module Rake
|
|
402
425
|
@ranlib ||= KNOWN_LANGUAGES[ @programming_language ][ :ranlib ]
|
403
426
|
@source_file_extension ||= KNOWN_LANGUAGES[ @programming_language ][ :source_file_extension ]
|
404
427
|
|
405
|
-
@source_search_paths = Rake::Path.expand_all_with_root( @source_search_paths, @rakefile_path )
|
406
|
-
@library_paths = Rake::Path.expand_all_with_root( @library_paths, @rakefile_path )
|
407
428
|
|
408
429
|
raise Error.new( "The target name cannot be nil", task_namespace ) if @target.nil?
|
409
430
|
raise Error.new( "The target name cannot be an empty string", task_namespace ) if @target == ''
|
410
|
-
@objects_path = Rake::Path.expand_with_root( @objects_path, @rakefile_path )
|
411
431
|
|
412
|
-
@target = File.expand_path( @target, @rakefile_path )
|
413
432
|
@target_type ||= to_target_type( @target )
|
414
433
|
raise Error.new( "Building #{ @target_type } targets is not supported", task_namespace ) if ! TARGET_TYPES.include?( @target_type )
|
415
434
|
@generated_files << @target
|
416
435
|
|
417
436
|
@install_path ||= default_install_path( @target_type )
|
418
|
-
@installable_headers = Rake::Path.expand_all_with_root( @installable_headers, @rakefile_path )
|
419
437
|
|
420
438
|
@linker_options ||= ''
|
421
|
-
@include_paths += []
|
422
|
-
@include_paths = Rake::Path.expand_all_with_root( @include_paths.uniq, @rakefile_path )
|
423
|
-
@generated_files = Rake::Path.expand_all_with_root( @generated_files, @rakefile_path )
|
424
439
|
|
425
440
|
@default_task ||= :build
|
426
441
|
@target_prerequisites << @rakefile
|
427
|
-
@local_config =
|
442
|
+
@local_config = '.rake-builder'
|
428
443
|
|
429
444
|
@makedepend_file = @objects_path + '/.' + target_basename + '.depend.mf'
|
430
445
|
@generated_files << @makedepend_file
|
431
446
|
|
432
|
-
raise Error.new(
|
447
|
+
raise Error.new("No source files found", task_namespace) if source_files.size == 0
|
433
448
|
end
|
434
449
|
|
435
450
|
def to_target_type(target)
|
@@ -446,8 +461,7 @@ module Rake
|
|
446
461
|
# Compiling and linking parameters
|
447
462
|
|
448
463
|
def include_path
|
449
|
-
|
450
|
-
paths.map { |p| "-I#{ p }" }.join( ' ' )
|
464
|
+
@include_paths.map { |p| "-I#{p}" }.join(' ')
|
451
465
|
end
|
452
466
|
|
453
467
|
def architecture_option
|
@@ -483,11 +497,6 @@ module Rake
|
|
483
497
|
def file_list(files)
|
484
498
|
files.join(' ')
|
485
499
|
end
|
486
|
-
|
487
|
-
def find_files( paths, extension )
|
488
|
-
files = Rake::Path.find_files( paths, extension )
|
489
|
-
Rake::Path.expand_all_with_root( files, @rakefile_path )
|
490
|
-
end
|
491
500
|
|
492
501
|
def library_paths_list
|
493
502
|
@library_paths.map { | path | "-L#{ path }" }.join( " " )
|
@@ -497,40 +506,39 @@ module Rake
|
|
497
506
|
# TODO: make install_headers_path a configuration option
|
498
507
|
install_headers_path = '/usr/local/include'
|
499
508
|
|
500
|
-
|
509
|
+
installer = Rake::Builder::Installer.new
|
510
|
+
project_headers.each do |installable_header|
|
501
511
|
destination_path = File.join( install_headers_path, installable_header[ :relative_path ] )
|
502
512
|
begin
|
503
513
|
`mkdir -p '#{ destination_path }'`
|
504
514
|
rescue Errno::EACCES => e
|
505
515
|
raise Error.new( "Permission denied to created directory '#{ destination_path }'", task_namespace )
|
506
516
|
end
|
507
|
-
|
517
|
+
installer.install installable_header[:source_file], destination_path
|
508
518
|
end
|
509
519
|
end
|
510
520
|
|
511
521
|
def project_headers
|
512
|
-
@installable_headers.reduce(
|
513
|
-
non_glob_search = (
|
522
|
+
@installable_headers.reduce([]) do |memo, search|
|
523
|
+
non_glob_search = (search.match(/^([^\*\?]*)/))[1]
|
514
524
|
case
|
515
|
-
when (
|
525
|
+
when search.start_with?('/'), search.start_with?('..')
|
516
526
|
# Skip paths that are not inside the project
|
517
|
-
when File.file?(
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
full_path = Rake::Path.expand_with_root( pathname, @rakefile_path )
|
523
|
-
memo << { :source_file => pathname, :relative_path => '' }
|
527
|
+
when File.file?(search)
|
528
|
+
memo << {:source_file => search, :relative_path => ''}
|
529
|
+
when File.directory?(search)
|
530
|
+
FileList[search + '/*.' + @header_file_extension].each do |pathname|
|
531
|
+
memo << {:source_file => pathname, :relative_path => ''}
|
524
532
|
end
|
525
|
-
when (
|
526
|
-
FileList[
|
527
|
-
full_path = Rake::Path.expand_with_root(
|
528
|
-
directory = File.dirname(
|
529
|
-
relative = Rake::Path.relative_path(
|
530
|
-
memo << {
|
533
|
+
when (search =~ /[\*\?]/)
|
534
|
+
FileList[search].each do |pathname|
|
535
|
+
full_path = Rake::Path.expand_with_root(pathname, @rakefile_path)
|
536
|
+
directory = File.dirname(full_path)
|
537
|
+
relative = Rake::Path.relative_path(directory, non_glob_search)
|
538
|
+
memo << {:source_file => pathname, :relative_path => relative}
|
531
539
|
end
|
532
540
|
else
|
533
|
-
$stderr.puts "Bad search path: '
|
541
|
+
$stderr.puts "Bad search path: '#{search}'"
|
534
542
|
end
|
535
543
|
memo
|
536
544
|
end
|
@@ -550,23 +558,14 @@ module Rake
|
|
550
558
|
end
|
551
559
|
end
|
552
560
|
|
553
|
-
def
|
554
|
-
begin
|
555
|
-
shell "cp '#{ source_pathname }' '#{ destination_path }'", Logger::INFO
|
556
|
-
rescue Errno::EACCES => e
|
557
|
-
source_filename = File.basename( source_pathname ) rescue '????'
|
558
|
-
raise Error.new( "You do not have permission to install '#{ source_filename }' to '#{ destination_path }'\nTry\n $ sudo rake install", task_namespace )
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
def shell(command, log_level = Logger::DEBUG)
|
561
|
+
def shell(command, log_level = ::Logger::DEBUG)
|
563
562
|
@logger.add(log_level, command)
|
564
563
|
originals = $stdout, $stderr
|
565
564
|
stdout, stderr = StringIO.new, StringIO.new
|
566
565
|
$stdout, $stderr = stdout, stderr
|
567
566
|
system command, {:out => :out, :err => :err}
|
568
567
|
$stdout, $stderr = *originals
|
569
|
-
[stdout.
|
568
|
+
[stdout.string, stderr.string]
|
570
569
|
end
|
571
570
|
end
|
572
571
|
end
|