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
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Rake::Builder
|
4
|
+
class Installer
|
5
|
+
def install(source_pathname, destination_path)
|
6
|
+
ensure_file_exists source_pathname
|
7
|
+
raise "The path '#{destination_path}' does not exist" unless File.exist?(destination_path)
|
8
|
+
raise "'#{destination_path}' is not a directory" unless File.directory?(destination_path)
|
9
|
+
ensure_directory_writable destination_path, "Cannot copy files to the directory '#{destination_path}'"
|
10
|
+
filename = File.basename(source_pathname)
|
11
|
+
destination_pathname = File.join(destination_path, filename)
|
12
|
+
if File.file?(destination_pathname) and not File.writable?(destination_pathname)
|
13
|
+
raise "The file '#{destination_pathname}' cannot be overwritten"
|
14
|
+
end
|
15
|
+
|
16
|
+
FileUtils.copy_file source_pathname, destination_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def uninstall(installed_pathname)
|
20
|
+
return unless File.exist?(installed_pathname)
|
21
|
+
ensure_directory_writable File.dirname(installed_pathname)
|
22
|
+
File.unlink installed_pathname
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def ensure_file_exists(pathname)
|
28
|
+
raise "File '#{pathname}' does not exist" unless File.exist?(pathname)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ensure_directory_writable(path, message = nil)
|
32
|
+
message ||= "The directory '#{path}' is not writable"
|
33
|
+
raise message unless File.writable?(path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -1,43 +1,42 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
class Rake::Builder
|
5
4
|
class LocalConfig
|
6
|
-
|
7
5
|
VERSIONS = ['1.0', '1.1']
|
8
6
|
|
9
7
|
attr_accessor :include_paths
|
10
8
|
attr_accessor :compilation_options
|
11
9
|
|
12
|
-
def initialize(
|
10
|
+
def initialize(file_name)
|
13
11
|
@file_name = file_name
|
14
12
|
@include_paths = []
|
15
13
|
@compilation_options = []
|
16
14
|
end
|
17
15
|
|
18
16
|
def load
|
19
|
-
config = YAML.load_file(
|
17
|
+
config = YAML.load_file(@file_name)
|
20
18
|
|
21
|
-
version
|
22
|
-
|
23
|
-
@compilation_options = config[:compilation_options]
|
24
|
-
if not VERSIONS.find_index(version)
|
19
|
+
version = config[:rake_builder][:config_file][:version]
|
20
|
+
if not VERSIONS.include?(version)
|
25
21
|
raise Rake::Builder::Error.new('Config file version incorrect')
|
26
22
|
end
|
23
|
+
@include_paths = config[:include_paths]
|
24
|
+
@compilation_options = config[:compilation_options]
|
27
25
|
end
|
28
26
|
|
29
27
|
def save
|
30
|
-
File.open(
|
28
|
+
File.open(@file_name, 'w') do |file|
|
31
29
|
file.write config.to_yaml
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
33
|
def config
|
36
|
-
{
|
34
|
+
{
|
35
|
+
:rake_builder => {:config_file => {:version => VERSIONS[-1]}},
|
37
36
|
:include_paths => @include_paths,
|
38
|
-
:compilation_options => @compilation_options
|
37
|
+
:compilation_options => @compilation_options
|
38
|
+
}
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
|
-
|
43
41
|
end
|
42
|
+
|
@@ -4,44 +4,84 @@ module Rake::Builder::Presenters::Makefile
|
|
4
4
|
class BuilderPresenter
|
5
5
|
def initialize(builder)
|
6
6
|
@builder = builder
|
7
|
+
check_target_type
|
7
8
|
end
|
8
9
|
|
9
10
|
def to_s
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
check_target_type
|
12
|
+
|
13
|
+
variables = main_variables
|
14
|
+
rules = main_rules
|
15
|
+
|
16
|
+
source_groups = group_files_by_path(@builder.source_files)
|
17
|
+
source_groups.each.with_index do |gp, i|
|
18
|
+
variables << "SOURCE_#{i + 1} = #{gp[0]}\n"
|
19
|
+
rules << <<EOT
|
20
|
+
|
21
|
+
$(OBJECT_DIR)/%.o: $(SOURCE_#{i + 1})/%.cpp
|
22
|
+
$(COMPILER) -c $(COMPILER_FLAGS) -o $@ $<
|
23
|
+
EOT
|
24
|
+
end
|
25
|
+
variables + rules
|
26
|
+
end
|
27
|
+
|
28
|
+
def save
|
29
|
+
File.open(@builder.makefile_name, 'w') do |file|
|
30
|
+
file.write to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def target_type
|
37
|
+
@builder.target_type
|
38
|
+
end
|
39
|
+
|
40
|
+
def target_name
|
41
|
+
case target_type
|
42
|
+
when :executable
|
43
|
+
'EXECUTABLE_TARGET'
|
44
|
+
when :static_library
|
45
|
+
'LIB_TARGET'
|
46
|
+
when :shared_library
|
47
|
+
'LIB_TARGET'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def target_ref
|
52
|
+
"$(#{target_name})"
|
53
|
+
end
|
54
|
+
|
55
|
+
def target_actions
|
56
|
+
case target_type
|
13
57
|
when :executable
|
14
|
-
target_name = 'EXECUTABLE_TARGET'
|
15
|
-
target_ref = "$(#{target_name})"
|
16
|
-
target_actions =
|
17
58
|
" $(LINKER) $(LINK_FLAGS) -o #{target_ref} $(OBJECTS)
|
18
59
|
"
|
19
60
|
when :static_library
|
20
|
-
target_name = 'LIB_TARGET'
|
21
|
-
target_ref = "$(#{target_name})"
|
22
|
-
target_actions =
|
23
61
|
" rm -f #{target_ref}
|
24
62
|
ar -cq #{target_ref} $(OBJECTS)
|
25
63
|
ranlib #{target_ref}
|
26
64
|
"
|
27
65
|
when :shared_library
|
28
|
-
target_name = 'LIB_TARGET'
|
29
|
-
target_ref = "$(#{target_name})"
|
30
|
-
target_actions =
|
31
66
|
" $(LINKER) -shared -o #{target_ref} $(OBJECTS) $(LINK_FLAGS)
|
32
67
|
"
|
33
68
|
end
|
69
|
+
end
|
34
70
|
|
35
|
-
|
71
|
+
def main_variables
|
72
|
+
<<EOT
|
36
73
|
COMPILER = #{@builder.compiler}
|
37
74
|
COMPILER_FLAGS = #{@builder.compiler_flags}
|
38
75
|
LINKER = #{@builder.linker}
|
39
76
|
LINK_FLAGS = #{@builder.link_flags}
|
40
77
|
OBJECT_DIR = #{@builder.objects_path}
|
41
78
|
OBJECTS = #{objects_list}
|
42
|
-
#{
|
79
|
+
#{target_name} = #{@builder.target}
|
43
80
|
EOT
|
44
|
-
|
81
|
+
end
|
82
|
+
|
83
|
+
def main_rules
|
84
|
+
<<EOT
|
45
85
|
|
46
86
|
all: #{target_ref}
|
47
87
|
|
@@ -52,30 +92,23 @@ clean:
|
|
52
92
|
#{target_ref}: $(OBJECTS)
|
53
93
|
#{target_actions}
|
54
94
|
EOT
|
95
|
+
end
|
55
96
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
rules << <<EOT
|
60
|
-
|
61
|
-
$(OBJECT_DIR)/%.o: $(SOURCE_#{i + 1})/%.cpp
|
62
|
-
$(COMPILER) -c $(COMPILER_FLAGS) -o $@ $<
|
63
|
-
EOT
|
64
|
-
end
|
65
|
-
variables + rules
|
97
|
+
def objects_list
|
98
|
+
objects = @builder.object_files.map { |f| f.sub(@builder.objects_path, '$(OBJECT_DIR)') }
|
99
|
+
objects.join(' ')
|
66
100
|
end
|
67
101
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
102
|
+
def group_files_by_path(files)
|
103
|
+
files.group_by do |f|
|
104
|
+
m = f.match(/(.*?)?\/?([^\/]+)$/)
|
105
|
+
m[1]
|
71
106
|
end
|
72
107
|
end
|
73
108
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
m[ 1 ]
|
78
|
-
end
|
109
|
+
def check_target_type
|
110
|
+
return if [:executable, :shared_library, :static_library].include?(target_type)
|
111
|
+
raise "Unknown build target type '#{target_type}'"
|
79
112
|
end
|
80
113
|
end
|
81
114
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Rake
|
1
|
+
module Rake::Builder::Presenters::MakefileAm
|
2
2
|
class BuilderPresenter
|
3
3
|
attr_accessor :builder
|
4
4
|
|
@@ -7,13 +7,13 @@ module Rake; class Builder; module Presenters; module MakefileAm
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_s
|
10
|
-
[sources, cpp_flags, ld_flags, libraries, ''].compact.join("
|
10
|
+
[sources, cpp_flags, ld_flags, libraries, ''].compact.join("\n")
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def sources
|
16
|
-
"#{builder.label}_SOURCES = #{builder.
|
16
|
+
"#{builder.label}_SOURCES = #{builder.source_files.join(' ')}"
|
17
17
|
end
|
18
18
|
|
19
19
|
def cpp_flags
|
@@ -36,5 +36,5 @@ module Rake; class Builder; module Presenters; module MakefileAm
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
40
40
|
|
@@ -47,8 +47,6 @@ module Rake
|
|
47
47
|
|
48
48
|
super
|
49
49
|
|
50
|
-
@resource_files = Rake::Path.expand_all_with_root( @resource_files, @rakefile_path )
|
51
|
-
@ui_files = Rake::Path.expand_all_with_root( @ui_files, @rakefile_path )
|
52
50
|
@compilation_options += [ '-pipe', '-g', '-gdwarf-2', '-Wall', '-W' ]
|
53
51
|
@include_paths << @objects_path # for UI headers
|
54
52
|
end
|
@@ -161,8 +159,7 @@ module Rake
|
|
161
159
|
end
|
162
160
|
|
163
161
|
def ui_header_path( ui_file )
|
164
|
-
|
165
|
-
Rake::Path.expand_with_root( header_name, @objects_path )
|
162
|
+
'ui_' + File.basename(ui_file).gsub('.ui', '.h')
|
166
163
|
end
|
167
164
|
|
168
165
|
# MOC
|
@@ -191,8 +188,7 @@ module Rake
|
|
191
188
|
end
|
192
189
|
|
193
190
|
def moc_pathname( header_name )
|
194
|
-
|
195
|
-
Rake::Path.expand_with_root( moc_name, @objects_path )
|
191
|
+
'moc_' + File.basename(header_name).gsub('.' + @header_file_extension, '.cpp')
|
196
192
|
end
|
197
193
|
|
198
194
|
# Resources
|
@@ -214,8 +210,7 @@ module Rake
|
|
214
210
|
end
|
215
211
|
|
216
212
|
def qrc_pathname( resource_name )
|
217
|
-
|
218
|
-
Rake::Path.expand_with_root( qrc_name, @objects_path )
|
213
|
+
'qrc_' + File.basename(resource_name).gsub('.qrc', '.cpp')
|
219
214
|
end
|
220
215
|
|
221
216
|
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'rake/file_task_alias'
|
2
|
-
require 'rake/local_config'
|
3
|
-
|
4
1
|
include Rake::DSL
|
5
2
|
|
6
3
|
class Rake::Builder
|
@@ -71,7 +68,7 @@ class Rake::Builder
|
|
71
68
|
@builder.create_local_config
|
72
69
|
end
|
73
70
|
|
74
|
-
once_task :load_local_config =>
|
71
|
+
once_task :load_local_config => @builder.local_config do
|
75
72
|
@builder.load_local_config
|
76
73
|
end
|
77
74
|
|
data/lib/rake/builder/version.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
-
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
-
require 'rake/tasklib'
|
3
1
|
require 'fileutils'
|
4
2
|
|
5
3
|
module Rake
|
6
|
-
|
7
4
|
module Microsecond
|
8
|
-
|
9
|
-
|
10
|
-
class FileTask < Task
|
11
|
-
|
5
|
+
class Base < Task
|
12
6
|
attr_accessor :timestamp
|
13
7
|
|
8
|
+
def prerequisites_needed?
|
9
|
+
prerequisites.any? do |n|
|
10
|
+
task = application[n]
|
11
|
+
if task.is_a?(Rake::FileTask) or
|
12
|
+
task.is_a?(self.class)
|
13
|
+
task.timestamp > @timestamp
|
14
|
+
else
|
15
|
+
task.needed?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Compensate for file systems with 1s resolution
|
22
|
+
class FileTask < Base
|
14
23
|
def self.define_task( *args, &block )
|
15
24
|
task = super( *args, &block )
|
16
25
|
task.timestamp = nil
|
@@ -20,32 +29,21 @@ module Rake
|
|
20
29
|
def needed?
|
21
30
|
return true if not File.exist?(self.name)
|
22
31
|
@timestamp = File.stat(self.name).mtime if @timestamp.nil?
|
23
|
-
|
24
|
-
task = application[n]
|
25
|
-
if task.is_a?(Rake::FileTask) or
|
26
|
-
task.is_a?(self.class)
|
27
|
-
task.timestamp > @timestamp
|
28
|
-
else
|
29
|
-
task.needed?
|
30
|
-
end
|
31
|
-
end
|
32
|
+
prerequisites_needed?
|
32
33
|
end
|
33
34
|
|
34
35
|
def execute(*args)
|
35
36
|
@timestamp = Time.now
|
36
37
|
super(*args)
|
37
38
|
end
|
38
|
-
|
39
39
|
end
|
40
40
|
|
41
|
-
class DirectoryTask <
|
42
|
-
|
41
|
+
class DirectoryTask < Base
|
43
42
|
include FileUtils
|
44
43
|
|
45
|
-
attr_accessor :timestamp
|
46
44
|
attr_accessor :path
|
47
45
|
|
48
|
-
def self.define_task(
|
46
|
+
def self.define_task(*args, &block)
|
49
47
|
task = super(*args, &block)
|
50
48
|
task.path = args[0]
|
51
49
|
task.timestamp = nil
|
@@ -53,11 +51,11 @@ module Rake
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def needed?
|
56
|
-
|
57
|
-
if
|
54
|
+
return true if not File.directory?(self.path)
|
55
|
+
if @timestamp.nil?
|
58
56
|
@timestamp = File.stat(self.path).mtime
|
59
57
|
end
|
60
|
-
|
58
|
+
prerequisites_needed?
|
61
59
|
end
|
62
60
|
|
63
61
|
def execute(*args)
|
@@ -65,11 +63,8 @@ module Rake
|
|
65
63
|
@timestamp = Time.now
|
66
64
|
super(*args)
|
67
65
|
end
|
68
|
-
|
69
66
|
end
|
70
|
-
|
71
67
|
end
|
72
|
-
|
73
68
|
end
|
74
69
|
|
75
70
|
def microsecond_file(*args, &block)
|
data/lib/rake/once_task.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
|
-
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
1
|
require 'rake/tasklib'
|
3
2
|
|
4
3
|
module Rake
|
5
|
-
|
6
4
|
# A task whick is no longer needed after its first invocation
|
7
5
|
class OnceTask < Task
|
8
|
-
|
9
6
|
attr_accessor :invoked
|
10
7
|
attr_accessor :timestamp
|
11
8
|
|
12
|
-
def self.define_task(
|
13
|
-
task = super(
|
9
|
+
def self.define_task(*args, &block)
|
10
|
+
task = super(*args, &block)
|
14
11
|
task.timestamp = nil
|
15
12
|
task.invoked = false
|
16
13
|
task
|
@@ -25,9 +22,7 @@ module Rake
|
|
25
22
|
def needed?
|
26
23
|
! @invoked
|
27
24
|
end
|
28
|
-
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
32
27
|
|
33
28
|
def once_task(*args, &block)
|