Sha256: 889158864cc2569b1ae25cdf91074ade8fece017dc43c018fe85df8e921d4c3a

Contents?: true

Size: 1.83 KB

Versions: 9

Compression:

Stored size: 1.83 KB

Contents

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

require 'pathname'

require_relative "compiler_config"

module Rake
  class BaseExtensionTask < TaskLib

    attr_accessor :name
    attr_accessor :gem_spec
    attr_accessor :tmp_dir
    attr_accessor :ext_dir
    attr_accessor :lib_dir
    attr_accessor :config_options
    attr_accessor :source_pattern
    attr_accessor :extra_options
    attr_accessor :extra_sources
    attr_writer :platform

    def platform
      @platform ||= RUBY_PLATFORM
    end

    def initialize(name = nil, gem_spec = nil)
      init(name, gem_spec)
      yield self if block_given?
      define
    end

    def init(name = nil, gem_spec = nil)
      @name = name
      @gem_spec = gem_spec
      @tmp_dir = 'tmp'
      @ext_dir = "ext/#{@name}"
      @lib_dir = 'lib'
      if @name and File.dirname(@name.to_s) != "."
        @lib_dir += "/#{File.dirname(@name.to_s)}"
      end
      @config_options = []
      @extra_options = ARGV.select { |i| i =~ /\A--?/ }
      @extra_sources = FileList[]
    end

    def define
      fail "Extension name must be provided." if @name.nil?
      @name = @name.to_s

      define_compile_tasks
    end

    private

    def define_compile_tasks
      raise NotImplementedError
    end

    def binary(platform = nil)
      ext = case platform
        when /darwin/
          'bundle'
        when /mingw|mswin|linux/
          'so'
        when /java/
          'jar'
        else
          RbConfig::CONFIG['DLEXT']
      end
      "#{@name}.#{ext}"
    end

    def source_files
      FileList["#{@ext_dir}/#{@source_pattern}"] + @extra_sources
    end

    def warn_once(message)
      @@already_warned ||= false
      return if @@already_warned
      @@already_warned = true
      warn message
    end

    def windows?
      Rake.application.windows?
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rake-compiler-1.2.9 lib/rake/baseextensiontask.rb
rake-compiler-1.2.8 lib/rake/baseextensiontask.rb
rake-compiler-1.2.7 lib/rake/baseextensiontask.rb
rake-compiler-1.2.6 lib/rake/baseextensiontask.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/rake-compiler-1.2.5/lib/rake/baseextensiontask.rb
rake-compiler-1.2.5 lib/rake/baseextensiontask.rb
rake-compiler-1.2.4 lib/rake/baseextensiontask.rb
rake-compiler-1.2.3 lib/rake/baseextensiontask.rb
rake-compiler-1.2.2 lib/rake/baseextensiontask.rb