rake-builder 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'the dependencies system' do
4
+
5
+ include RakeBuilderHelper
6
+
7
+ before( :each ) do
8
+ Rake::Task.clear
9
+ @project = cpp_task( :executable )
10
+ Rake::Task[ 'clean' ].execute
11
+ end
12
+
13
+ after( :each ) do
14
+ Rake::Task[ 'clean' ].execute
15
+ end
16
+
17
+ it 'says the target is up to date, if nothing changes' do
18
+ Rake::Task[ 'build' ].invoke
19
+ Rake::Task[ @project.target ].needed?.should_not be_true
20
+ end
21
+
22
+ it 'says the build is up to date, if nothing changes' do
23
+ Rake::Task[ 'build' ].invoke
24
+ Rake::Task[ 'build' ].needed?.should be_false
25
+ end
26
+
27
+ it 'doesn\'t recompile objects, if nothing changes' do
28
+ isolating_seconds do
29
+ Rake::Task[ 'compile' ].invoke
30
+ end
31
+ Rake::Task.clear
32
+ @project = cpp_task( :executable )
33
+ object_file_path = Rake::Builder.expand_path_with_root( 'main.o', SPEC_PATH )
34
+ Rake::Task[ object_file_path ].needed?.should be_false
35
+ end
36
+
37
+ it 'recompiles objects, if a source file changes' do
38
+ isolating_seconds do
39
+ Rake::Task[ 'compile' ].invoke
40
+ end
41
+ Rake::Task.clear
42
+ @project = cpp_task( :executable )
43
+ source_file_path = Rake::Builder.expand_path_with_root( 'cpp_project/main.cpp', SPEC_PATH )
44
+ object_file_path = Rake::Builder.expand_path_with_root( 'main.o', SPEC_PATH )
45
+ touching_temporarily( source_file_path, File.mtime( object_file_path ) + 1 ) do
46
+ Rake::Task[ object_file_path ].needed?.should be_true
47
+ end
48
+ end
49
+
50
+ it 'recompiles source files, if header dependencies' do
51
+ header_file_path = Rake::Builder.expand_path_with_root( 'cpp_project/main.h', SPEC_PATH )
52
+ object_file_path = Rake::Builder.expand_path_with_root( 'main.o', SPEC_PATH )
53
+ isolating_seconds do
54
+ Rake::Task[ 'compile' ].invoke
55
+ end
56
+ Rake::Task.clear
57
+ @project = cpp_task( :executable )
58
+ # Header dependencies aren't loaded until we call :compile
59
+ Rake::Task[ :load_makedepend ].invoke
60
+ touching_temporarily( header_file_path, File.mtime( object_file_path ) + 1 ) do
61
+ Rake::Task[ object_file_path ].needed?.should be_true
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ describe 'Rakefile dependencies' do
68
+
69
+ include RakeBuilderHelper
70
+
71
+ before( :each ) do
72
+ Rake::Task.clear
73
+ @project = cpp_task( :executable )
74
+ Rake::Task[ 'clean' ].execute
75
+ end
76
+
77
+ after( :each ) do
78
+ Rake::Task[ 'clean' ].execute
79
+ end
80
+
81
+ it 'should make the target depend on the Rakefile' do
82
+ Rake::Task[ @project.target ].prerequisites.include?( @project.rakefile ).should be_true
83
+ end
84
+
85
+ # In our case this spec file is the spec_helper
86
+ # i.e., the file that calls Rake::Builder.new
87
+ it 'should indicate the target is out of date, if the Rakefile is newer' do
88
+ Rake::Task[ 'build' ].invoke
89
+ Rake::Task[ @project.target ].needed?.should be_false
90
+ touching_temporarily( @project.target, File.mtime( @project.rakefile ) - 1 ) do
91
+ Rake::Task[ @project.target ].needed?.should be_true
92
+ end
93
+ end
94
+
95
+ it 'should indicate that a build is needed if the Rakefile changes' do
96
+ Rake::Task[ 'build' ].invoke
97
+ Rake::Task[ 'build' ].needed?.should be_false
98
+ touching_temporarily( @project.target, File.mtime( @project.rakefile ) - 1 ) do
99
+ Rake::Task[ 'build' ].needed?.should be_true
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'when handling generated files' do
4
+
5
+ include RakeBuilderHelper
6
+
7
+ before( :each ) do
8
+ Rake::Task.clear
9
+ @project = cpp_task( :executable )
10
+ @expected_generated = Rake::Builder.expand_paths_with_root(
11
+ [
12
+ 'main.o',
13
+ 'rake-builder-testfile.txt',
14
+ @project.makedepend_file,
15
+ @project.target
16
+ ],
17
+ SPEC_PATH
18
+ )
19
+ end
20
+
21
+ after( :each ) do
22
+ Rake::Task[ 'clean' ].execute
23
+ end
24
+
25
+ it 'lists generated files, with a method' do
26
+ @project.generated_files.should =~ @expected_generated
27
+ end
28
+
29
+ it 'lists generated files, via the task' do
30
+ output = capturing_output do
31
+ Rake::Task[ 'generated_files' ].execute
32
+ end
33
+ eval( output ).should =~ @expected_generated
34
+ end
35
+
36
+ it 'removes generated files with \'clean\'' do
37
+ Rake::Task[ 'run' ].invoke
38
+ @expected_generated.each do |f|
39
+ exist?( f ).should be_true
40
+ end
41
+ Rake::Task[ 'clean' ].invoke
42
+ @expected_generated.each do |f|
43
+ exist?( f ).should be_false
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ describe 'when adding generated files' do
50
+
51
+ include RakeBuilderHelper
52
+
53
+ before( :each ) do
54
+ @file = 'foobar.txt'
55
+ @file_with_path = Rake::Builder.expand_path_with_root( @file, SPEC_PATH )
56
+ end
57
+
58
+ it 'includes added files' do
59
+ @project = cpp_task( :executable ) do |app|
60
+ app.generated_files << @file_with_path
61
+ end
62
+ @project.generated_files.include?( @file_with_path ).should be_true
63
+ end
64
+
65
+ it 'expands the paths of added files' do
66
+ @project = cpp_task( :executable ) do |app|
67
+ app.generated_files << @file
68
+ end
69
+ @project.generated_files.include?( @file_with_path ).should be_true
70
+ end
71
+
72
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'when using libraries' do
4
+
5
+ include RakeBuilderHelper
6
+
7
+ before( :each ) do
8
+ Rake::Task.clear
9
+ end
10
+
11
+ after( :each ) do
12
+ Rake::Task[ 'clean' ].execute
13
+ end
14
+
15
+ it 'builds if libraries are found' do
16
+ lambda do
17
+ @project = cpp_task( :executable ) do |builder|
18
+ builder.library_dependencies = [ 'gcc' ] # As we're using GCC, libgcc.a should always be present
19
+ end
20
+ Rake::Task[ 'build' ].invoke
21
+ end.should_not raise_error
22
+ end
23
+
24
+ it 'fails to build if libraries are missing' do
25
+ lambda do
26
+ @project = cpp_task( :executable ) do |builder|
27
+ builder.library_dependencies = [ 'library_that_doesnt_exist' ]
28
+ end
29
+ Rake::Task[ 'build' ].invoke
30
+ end.should raise_error( Rake::BuildFailureError )
31
+ end
32
+
33
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'the logger' do
4
+
5
+ it 'can be read' do
6
+ builder = Rake::Builder.new do |builder|
7
+ builder.source_search_paths = [ 'cpp_project' ]
8
+ end
9
+ builder.logger.should_not be_nil
10
+ end
11
+
12
+ it 'can be set' do
13
+ builder = Rake::Builder.new do |builder|
14
+ builder.source_search_paths = [ 'cpp_project' ]
15
+ end
16
+ lambda do
17
+ builder.logger = Logger.new( STDOUT )
18
+ end.should_not raise_exception
19
+ end
20
+
21
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ PATHS_SPEC_PATH = File.expand_path( File.dirname(__FILE__) )
4
+
5
+ describe 'when creating tasks' do
6
+
7
+ before( :each ) do
8
+ Rake::Task.clear
9
+ end
10
+
11
+ it 'remembers the Rakefile path' do
12
+ builder = Rake::Builder.new do |builder|
13
+ builder.source_search_paths = [ 'cpp_project' ]
14
+ end
15
+ builder.rakefile_path.should == PATHS_SPEC_PATH
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,99 @@
1
+ require 'spec'
2
+ require File.dirname(__FILE__) + '/../lib/rake/builder'
3
+
4
+ SPEC_PATH = File.expand_path( File.dirname(__FILE__) )
5
+
6
+ module RakeBuilderHelper
7
+
8
+ TARGET = {
9
+ :executable => 'the_executable',
10
+ :static_library => 'libthe_static_library.a',
11
+ :shared_library => 'libthe_dynamic_library.so',
12
+ }
13
+
14
+ def cpp_task( type, namespace = nil )
15
+ Rake::Builder.new do |builder|
16
+ builder.programming_language = 'c++'
17
+ builder.target = TARGET[ type ]
18
+ builder.task_namespace = namespace
19
+ builder.source_search_paths = [ 'cpp_project' ]
20
+ builder.header_search_paths = [ 'cpp_project' ]
21
+ builder.generated_files << 'rake-builder-testfile.txt'
22
+ yield builder if block_given?
23
+ end
24
+ end
25
+
26
+ def c_task( type, namespace = nil )
27
+ Rake::Builder.new do |builder|
28
+ builder.programming_language = 'c'
29
+ builder.target = TARGET[ type ]
30
+ builder.task_namespace = namespace
31
+ builder.source_search_paths = [ 'c_project' ]
32
+ builder.header_search_paths = [ 'c_project' ]
33
+ builder.generated_files << 'rake-c-testfile.txt'
34
+ yield builder if block_given?
35
+ end
36
+ end
37
+
38
+ def touch( file )
39
+ `touch #{file}`
40
+ end
41
+
42
+ def exist?( file )
43
+ File.exist? file
44
+ end
45
+
46
+ def task_names
47
+ Rake::Task.tasks.map( &:to_s )
48
+ end
49
+
50
+ def default_tasks
51
+ [ 'build', 'clean', 'compile', 'load_makedepend' ]
52
+ end
53
+
54
+ def expected_tasks( extras, scope = nil )
55
+ t = scoped_tasks( default_tasks, scope )
56
+ t += extras
57
+ t << if scope.nil?
58
+ 'default'
59
+ else
60
+ scope
61
+ end
62
+ t
63
+ end
64
+
65
+ def scoped_tasks( tasks, scope )
66
+ return tasks if scope.nil?
67
+ tasks.map{ |t| "#{scope}:#{t}" }
68
+ end
69
+
70
+ def capturing_output
71
+ output = StringIO.new
72
+ $stdout = output
73
+ yield
74
+ output.string
75
+ ensure
76
+ $stdout = STDOUT
77
+ end
78
+
79
+ # Most file systems have a 1s resolution
80
+ # Force a wait into the next second around a task
81
+ # So FileTask's out_of_date? will behave correctly
82
+ def isolating_seconds
83
+ sec = Time.now.sec
84
+ yield
85
+ while( Time.now.sec == sec ) do end
86
+ end
87
+
88
+ def touching_temporarily( file, touch_time )
89
+ begin
90
+ atime = File.atime( file )
91
+ mtime = File.mtime( file )
92
+ File.utime( atime, touch_time, file )
93
+ yield
94
+ ensure
95
+ File.utime( atime, mtime, file )
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'when creating tasks' do
4
+
5
+ before( :each ) do
6
+ Rake::Task.clear
7
+ end
8
+
9
+ it 'raises an error when the target is an empty string' do
10
+ lambda do
11
+ Rake::Builder.new do |builder|
12
+ builder.target = ''
13
+ builder.source_search_paths = [ 'cpp_project' ]
14
+ end
15
+ end.should raise_error( RuntimeError )
16
+ end
17
+
18
+ it 'raises an error when the target is set to nil' do
19
+ lambda do
20
+ Rake::Builder.new do |builder|
21
+ builder.target = nil
22
+ builder.source_search_paths = [ 'cpp_project' ]
23
+ end
24
+ end.should raise_error( RuntimeError )
25
+ end
26
+
27
+ it 'sets the target to \'a.out\' if it is not set' do
28
+ builder = Rake::Builder.new do |builder|
29
+ builder.source_search_paths = [ 'cpp_project' ]
30
+ end
31
+ builder.target.should == Rake::Builder.expand_path_with_root( 'a.out', SPEC_PATH )
32
+ end
33
+
34
+ it 'raises an error when the supplied target_type is unknown' do
35
+ lambda do
36
+ project = Rake::Builder.new do |builder|
37
+ builder.target = 'my_prog'
38
+ builder.target_type = :foo
39
+ builder.source_search_paths = [ 'cpp_project' ]
40
+ end
41
+ end.should raise_error
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-builder
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 8
10
+ version: 0.0.8
11
+ platform: ruby
12
+ authors:
13
+ - Joe Yates
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-20 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 49
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 7
34
+ version: 0.8.7
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Provides Rake:Builder, a specific rake TaskLib for building C, C++, Objective-C and Objective-C++ projects
38
+ email: joe.g.yates@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - COPYING
45
+ - README.rdoc
46
+ - lib/rake/builder.rb
47
+ - examples/README.rdoc
48
+ - examples/01_hello_world_cpp/Rakefile
49
+ - examples/02_hello_world_c/Rakefile
50
+ - examples/03_search_paths/Rakefile
51
+ - examples/04_zlib/Rakefile
52
+ - examples/05_tests/Rakefile
53
+ - examples/06_hello_world_objective_c/Rakefile
54
+ files:
55
+ - CHANGES
56
+ - COPYING
57
+ - Rakefile
58
+ - README.rdoc
59
+ - lib/rake/builder.rb
60
+ - examples/03_search_paths/include/main.h
61
+ - examples/04_zlib/include/main.h
62
+ - examples/05_tests/include/main.h
63
+ - examples/05_tests/include/units.h
64
+ - examples/02_hello_world_c/main.c
65
+ - examples/04_zlib/src/main.c
66
+ - examples/01_hello_world_cpp/main.cpp
67
+ - examples/03_search_paths/src/main.cpp
68
+ - examples/05_tests/src/main.cpp
69
+ - examples/05_tests/src/units.cpp
70
+ - examples/05_tests/test/test_unit.cpp
71
+ - examples/06_hello_world_objective_c/main.m
72
+ - examples/README.rdoc
73
+ - examples/01_hello_world_cpp/Rakefile
74
+ - examples/02_hello_world_c/Rakefile
75
+ - examples/03_search_paths/Rakefile
76
+ - examples/04_zlib/Rakefile
77
+ - examples/05_tests/Rakefile
78
+ - examples/06_hello_world_objective_c/Rakefile
79
+ - spec/c_project/main.c
80
+ - spec/c_project/main.h
81
+ - spec/c_project_spec.rb
82
+ - spec/cpp_project/main.cpp
83
+ - spec/cpp_project/main.h
84
+ - spec/cpp_project_spec.rb
85
+ - spec/dependencies_spec.rb
86
+ - spec/generated_files_spec.rb
87
+ - spec/libraries_spec.rb
88
+ - spec/logger_spec.rb
89
+ - spec/paths_spec.rb
90
+ - spec/spec_helper.rb
91
+ - spec/target_spec.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/joeyates/rake-builder
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --quiet
99
+ - --main
100
+ - README.rdoc
101
+ - --inline-source
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.3.7
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Rake for C/C++ Projects
129
+ test_files:
130
+ - spec/c_project/main.c
131
+ - spec/c_project/main.h
132
+ - spec/c_project_spec.rb
133
+ - spec/cpp_project/main.cpp
134
+ - spec/cpp_project/main.h
135
+ - spec/cpp_project_spec.rb
136
+ - spec/dependencies_spec.rb
137
+ - spec/generated_files_spec.rb
138
+ - spec/libraries_spec.rb
139
+ - spec/logger_spec.rb
140
+ - spec/paths_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/target_spec.rb