Class: Gem::Commands::CompileCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/compile_command.rb

Constant Summary collapse

ABIs =
{
    "ruby"   => :ruby,
    "strict" => :strict,
    "none"   => :none
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeCompileCommand

Returns a new instance of CompileCommand.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rubygems/commands/compile_command.rb', line 13

def initialize
  defaults = {
    output: Dir.pwd,
    abi_lock: :ruby
  }

  super "compile", "Create binary pre-compiled gem", defaults

  add_option "-O", "--output DIR", "Directory where binary will be stored" do |value, options|
    options[:output] = File.expand_path(value, Dir.pwd)
  end

  add_option "--include-shared-dir DIR", "Additional directory for shared libraries" do |value, options|
    options[:include_shared_dir] = value
  end

  add_option "--prune", "Clean non-existing files during re-packaging" do |value, options|
    options[:prune] = true
  end

  add_option "--abi-lock MODE",
    "Lock to version of Ruby (ruby, strict, none)" do |value, options|

    mode = ABIs[value]
    unless mode
      valid = ABIs.keys.sort
      raise OptionParser::InvalidArgument, "#{value} (#{valid.join ', '} are valid)"
    end

    options[:abi_lock] = mode
  end

  add_option "-N", "--no-abi-lock", "Do not lock compiled Gem to Ruby's ABI (same as --abi-lock=none)" do |value, options|
    options[:abi_lock] = :none
  end

  add_option "-S", "--strip [CMD]", "Strip symbols from generated binaries" do |value, options|
    if value.nil? || value.empty?
      options[:strip] = RbConfig::CONFIG["STRIP"]
    else
      options[:strip] = value
    end
  end
end

Instance Method Details

#argumentsObject



58
59
60
# File 'lib/rubygems/commands/compile_command.rb', line 58

def arguments
  "GEMFILE       path to the gem file to compile"
end

#executeObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rubygems/commands/compile_command.rb', line 66

def execute
  gemfile = options[:args].shift

  # no gem, no binary
  unless gemfile
    raise Gem::CommandLineError,
          "Please specify a gem file on the command line (e.g. #{program_name} foo-0.1.0.gem)"
  end

  require "rubygems/compiler"

  compiler = Gem::Compiler.new(gemfile, options)
  compiler.compile
end

#usageObject



62
63
64
# File 'lib/rubygems/commands/compile_command.rb', line 62

def usage
  "#{program_name} GEMFILE"
end