Class: Gem::Compiler
- Inherits:
-
Object
- Object
- Gem::Compiler
- Includes:
- UserInteraction
- Defined in:
- lib/rubygems/compiler/version.rb,
lib/rubygems/compiler.rb
Defined Under Namespace
Classes: CompilerError
Constant Summary collapse
- VERSION =
"0.4.0"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target_dir ⇒ Object
readonly
Returns the value of attribute target_dir.
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(gemfile, _options = {}) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(gemfile, _options = {}) ⇒ Compiler
Returns a new instance of Compiler.
20 21 22 23 24 |
# File 'lib/rubygems/compiler.rb', line 20 def initialize(gemfile, = {}) @gemfile = gemfile @output_dir = .delete(:output) = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/rubygems/compiler.rb', line 18 def end |
#target_dir ⇒ Object (readonly)
Returns the value of attribute target_dir.
18 19 20 |
# File 'lib/rubygems/compiler.rb', line 18 def target_dir @target_dir end |
Instance Method Details
#compile ⇒ Object
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubygems/compiler.rb', line 26 def compile unpack # build extensions installer.build_extensions # determine build artifacts from require_paths dlext = RbConfig::CONFIG["DLEXT"] lib_dirs = installer.spec.require_paths.join(",") artifacts = Dir.glob("#{target_dir}/{#{lib_dirs}}/**/*.#{dlext}") # build a new gemspec from the original one gemspec = installer.spec.dup # remove any non-existing files if [:prune] gemspec.files.reject! { |f| !File.exist?("#{target_dir}/#{f}") } end # add discovered artifacts artifacts.each do |path| # path needs to be relative to target_dir file = path.gsub("#{target_dir}/", "") debug "Adding '#{file}' to gemspec" gemspec.files.push file end # clear out extensions from gemspec gemspec.extensions.clear # adjust platform gemspec.platform = Gem::Platform::CURRENT # build new gem output_gem = nil Dir.chdir target_dir do output_gem = if defined?(Gem::Builder) Gem::Builder.new(gemspec).build else Gem::Package.build(gemspec) end end unless output_gem raise CompilerError, "There was a problem building the gem." end # move the built gem to the original output directory FileUtils.mv File.join(target_dir, output_gem), @output_dir cleanup # return the path of the gem output_gem end |