rake-builder 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +49 -22
- data/lib/rake/builder.rb +120 -23
- data/spec/cpp_project_spec.rb +8 -6
- data/spec/generated_files_spec.rb +3 -5
- data/spec/local_config_spec.rb +70 -0
- data/spec/objective_c_project/main.h +1 -0
- data/spec/objective_c_project/main.m +18 -0
- data/spec/objective_c_project_spec.rb +78 -0
- data/spec/spec_helper.rb +15 -1
- metadata +12 -4
data/README.rdoc
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
rake-builder builds C, C++, Objective-C and Objective-C++
|
4
4
|
projects.
|
5
|
-
Project files are dicovered accoring to indicated paths
|
6
|
-
and or flie globs.
|
7
|
-
|
8
|
-
Projects are managed and built via a 'Rakefile'.
|
9
5
|
|
10
6
|
Here is a typical example:
|
11
7
|
|
@@ -40,18 +36,49 @@ See the 'examples' directory.
|
|
40
36
|
If you've installed the gem system-wide, type the following to go to
|
41
37
|
the correct directory:
|
42
38
|
|
43
|
-
$ cd `gem environment gemdir`/gems/rake-builder
|
39
|
+
$ cd `gem environment gemdir`/gems/rake-builder-nnn
|
40
|
+
$ cd examples
|
41
|
+
|
42
|
+
== Project Configuration
|
43
|
+
|
44
|
+
In order to build on a specific computer, you will need
|
45
|
+
to indicate information like non-standard
|
46
|
+
include paths.
|
47
|
+
|
48
|
+
Rake::Builder collects all such information in one file:
|
49
|
+
'.rake-builder'
|
50
|
+
|
51
|
+
This file should be created in the same
|
52
|
+
directory as the Rakefile.
|
53
|
+
|
54
|
+
The file should be a YAML structure, and must include a version.
|
55
|
+
|
56
|
+
Currently, the following can be configured:
|
57
|
+
* extra include paths: :include_paths
|
58
|
+
|
59
|
+
=== Example '.rake-builder'
|
44
60
|
|
45
|
-
|
61
|
+
---
|
62
|
+
:rake_builder:
|
63
|
+
:config_file:
|
64
|
+
:version: "1.0"
|
65
|
+
:include_paths:
|
66
|
+
- /opt/local/include
|
67
|
+
- /usr/include/c++/4.2.1
|
46
68
|
|
47
|
-
|
69
|
+
= Default Tasks
|
48
70
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
71
|
+
* compile
|
72
|
+
* build
|
73
|
+
* run - executables only
|
74
|
+
* install
|
75
|
+
* clean
|
76
|
+
|
77
|
+
= Installing Headers
|
78
|
+
|
79
|
+
If you install a static library, your headers will also be installed.
|
80
|
+
Ensure that you use file globs, e.g. './include/**/*.h',
|
81
|
+
as these will ensure that your headers are installed in the correct subdirectories.
|
55
82
|
|
56
83
|
= Online
|
57
84
|
|
@@ -59,6 +86,12 @@ You can list tasks as follows:
|
|
59
86
|
* Documentation[http://rdoc.info/projects/joeyates/rake-builder]
|
60
87
|
* Gem[http://rubygems.org/gems/rake-builder]
|
61
88
|
|
89
|
+
= Dependencies
|
90
|
+
|
91
|
+
Task dependencies must ensure that out of date files are recreated as needed.
|
92
|
+
|
93
|
+
http://github.com/downloads/joeyates/rake-builder/RakeBuilderDependencyStructure.png
|
94
|
+
|
62
95
|
= Limitations
|
63
96
|
|
64
97
|
== File Modification Times
|
@@ -68,7 +101,7 @@ modification times (see the private method <em>out_of_date?</em>, which returns
|
|
68
101
|
dependency was modified *after* the dependent).
|
69
102
|
Unfortunately, most modern file systems hold modification times in whole
|
70
103
|
seconds. If a dependency and a dependent were modificed during the same second,
|
71
|
-
<b>even if the dependency were modified later</b>, <em>out_of_date?</em>
|
104
|
+
<b>even if the dependency were modified later</b>, <em>out_of_date?</em> returns *false*
|
72
105
|
which is not the correct answer.
|
73
106
|
|
74
107
|
This problem is mostly felt in testing, where file modification times are temporarily
|
@@ -88,17 +121,11 @@ So, if there are two source files with the same name, they will overwrite each o
|
|
88
121
|
|
89
122
|
= Status
|
90
123
|
|
91
|
-
* Builds C and C
|
124
|
+
* Builds C, C++ and Objective-C projects using GCC[http://gcc.gnu.org/].
|
92
125
|
|
93
126
|
= Alternatives
|
94
127
|
|
95
128
|
* make
|
96
129
|
* CMake
|
97
130
|
* Boost.Build
|
98
|
-
* rakepp - another
|
99
|
-
|
100
|
-
= TODO
|
101
|
-
|
102
|
-
* Objective-C++ projects
|
103
|
-
* pre-compiled headers
|
104
|
-
* parallel builds
|
131
|
+
* rakepp - another customisation of Rake for C++ projects
|
data/lib/rake/builder.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems' if RUBY_VERSION < '1.9'
|
|
2
2
|
require 'logger'
|
3
3
|
require 'rake'
|
4
4
|
require 'rake/tasklib'
|
5
|
-
require 'rake/loaders/makefile'
|
6
5
|
|
7
6
|
module Rake
|
8
7
|
|
@@ -33,7 +32,7 @@ module Rake
|
|
33
32
|
module VERSION #:nodoc:
|
34
33
|
MAJOR = 0
|
35
34
|
MINOR = 0
|
36
|
-
TINY =
|
35
|
+
TINY = 10
|
37
36
|
|
38
37
|
STRING = [ MAJOR, MINOR, TINY ].join('.')
|
39
38
|
end
|
@@ -107,10 +106,23 @@ module Rake
|
|
107
106
|
# It is the file which calls to Rake::Builder.new
|
108
107
|
attr_reader :rakefile
|
109
108
|
|
110
|
-
# Directories
|
109
|
+
# Directories/file globs to search for project source files
|
111
110
|
attr_accessor :source_search_paths
|
112
111
|
|
113
|
-
# Directories
|
112
|
+
# Directories/file globs to search for header files
|
113
|
+
# When static libraries are installed,
|
114
|
+
# headers are install too.
|
115
|
+
# During installation, the destination path is:
|
116
|
+
# /usr/local/include + the relative path
|
117
|
+
# This 'relative path' is calculated as follows:
|
118
|
+
# 1. Named files are installed directly under /usr/local/include
|
119
|
+
# 2. Files found by directory are also installed directly under /usr/local/include
|
120
|
+
# 3. Files found by glob have the fixed part of the glob removed and
|
121
|
+
# the relative path calculated:
|
122
|
+
# E.g. files found with './include/**/*' will have './include' removed to calculate the
|
123
|
+
# relative path.
|
124
|
+
# So, ./include/my_lib/foo.h' produces a relative path of 'my_lib'
|
125
|
+
# so the file will be installed as '/usr/local/include/my_lib/foo.h'
|
114
126
|
attr_accessor :header_search_paths
|
115
127
|
|
116
128
|
# (Optional) namespace for tasks
|
@@ -161,6 +173,8 @@ module Rake
|
|
161
173
|
define_default
|
162
174
|
end
|
163
175
|
|
176
|
+
private
|
177
|
+
|
164
178
|
# Source files found in source_search_paths
|
165
179
|
def source_files
|
166
180
|
@source_fies ||= find_files( @source_search_paths, @source_file_extension )
|
@@ -171,15 +185,12 @@ module Rake
|
|
171
185
|
@header_files ||= find_files( @header_search_paths, @header_file_extension )
|
172
186
|
end
|
173
187
|
|
174
|
-
private
|
175
|
-
|
176
188
|
def initialize_attributes
|
177
189
|
@logger = Logger.new( STDOUT )
|
178
190
|
@logger.level = Logger::UNKNOWN
|
179
191
|
@programming_language = 'c++'
|
180
192
|
@header_file_extension = 'h'
|
181
193
|
@objects_path = @rakefile_path.dup
|
182
|
-
@generated_files = []
|
183
194
|
@library_paths = []
|
184
195
|
@library_dependencies = []
|
185
196
|
@target_prerequisites = []
|
@@ -211,7 +222,6 @@ module Rake
|
|
211
222
|
@compilation_options ||= ''
|
212
223
|
@linker_options ||= ''
|
213
224
|
@include_paths ||= @header_search_paths.dup
|
214
|
-
@include_paths = Rake::Builder.expand_paths_with_root( @include_paths, @rakefile_path )
|
215
225
|
@generated_files = Rake::Builder.expand_paths_with_root( @generated_files, @rakefile_path )
|
216
226
|
|
217
227
|
@default_task ||= :build
|
@@ -219,9 +229,32 @@ module Rake
|
|
219
229
|
|
220
230
|
@makedepend_file = @objects_path + '/.' + target_basename + '.depend.mf'
|
221
231
|
|
232
|
+
load_local_config
|
233
|
+
|
234
|
+
@include_paths = Rake::Builder.expand_paths_with_root( @include_paths, @rakefile_path )
|
235
|
+
|
222
236
|
raise "No source files found" if source_files.length == 0
|
223
237
|
end
|
224
238
|
|
239
|
+
def local_config
|
240
|
+
filename = '.rake-builder'
|
241
|
+
filename += '.' + @task_namespace.to_s if @task_namespace
|
242
|
+
Rake::Builder.expand_path_with_root( filename, @rakefile_path )
|
243
|
+
end
|
244
|
+
|
245
|
+
def load_local_config
|
246
|
+
return if ! File.exist?( local_config )
|
247
|
+
|
248
|
+
config = YAML.load_file( local_config )
|
249
|
+
|
250
|
+
version = config[ :rake_builder ][ :config_file ][ :version ]
|
251
|
+
raise "Config file version missing" if version.nil?
|
252
|
+
|
253
|
+
@include_paths += config[ :include_paths ] if config[ :include_paths ]
|
254
|
+
rescue => e
|
255
|
+
raise "#{__FILE__}:#{__LINE__}: Failed to load local config file '#{ local_config }': #{ e.message }"
|
256
|
+
end
|
257
|
+
|
225
258
|
def define_tasks
|
226
259
|
if @task_namespace
|
227
260
|
namespace @task_namespace do
|
@@ -255,7 +288,7 @@ module Rake
|
|
255
288
|
FileTaskAlias.define_task( :build, @target )
|
256
289
|
|
257
290
|
desc "Build '#{ target_basename }'"
|
258
|
-
file @target => [ scoped_task( :compile ),
|
291
|
+
file @target => [ scoped_task( :compile ), *@target_prerequisites ] do |t|
|
259
292
|
shell "rm -f #{ t.name }"
|
260
293
|
case @target_type
|
261
294
|
when :executable
|
@@ -290,7 +323,11 @@ module Rake
|
|
290
323
|
shell command
|
291
324
|
end
|
292
325
|
|
293
|
-
|
326
|
+
# Reimplemented mkdepend file loading to make objects depend on
|
327
|
+
# sources with the correct paths:
|
328
|
+
# the standard rake mkdepend loader doesn't do what we want,
|
329
|
+
# as it assumes files will be compiled in their own directory.
|
330
|
+
task :load_makedepend => @makedepend_file do
|
294
331
|
object_to_source = source_files.inject( {} ) do |memo, source|
|
295
332
|
mapped_object = source.gsub( '.' + @source_file_extension, '.o' )
|
296
333
|
memo[ mapped_object ] = source
|
@@ -300,8 +337,8 @@ module Rake
|
|
300
337
|
next if line !~ /:\s/
|
301
338
|
mapped_object_file = $`
|
302
339
|
header_file = $'.gsub( "\n", '' )
|
303
|
-
# Why does it work
|
304
|
-
# if I make the object (not the source) depend on the header
|
340
|
+
# TODO: Why does it work,
|
341
|
+
# if I make the object (not the source) depend on the header?
|
305
342
|
source_file = object_to_source[ mapped_object_file ]
|
306
343
|
object_file = object_path( source_file )
|
307
344
|
object_file_task = Rake.application[ object_file ]
|
@@ -309,7 +346,7 @@ module Rake
|
|
309
346
|
end
|
310
347
|
end
|
311
348
|
|
312
|
-
desc
|
349
|
+
desc "List generated files (which are removed with 'rake #{ scoped_task( :clean ) }')"
|
313
350
|
task :generated_files do
|
314
351
|
puts @generated_files.inspect
|
315
352
|
end
|
@@ -329,11 +366,8 @@ module Rake
|
|
329
366
|
desc "Install '#{ target_basename }' in '#{ @install_path }'"
|
330
367
|
task :install, [] => [ scoped_task( :build ) ] do
|
331
368
|
destination = File.join( @install_path, target_basename )
|
332
|
-
|
333
|
-
|
334
|
-
rescue Errno::EACCES => e
|
335
|
-
raise "You do not have premission to install '#{ target_basename }' in '#{ @install_path }'\nTry\n $ sudo rake install"
|
336
|
-
end
|
369
|
+
install( @target, destination )
|
370
|
+
install_headers if @target_type == :static_library
|
337
371
|
end
|
338
372
|
|
339
373
|
desc "Uninstall '#{ target_basename }' from '#{ @install_path }'"
|
@@ -413,9 +447,16 @@ module Rake
|
|
413
447
|
# Lists of files
|
414
448
|
|
415
449
|
def find_files( paths, extension )
|
416
|
-
files = paths.reduce( [] ) do |memo, path|
|
417
|
-
|
418
|
-
|
450
|
+
files = paths.reduce( [] ) do | memo, path |
|
451
|
+
case
|
452
|
+
when File.file?( path )
|
453
|
+
files = FileList[ path ]
|
454
|
+
when ( path =~ /[\*\?]/ )
|
455
|
+
files = FileList[ path ]
|
456
|
+
else
|
457
|
+
files = FileList[ path + '/*.' + extension ]
|
458
|
+
end
|
459
|
+
memo + files
|
419
460
|
end
|
420
461
|
Rake::Builder.expand_paths_with_root( files, @rakefile_path )
|
421
462
|
end
|
@@ -434,11 +475,67 @@ module Rake
|
|
434
475
|
end
|
435
476
|
|
436
477
|
def library_paths_list
|
437
|
-
@library_paths.map { |
|
478
|
+
@library_paths.map { | path | "-L#{ path }" }.join( " " )
|
438
479
|
end
|
439
480
|
|
440
481
|
def library_dependencies_list
|
441
|
-
@library_dependencies.map { |
|
482
|
+
@library_dependencies.map { | lib | "-l#{ lib }" }.join( " " )
|
483
|
+
end
|
484
|
+
|
485
|
+
def install_headers
|
486
|
+
# TODO: make install_headers_path a configuration option
|
487
|
+
install_headers_path = '/usr/local/include'
|
488
|
+
|
489
|
+
installable_headers.each do | installable_header |
|
490
|
+
destination_path = File.join( install_headers_path, installable_header[ :relative_path ] )
|
491
|
+
begin
|
492
|
+
`mkdir -p '#{ destination_path }'`
|
493
|
+
rescue Errno::EACCES => e
|
494
|
+
raise "Permission denied to created directory '#{ destination_path }'"
|
495
|
+
end
|
496
|
+
install( installable_header[ :source_file ], destination_path )
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
def subtract_path_prefix( prefix, path )
|
501
|
+
path[ prefix.size .. -1 ]
|
502
|
+
end
|
503
|
+
|
504
|
+
def installable_headers
|
505
|
+
@header_search_paths.reduce( [] ) do | memo, search |
|
506
|
+
non_glob_search = ( search.match( /^([^\*\?]*)/ ) )[ 1 ]
|
507
|
+
case
|
508
|
+
when ( non_glob_search !~ /#{ @rakefile_path }/ )
|
509
|
+
# Skip paths that are not inside the project
|
510
|
+
when File.file?( search )
|
511
|
+
full_path = Rake::Builder.expand_path_with_root( search, @rakefile_path )
|
512
|
+
memo << { :source_file => search, :relative_path => '' }
|
513
|
+
when File.directory?( search )
|
514
|
+
FileList[ search + '/*.' + @header_file_extension ].each do | pathname |
|
515
|
+
full_path = Rake::Builder.expand_path_with_root( pathname, @rakefile_path )
|
516
|
+
memo << { :source_file => pathname, :relative_path => '' }
|
517
|
+
end
|
518
|
+
when ( search =~ /[\*\?]/ )
|
519
|
+
FileList[ search ].each do | pathname |
|
520
|
+
full_path = Rake::Builder.expand_path_with_root( pathname, @rakefile_path )
|
521
|
+
directory = File.dirname( full_path )
|
522
|
+
relative = subtract_path_prefix( non_glob_search, directory )
|
523
|
+
memo << { :source_file => pathname, :relative_path => relative }
|
524
|
+
end
|
525
|
+
else
|
526
|
+
$stderr.puts "Bad search path: '${ search }'"
|
527
|
+
end
|
528
|
+
memo
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def install( source_pathname, destination_path )
|
533
|
+
begin
|
534
|
+
shell "cp '#{ source_pathname }' '#{ destination_path }'", Logger::INFO
|
535
|
+
rescue Errno::EACCES => e
|
536
|
+
source_filename = File.basename( source_pathname ) rescue '????'
|
537
|
+
raise "You do not have permission to install '#{ source_filename }' to '#{ destination_path }'\nTry\n $ sudo rake install"
|
538
|
+
end
|
442
539
|
end
|
443
540
|
|
444
541
|
def shell( command, log_level = Logger::ERROR )
|
data/spec/cpp_project_spec.rb
CHANGED
@@ -5,11 +5,11 @@ describe 'when building an executable' do
|
|
5
5
|
include RakeBuilderHelper
|
6
6
|
|
7
7
|
before( :all ) do
|
8
|
-
@test_output_file = Rake::Builder.expand_path_with_root(
|
8
|
+
@test_output_file = Rake::Builder.expand_path_with_root(
|
9
|
+
'rake-builder-testfile.txt', SPEC_PATH )
|
9
10
|
@expected_target = Rake::Builder.expand_path_with_root(
|
10
|
-
|
11
|
-
|
12
|
-
)
|
11
|
+
RakeBuilderHelper::TARGET[ :executable ],
|
12
|
+
SPEC_PATH )
|
13
13
|
end
|
14
14
|
|
15
15
|
before( :each ) do
|
@@ -43,12 +43,14 @@ describe 'when building an executable' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'finds source files' do
|
46
|
-
expected_sources = Rake::Builder.expand_paths_with_root(
|
46
|
+
expected_sources = Rake::Builder.expand_paths_with_root(
|
47
|
+
[ 'cpp_project/main.cpp' ], SPEC_PATH )
|
47
48
|
@project.source_files.should == expected_sources
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'finds header files' do
|
51
|
-
expected_headers = Rake::Builder.expand_paths_with_root(
|
52
|
+
expected_headers = Rake::Builder.expand_paths_with_root(
|
53
|
+
[ 'cpp_project/main.h' ], SPEC_PATH )
|
52
54
|
@project.header_files.should == expected_headers
|
53
55
|
end
|
54
56
|
|
@@ -12,10 +12,8 @@ describe 'when handling generated files' do
|
|
12
12
|
'main.o',
|
13
13
|
'rake-builder-testfile.txt',
|
14
14
|
@project.makedepend_file,
|
15
|
-
@project.target
|
16
|
-
|
17
|
-
SPEC_PATH
|
18
|
-
)
|
15
|
+
@project.target ],
|
16
|
+
SPEC_PATH )
|
19
17
|
end
|
20
18
|
|
21
19
|
after( :each ) do
|
@@ -28,7 +26,7 @@ describe 'when handling generated files' do
|
|
28
26
|
|
29
27
|
it 'lists generated files, via the task' do
|
30
28
|
output = capturing_output do
|
31
|
-
Rake::Task[ 'generated_files' ].
|
29
|
+
Rake::Task[ 'generated_files' ].invoke
|
32
30
|
end
|
33
31
|
eval( output ).should =~ @expected_generated
|
34
32
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
LOCAL_CONFIG_SPEC_PATH = File.expand_path( File.dirname(__FILE__) )
|
4
|
+
|
5
|
+
describe 'local config files' do
|
6
|
+
|
7
|
+
include RakeBuilderHelper
|
8
|
+
|
9
|
+
before( :each ) do
|
10
|
+
@local_config_file = Rake::Builder.expand_path_with_root( '.rake-builder', LOCAL_CONFIG_SPEC_PATH )
|
11
|
+
@expected_path = "/some/special/path"
|
12
|
+
@config = {:rake_builder=>{:config_file=>{:version=>"1.0"}}, :include_paths=>[ @expected_path ]}
|
13
|
+
`rm -f '#{ @local_config_file }'`
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'works if the\'s no config file' do
|
17
|
+
lambda do
|
18
|
+
@builder = cpp_task( :executable )
|
19
|
+
end.should_not raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'loads the local config file' do
|
23
|
+
save_config
|
24
|
+
@builder = cpp_task( :executable )
|
25
|
+
@builder.include_paths.should include( @expected_path )
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'fails if there\'s no version' do
|
29
|
+
@config[ :rake_builder ][ :config_file ].delete( :version )
|
30
|
+
save_config
|
31
|
+
lambda do
|
32
|
+
@project = cpp_task( :executable )
|
33
|
+
end.should raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'for the default namespace, loads only the \'.rake-builder\' config file' do
|
37
|
+
namespaced_config_path = @local_config_file + '.foo'
|
38
|
+
namespaced_config = @config.dup
|
39
|
+
unexpected_path = '/this/shouldnt/show/up'
|
40
|
+
namespaced_config[ :include_paths ] = [ unexpected_path ]
|
41
|
+
save_config
|
42
|
+
save_config( namespaced_config, namespaced_config_path )
|
43
|
+
@builder = cpp_task( :executable )
|
44
|
+
@builder.include_paths.should include( @expected_path )
|
45
|
+
@builder.include_paths.should_not include( unexpected_path )
|
46
|
+
`rm -f '#{ namespaced_config_path }'`
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'for a particular namespace, loads only that namespace\'s config file' do
|
50
|
+
namespaced_config_path = @local_config_file + '.foo'
|
51
|
+
namespaced_config = @config.dup
|
52
|
+
unexpected_path = '/this/shouldnt/show/up'
|
53
|
+
namespaced_config[ :include_paths ] = [ unexpected_path ]
|
54
|
+
save_config
|
55
|
+
save_config( namespaced_config, namespaced_config_path )
|
56
|
+
@builder = cpp_task( :executable, 'foo' )
|
57
|
+
@builder.include_paths.should_not include( @expected_path )
|
58
|
+
@builder.include_paths.should include( unexpected_path )
|
59
|
+
`rm -f '#{ namespaced_config_path }'`
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def save_config( config = @config, filename = @local_config_file )
|
65
|
+
File.open( filename, 'w' ) do | file |
|
66
|
+
file.write config.to_yaml
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#import "main.h"
|
2
|
+
|
3
|
+
int main(void)
|
4
|
+
{
|
5
|
+
NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ];
|
6
|
+
NSString *text = @"Written by Objective-C";
|
7
|
+
NSString *filename = @"./rake-builder-testfile.txt";
|
8
|
+
NSData *data = [ text dataUsingEncoding: NSASCIIStringEncoding ];
|
9
|
+
NSFileManager *filemanager = [NSFileManager defaultManager];
|
10
|
+
BOOL written = [ filemanager createFileAtPath: filename contents: data attributes: nil ];
|
11
|
+
if( ! written ) {
|
12
|
+
NSLog( @"Failed to write to file" );
|
13
|
+
}
|
14
|
+
|
15
|
+
[ pool release ];
|
16
|
+
|
17
|
+
return 0;
|
18
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'when building an Objective-C executable' do
|
4
|
+
|
5
|
+
include RakeBuilderHelper
|
6
|
+
|
7
|
+
before( :all ) do
|
8
|
+
@test_output_file = Rake::Builder.expand_path_with_root(
|
9
|
+
'rake-builder-testfile.txt', SPEC_PATH )
|
10
|
+
@expected_target = Rake::Builder.expand_path_with_root(
|
11
|
+
RakeBuilderHelper::TARGET[ :executable ],
|
12
|
+
SPEC_PATH )
|
13
|
+
end
|
14
|
+
|
15
|
+
before( :each ) do
|
16
|
+
Rake::Task.clear
|
17
|
+
@project = objective_c_task( :executable )
|
18
|
+
`rm -f #{ @test_output_file }`
|
19
|
+
`rm -f #{ @project.target }`
|
20
|
+
end
|
21
|
+
|
22
|
+
after( :each ) do
|
23
|
+
Rake::Task[ 'clean' ].invoke
|
24
|
+
`rm -f #{ @test_output_file }`
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'knows the target' do
|
28
|
+
@project.target.should == @expected_target
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'builds the target in the objects directory' do
|
32
|
+
File.dirname( @project.target ).should == @project.objects_path
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'knows the project type' do
|
36
|
+
@project.target_type.should == :executable
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'creates the correct tasks' do
|
40
|
+
expected_tasks = expected_tasks( [ @project.target ] )
|
41
|
+
missing_tasks = expected_tasks - task_names
|
42
|
+
missing_tasks.should == []
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'finds source files' do
|
46
|
+
expected_sources = Rake::Builder.expand_paths_with_root(
|
47
|
+
[ 'objective_c_project/main.m' ], SPEC_PATH )
|
48
|
+
@project.source_files.should == expected_sources
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'finds header files' do
|
52
|
+
expected_headers = Rake::Builder.expand_paths_with_root(
|
53
|
+
[ 'objective_c_project/main.h' ], SPEC_PATH )
|
54
|
+
@project.header_files.should == expected_headers
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'builds the program with \'build\'' do
|
58
|
+
Rake::Task[ 'build' ].invoke
|
59
|
+
exist?( @project.target ).should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has a \'run\' task' do
|
63
|
+
Rake::Task[ 'run' ].should_not be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'builds the program with \'run\'' do
|
67
|
+
Rake::Task[ 'run' ].invoke
|
68
|
+
exist?( @project.target ).should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'runs the program with \'run\'' do
|
72
|
+
lambda do
|
73
|
+
Rake::Task[ 'run' ].invoke
|
74
|
+
end.should_not raise_exception
|
75
|
+
exist?( @test_output_file ).should be_true
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'spec'
|
2
|
-
require File.dirname(__FILE__) + '/../lib/rake/builder'
|
2
|
+
require File.expand_path( File.dirname(__FILE__) + '/../lib/rake/builder' )
|
3
3
|
|
4
4
|
SPEC_PATH = File.expand_path( File.dirname(__FILE__) )
|
5
5
|
|
@@ -35,6 +35,20 @@ module RakeBuilderHelper
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def objective_c_task( type, namespace = nil )
|
39
|
+
Rake::Builder.new do |builder|
|
40
|
+
builder.programming_language = 'objective-c'
|
41
|
+
builder.target = TARGET[ type ]
|
42
|
+
builder.task_namespace = namespace
|
43
|
+
builder.source_search_paths = [ 'objective_c_project' ]
|
44
|
+
builder.header_search_paths = [ 'objective_c_project' ]
|
45
|
+
builder.generated_files << 'rake-builder-testfile.txt'
|
46
|
+
builder.library_dependencies = [ 'objc' ]
|
47
|
+
builder.linker_options = '-framework CoreFoundation -framework Foundation'
|
48
|
+
yield builder if block_given?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
38
52
|
def touch( file )
|
39
53
|
`touch #{file}`
|
40
54
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Yates
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-25 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -85,7 +85,11 @@ files:
|
|
85
85
|
- spec/dependencies_spec.rb
|
86
86
|
- spec/generated_files_spec.rb
|
87
87
|
- spec/libraries_spec.rb
|
88
|
+
- spec/local_config_spec.rb
|
88
89
|
- spec/logger_spec.rb
|
90
|
+
- spec/objective_c_project/main.h
|
91
|
+
- spec/objective_c_project/main.m
|
92
|
+
- spec/objective_c_project_spec.rb
|
89
93
|
- spec/paths_spec.rb
|
90
94
|
- spec/spec_helper.rb
|
91
95
|
- spec/target_spec.rb
|
@@ -136,7 +140,11 @@ test_files:
|
|
136
140
|
- spec/dependencies_spec.rb
|
137
141
|
- spec/generated_files_spec.rb
|
138
142
|
- spec/libraries_spec.rb
|
143
|
+
- spec/local_config_spec.rb
|
139
144
|
- spec/logger_spec.rb
|
145
|
+
- spec/objective_c_project/main.h
|
146
|
+
- spec/objective_c_project/main.m
|
147
|
+
- spec/objective_c_project_spec.rb
|
140
148
|
- spec/paths_spec.rb
|
141
149
|
- spec/spec_helper.rb
|
142
150
|
- spec/target_spec.rb
|