diff options
author | James Tucker <jftucker@gmail.com> | 2023-03-06 16:52:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-07 09:52:53 +0900 |
commit | f845901f79681ddee8d387c20212585dee494990 (patch) | |
tree | 4a66f3617bc52c3c8f98fa07a3096793dc567e28 | |
parent | 08cffbc440566b56ab8110f85b10129b3212dcb3 (diff) | |
download | rake-compiler-f845901f79681ddee8d387c20212585dee494990.tar.gz |
baseextensiontask: provide an API to allow for dynamic sources (#211)
If a build wishes to generate some of the extension source files then
the pattern input is insufficient. Provide a place to stash an
additional FileList that will then become a dependency of the compile
tasks.
Example:
```ruby
file 'ext/libfoo/generated.c' do |t|
open(t.name, 'w+) { |f| f << '#include <foo.h>' }
end
Rake::ExtensionTask.new('foo') do |ext|
ext.extra_sources << 'generated.c'
end
```
-rw-r--r-- | lib/rake/baseextensiontask.rb | 4 | ||||
-rw-r--r-- | spec/lib/rake/extensiontask_spec.rb | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/rake/baseextensiontask.rb b/lib/rake/baseextensiontask.rb index 063a555..7b294ad 100644 --- a/lib/rake/baseextensiontask.rb +++ b/lib/rake/baseextensiontask.rb @@ -18,6 +18,7 @@ module Rake attr_accessor :config_options attr_accessor :source_pattern attr_accessor :extra_options + attr_accessor :extra_sources attr_writer :platform def platform @@ -41,6 +42,7 @@ module Rake end @config_options = [] @extra_options = ARGV.select { |i| i =~ /\A--?/ } + @extra_sources = FileList[] end def define @@ -71,7 +73,7 @@ module Rake end def source_files - FileList["#{@ext_dir}/#{@source_pattern}"] + FileList["#{@ext_dir}/#{@source_pattern}"] + @extra_sources end def warn_once(message) diff --git a/spec/lib/rake/extensiontask_spec.rb b/spec/lib/rake/extensiontask_spec.rb index 1c4c9bb..ba87a92 100644 --- a/spec/lib/rake/extensiontask_spec.rb +++ b/spec/lib/rake/extensiontask_spec.rb @@ -58,6 +58,15 @@ describe Rake::ExtensionTask do end ext.platform.should == 'universal-foo-bar-10.5' end + + it 'should allow extra sources to be added' do + ext = Rake::ExtensionTask.new('extension_one') do |ext| + ext.extra_sources << 'extra.c' + end + ext.extra_sources.should include('extra.c') + # Private API between the base task and the extension task + ext.send(:source_files).should include('extra.c') + end end end |