Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Add basic support for compile-time options via a yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Oct 20, 2009
1 parent 2aa70b3 commit 793c938
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,4 +1,7 @@
.DS_Store
tmp
pkg
testing/Gemfile
testing/Gemfile
spec/fixtures/very-simple-binary/ext/Makefile
spec/fixtures/very-simple-binary/ext/very-simple-binary.o
spec/fixtures/very-simple-binary/ext/very_simple_binary.bundle
6 changes: 6 additions & 0 deletions lib/bundler/commands/bundle_command.rb
Expand Up @@ -26,6 +26,12 @@ def initialize
add_option('--list', "List all gems that are part of the active bundle") do
options[:list] = true
end

add_option('-b', '--build-options OPTION_FILE', "Specify a path to a yml file with build options for binary gems") do |option_file, options|
if File.exist?(option_file)
options[:build_options] = YAML.load_file(option_file)
end
end
end

def usage
Expand Down
13 changes: 7 additions & 6 deletions lib/bundler/environment.rb
Expand Up @@ -53,12 +53,13 @@ def install(options = {})
no_bundle = dependencies.select { |dep| !dep.bundle }

repository.install(gem_dependencies, sources,
:rubygems => rubygems,
:system_gems => system_gems,
:manifest => filename,
:update => update,
:cached => cached,
:no_bundle => no_bundle.map { |dep| dep.name }
:rubygems => rubygems,
:system_gems => system_gems,
:manifest => filename,
:update => update,
:cached => cached,
:build_options => options[:build_options],
:no_bundle => no_bundle.map { |dep| dep.name }
)
Bundler.logger.info "Done."
end
Expand Down
6 changes: 6 additions & 0 deletions lib/bundler/repository.rb
Expand Up @@ -135,6 +135,10 @@ def expand_gemfile(spec, options)

gemfile = @path.join("cache", "#{spec.full_name}.gem").to_s

if build_args = options[:build_options][spec.name]
Gem::Command.build_args = build_args.map {|k,v| "--with-#{k}=#{v}"}
end

installer = Gem::Installer.new(gemfile, options.merge(
:install_dir => @path,
:ignore_dependencies => true,
Expand All @@ -143,6 +147,8 @@ def expand_gemfile(spec, options)
:bin_dir => @bindir
))
installer.install
ensure
Gem::Command.build_args = []
end

def expand_vendored_gem(spec, options)
Expand Down
43 changes: 43 additions & 0 deletions spec/bundler/cli_spec.rb
@@ -1,6 +1,49 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Bundler::CLI" do
describe "it compiles gems that take options" do
before(:each) do
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "very-simple-binary"
Gemfile
end

it "fails if the option is not provided" do
Dir.chdir(bundled_app) do
output = gem_command :bundle, "2>&1"
end

output.should =~ /Failed to build gem native extension/
end

it "passes if a yaml is specified that contains the necessary options" do
File.open(bundled_app.join("build.yml"), "w+") do |file|
file.puts <<-build_options.gsub(/^ /, '')
very-simple-binary:
simple: wot
build_options
end

Dir.chdir(bundled_app) do
@output = gem_command :bundle, "--build-options=build.yml 2>&1"
end

@output.should_not =~ /Failed to build gem native extension/

ruby_code = <<-RUBY.split("\n").join("; ")
require %{very_simple_binary}
include VerySimpleBinaryForTests
puts working
RUBY

@output = run_in_context "exec %{#{Gem.ruby} -e '#{ruby_code}'}"

@output.should == "true"
end
end

describe "it working" do
before(:each) do
build_manifest <<-Gemfile
Expand Down

0 comments on commit 793c938

Please sign in to comment.