Sha256: bc1a34711de0c26e88394e484422b12351ccede0e0c487e90ae2705877c2052e

Contents?: true

Size: 1.32 KB

Versions: 22

Compression:

Stored size: 1.32 KB

Contents

require 'rake'
require 'rake/tasklib'
require 'rake/clean'

module FFI
  module Compiler
    class ExportTask < Rake::TaskLib

      def initialize(rb_dir, out_dir, options = {})
        @rb_dir = rb_dir
        @out_dir = out_dir
        @gem_spec = options[:gem_spec]
        @exports = []
        
        if block_given?
          yield self
          define_tasks!
        end
      end

      def export(rb_file)
        @exports << { :rb_file => File.join(@rb_dir, rb_file), :header => File.join(@out_dir, File.basename(rb_file).sub(/\.rb$/, '.h')) }
      end

      def export_all
        Dir["#@rb_dir/**/*rb"].each do |rb_file|
          @exports << { :rb_file => rb_file, :header => File.join(@out_dir, File.basename(rb_file).sub(/\.rb$/, '.h')) }
        end
      end

      private
      def define_tasks!
        @exports.each do |e|
          file e[:header] => [ e[:rb_file] ] do |t|
            ruby "-I#{File.join(File.dirname(__FILE__), 'fake_ffi')} #{File.join(File.dirname(__FILE__), 'exporter.rb')} #{t.prerequisites[0]} #{t.name}"
          end
          CLEAN.include(e[:header])

          desc "Export API headers"
          task :api_headers => [ e[:header] ]
          @gem_spec.files << e[:header] unless @gem_spec.nil?
        end

        task :gem => [ :api_headers ] unless @gem_spec.nil?
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/export_task.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/export_task.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/export_task.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/ffi-compiler-1.3.2/lib/ffi-compiler/export_task.rb
ffi-compiler-1.3.2 lib/ffi-compiler/export_task.rb
ffi-compiler-1.3.1 lib/ffi-compiler/export_task.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/export_task.rb
ffi-compiler2-2.3.0 lib/ffi-compiler/export_task.rb
ffi-compiler2-2.2.2 lib/ffi-compiler/export_task.rb
ffi-compiler2-2.2.1 lib/ffi-compiler/export_task.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/export_task.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/export_task.rb
ffi-compiler2-2.0.1 lib/ffi-compiler/export_task.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/ffi-compiler2-2.0.0/lib/ffi-compiler/export_task.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/ffi-compiler2-2.0.0/lib/ffi-compiler/export_task.rb
ffi-compiler-1.0.1 lib/ffi-compiler/export_task.rb
ffi-compiler-1.0.0 lib/ffi-compiler/export_task.rb
ffi-compiler2-2.0.0 lib/ffi-compiler/export_task.rb
ffi-compiler-0.1.3 lib/ffi-compiler/export_task.rb
ffi-compiler-0.1.2 lib/ffi-compiler/export_task.rb