From f845901f79681ddee8d387c20212585dee494990 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Mon, 6 Mar 2023 16:52:53 -0800 Subject: 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 ' } end Rake::ExtensionTask.new('foo') do |ext| ext.extra_sources << 'generated.c' end ``` --- lib/rake/baseextensiontask.rb | 4 +++- spec/lib/rake/extensiontask_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1