diff options
author | Carl Lerche <carllerche@mac.com> | 2009-07-28 19:59:14 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2009-07-28 19:59:14 -0700 |
commit | 7119291be40909f801598f7cb55d72a48435c0a9 (patch) | |
tree | e7ef491e5813940e2bc21baf56de8ccc59cc18f2 | |
parent | 56082a7589deaceb1e23c130caaa8d74d972432d (diff) | |
download | bundler-7119291be40909f801598f7cb55d72a48435c0a9.tar.gz |
Add a disable_system_gems option to the Gemfile
-rw-r--r-- | lib/bundler/manifest.rb | 3 | ||||
-rw-r--r-- | lib/bundler/manifest_file.rb | 20 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 8 | ||||
-rw-r--r-- | lib/bundler/templates/environment.rb | 4 | ||||
-rw-r--r-- | spec/bundler/manifest_spec.rb | 27 | ||||
-rw-r--r-- | spec/spec_helper.rb | 7 |
6 files changed, 52 insertions, 17 deletions
diff --git a/lib/bundler/manifest.rb b/lib/bundler/manifest.rb index e0e07a30de..d47f9a7557 100644 --- a/lib/bundler/manifest.rb +++ b/lib/bundler/manifest.rb @@ -6,13 +6,14 @@ module Bundler class Manifest attr_reader :sources, :dependencies, :path - def initialize(sources, dependencies, bindir, repository_path, rubygems) + def initialize(sources, dependencies, bindir, repository_path, rubygems, system_gems) sources.map! {|s| s.is_a?(URI) ? s : URI.parse(s) } @sources = sources @dependencies = dependencies @bindir = bindir @repository = Repository.new(repository_path) @rubygems = rubygems + @system_gems = system_gems end def install diff --git a/lib/bundler/manifest_file.rb b/lib/bundler/manifest_file.rb index 2c96423262..9e0f035409 100644 --- a/lib/bundler/manifest_file.rb +++ b/lib/bundler/manifest_file.rb @@ -3,18 +3,18 @@ module Bundler class ManifestFile attr_reader :sources, :dependencies - attr_accessor :gem_path, :bindir, :rubygems + attr_accessor :gem_path, :bindir, :rubygems, :system_gems def self.load(filename = nil) new(filename).load end def initialize(filename) - @filename = filename - @sources = %w(http://gems.rubyforge.org) - @dependencies = [] - @system_gem_fallback = true - @rubygems = :optional + @filename = filename + @sources = %w(http://gems.rubyforge.org) + @dependencies = [] + @system_gems = true + @rubygems = :optional end def load @@ -31,7 +31,7 @@ module Bundler end def setup_environment - unless @system_gem_fallback + unless @system_gems ENV["GEM_HOME"] = @gem_path ENV["GEM_PATH"] = @gem_path end @@ -41,11 +41,7 @@ module Bundler def load_manifest ManifestBuilder.load(self, filename) - Manifest.new(sources, dependencies, bindir, gem_path, rubygems) - end - - def disable_fallback! - @system_gem_fallback = false + Manifest.new(sources, dependencies, bindir, gem_path, rubygems, system_gems) end def gem_path diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 02a3d6c45e..e8f3a2b3d9 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -40,6 +40,10 @@ module Bundler @manifest_file.rubygems = :require end + def disable_system_gems + @manifest_file.system_gems = false + end + def source(source) @manifest_file.sources << source @manifest_file.sources.uniq! @@ -55,9 +59,5 @@ module Bundler @manifest_file.dependencies << Dependency.new(name, options.merge(:version => version)) end - - def disable_fallback! - @manifest_file.disable_fallback! - end end end diff --git a/lib/bundler/templates/environment.rb b/lib/bundler/templates/environment.rb index 97060aeb04..a782481ab3 100644 --- a/lib/bundler/templates/environment.rb +++ b/lib/bundler/templates/environment.rb @@ -6,6 +6,10 @@ module Bundler end end +<% unless @system_gems %> +ENV["GEM_HOME"] = "<%= @repository.path %>" +ENV["GEM_PATH"] = "<%= @repository.path %>" +<% end %> ENV["PATH"] = "<%= @bindir %>:#{ENV["PATH"]}" ENV["RUBYOPT"] = "-r#{__FILE__} #{ENV["RUBYOPT"]}" diff --git a/spec/bundler/manifest_spec.rb b/spec/bundler/manifest_spec.rb index 141b11e59d..dcc5ab0976 100644 --- a/spec/bundler/manifest_spec.rb +++ b/spec/bundler/manifest_spec.rb @@ -174,6 +174,33 @@ describe "Bundler::Manifest" do File.expand_path(tmp_gem_path("gems", "very-simple-1.0", "lib", "very-simple.rb")) end end + + it "is able to work system gems" do + m = build_manifest <<-Gemfile + sources.clear + source "file://#{gem_repo1}" + gem "very-simple" + require_rubygems + Gemfile + + m.install + out = run_in_context "require 'rake' ; puts Rake" + out.should == "Rake\n" + end + + it "it does not work with system gems if system gems have been disabled" do + m = build_manifest <<-Gemfile + sources.clear + source "file://#{gem_repo1}" + gem "very-simple" + require_rubygems + disable_system_gems + Gemfile + + m.install + out = run_in_context "begin ; require 'rake' ; rescue LoadError ; puts('WIN') ; end" + out.should == "WIN\n" + end end describe "environments" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b0b49ecbcd..dc306781e2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,6 +52,13 @@ module Spec FileUtils.cp(fixture(gem_name), File.join(tmp_dir, 'cache')) end + def run_in_context(*args) + cmd = args.pop.gsub(/(?=")/, "\\") + env = args.pop || tmp_file("vendor", "gems", "environments", "default") + %x{#{Gem.ruby} -r #{env} -e "#{cmd}"} + # system Gem.ruby, "-r", env, "-e", cmd + end + def build_manifest_file(*args) path = tmp_file("Gemfile") path = args.shift if args.first.is_a?(Pathname) |