Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change gemfile => gemdep, add Gem.detect_gemdeps to autoload

  • Loading branch information...
commit 204ba6fda574174b48b8474a17e4a99f5f811621 1 parent ed95e35
@evanphx evanphx authored
View
25 lib/rubygems.rb
@@ -122,6 +122,8 @@ module Gem
/wince/i,
]
+ GEM_DEP_FILES = %w!gem.deps.rb Gemfile Isolate!
+
@@win_platform = nil
@configuration = nil
@@ -214,6 +216,29 @@ def self.finish_resolve(request_set=Gem::RequestSet.new)
end
end
+ def self.detect_gemdeps
+ if path = ENV['RUBYGEMS_GEMDEPS']
+ path = path.dup.untaint
+
+ if path == "-"
+ path = GEM_DEP_FILES.find { |f| File.exists?(f) }
+
+ return unless path
+ end
+
+ return unless File.exists? path
+
+ rs = Gem::RequestSet.new
+ rs.load_gemdeps path
+
+ rs.resolve_current.map do |s|
+ sp = s.full_spec
+ sp.activate
+ sp
+ end
+ end
+ end
+
##
# An Array of all possible load paths for all versions of all gems in the
# Gem installation.
View
15 lib/rubygems/commands/install_command.rb
@@ -34,9 +34,10 @@ def initialize
add_version_option
add_prerelease_option "to be installed. (Only for listed gems)"
- add_option(:"Install/Update", '-g', '--gemfile FILE',
- 'Read from a Gemfile and install the listed gems') do |v,o|
- o[:gemfile] = v
+ add_option(:"Install/Update", '-g', '--file FILE',
+ 'Read from a gem dependencies API file and',
+ 'install the listed gems') do |v,o|
+ o[:gemdeps] = v
end
@installed_specs = nil
@@ -108,10 +109,10 @@ def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
end
- def install_from_gemfile(gf)
+ def install_from_gemdeps(gf)
require 'rubygems/request_set'
rs = Gem::RequestSet.new
- rs.load_gemfile gf
+ rs.load_gemdeps gf
rs.resolve
@@ -131,8 +132,8 @@ def install_from_gemfile(gf)
end
def execute
- if gf = options[:gemfile] then
- install_from_gemfile gf
+ if gf = options[:gemdeps] then
+ install_from_gemdeps gf
return
end
View
10 lib/rubygems/request_set.rb
@@ -47,10 +47,10 @@ def resolve_current
resolve DependencyResolver::CurrentSet.new
end
- # Load a Bundler-style Gemfile as much as possible.
+ # Load a dependency management file.
#
- def load_gemfile(path)
- gf = GemFile.new(self, path)
+ def load_gemdeps(path)
+ gf = GemDepedencyAPI.new(self, path)
gf.load
end
@@ -145,14 +145,14 @@ def install(options, &b)
# A semi-compatible DSL for Bundler's Gemfile format
#
- class GemFile
+ class GemDepedencyAPI
def initialize(set, path)
@set = set
@path = path
end
def load
- instance_eval File.read(@path), @path, 1
+ instance_eval File.read(@path).untaint, @path, 1
end
# DSL
View
4 lib/rubygems/source_list.rb
@@ -65,6 +65,10 @@ def to_a
alias_method :to_ary, :to_a
+ def first
+ @sources.first
+ end
+
def include?(other)
if other.kind_of? Gem::Source
@sources.include? other
View
14 lib/rubygems/test_case.rb
@@ -260,13 +260,17 @@ def teardown
def install_gem spec, options = {}
require 'rubygems/installer'
- use_ui Gem::MockGemUi.new do
- Dir.chdir @tempdir do
- Gem::Package.build spec
+ gem = File.join @tempdir, "gems", "#{spec.full_name}.gem"
+
+ unless File.exists? gem
+ use_ui Gem::MockGemUi.new do
+ Dir.chdir @tempdir do
+ Gem::Package.build spec
+ end
end
- end
- gem = File.join(@tempdir, File.basename(spec.cache_file)).untaint
+ gem = File.join(@tempdir, File.basename(spec.cache_file)).untaint
+ end
Gem::Installer.new(gem, options.merge({:wrappers => true})).install
end
View
69 test/rubygems/test_gem.rb
@@ -15,6 +15,7 @@ class TestGem < Gem::TestCase
def setup
super
+ ENV.delete 'RUBYGEMS_GEMDEPS'
@additional = %w[a b].map { |d| File.join @tempdir, d }
util_remove_interrupt_command
@@ -1346,6 +1347,74 @@ def test_gem_path_ordering_short
"Wrong spec selected"
end
+ def test_auto_activation_of_specific_gemdeps_file
+ util_clear_gems
+
+ a = new_spec "a", "1", nil, "lib/a.rb"
+ b = new_spec "b", "1", nil, "lib/b.rb"
+ c = new_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+
+ ENV['RUBYGEMS_GEMDEPS'] = path
+
+ Gem.detect_gemdeps
+
+ assert_equal %w!a-1 b-1 c-1!, loaded_spec_names
+ end
+
+ def test_auto_activation_of_detected_gemdeps_file
+ util_clear_gems
+
+ a = new_spec "a", "1", nil, "lib/a.rb"
+ b = new_spec "b", "1", nil, "lib/b.rb"
+ c = new_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+
+ ENV['RUBYGEMS_GEMDEPS'] = "-"
+
+ assert_equal [a,b,c], Gem.detect_gemdeps
+ end
+
+ def notest_auto_activation_of_gemdeps
+ a = new_spec "a", "1", nil, "lib/a.rb"
+ b = new_spec "b", "1", nil, "lib/b.rb"
+ c = new_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ path = File.join(@tempdir, "gd-tmp")
+
+ Gem.ensure_gem_subdirectories path
+
+ install_gem a, :install_dir => path
+ install_gem b, :install_dir => path
+ install_gem c, :install_dir => path
+
+ ENV['RUBYGEMS_GEMDEPS'] = path
+
+ util_clear_gems
+
+ assert_equal [a,b,c], Gem.detect_gemdeps
+ end
+
def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
@@project_dir)
View
46 test/rubygems/test_gem_commands_install_command.rb
@@ -9,13 +9,13 @@ def setup
@cmd = Gem::Commands::InstallCommand.new
@cmd.options[:document] = []
- @gemfile = "tmp_install_gemfile"
+ @gemdeps = "tmp_install_gemdeps"
end
def teardown
super
- File.unlink @gemfile if File.file? @gemfile
+ File.unlink @gemdeps if File.file? @gemdeps
end
def test_execute_exclude_prerelease
@@ -550,18 +550,18 @@ def test_execute_satisify_deps_of_local_from_sources
assert out.empty?, out.inspect
end
- def test_execute_uses_from_a_gemfile
+ def test_execute_uses_from_a_gemdeps
util_setup_fake_fetcher
util_setup_spec_fetcher
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary(@a2.cache_file)
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'a'"
end
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
@@ -579,7 +579,7 @@ def test_execute_uses_from_a_gemfile
assert out.empty?, out.inspect
end
- def test_execute_installs_from_a_gemfile
+ def test_execute_installs_from_a_gemdeps
util_setup_fake_fetcher
util_setup_spec_fetcher @a2
util_clear_gems
@@ -587,11 +587,11 @@ def test_execute_installs_from_a_gemfile
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary(@a2.cache_file)
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'a'"
end
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
@@ -609,7 +609,7 @@ def test_execute_installs_from_a_gemfile
assert out.empty?, out.inspect
end
- def test_execute_installs_deps_a_gemfile
+ def test_execute_installs_deps_a_gemdeps
q, q_gem = util_gem 'q', '1.0'
r, r_gem = util_gem 'r', '2.0', 'q' => nil
@@ -620,11 +620,11 @@ def test_execute_installs_deps_a_gemfile
add_to_fetcher q, q_gem
add_to_fetcher r, r_gem
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'r'"
end
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
@@ -645,7 +645,7 @@ def test_execute_installs_deps_a_gemfile
assert out.empty?, out.inspect
end
- def test_execute_uses_deps_a_gemfile
+ def test_execute_uses_deps_a_gemdeps
q, q_gem = util_gem 'q', '1.0'
r, r_gem = util_gem 'r', '2.0', 'q' => nil
@@ -657,11 +657,11 @@ def test_execute_uses_deps_a_gemfile
Gem::Specification.add_specs q
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'r'"
end
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
@@ -682,7 +682,7 @@ def test_execute_uses_deps_a_gemfile
assert out.empty?, out.inspect
end
- def test_execute_installs_deps_a_gemfile_into_a_path
+ def test_execute_installs_deps_a_gemdeps_into_a_path
q, q_gem = util_gem 'q', '1.0'
r, r_gem = util_gem 'r', '2.0', 'q' => nil
@@ -693,12 +693,12 @@ def test_execute_installs_deps_a_gemfile_into_a_path
add_to_fetcher q, q_gem
add_to_fetcher r, r_gem
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'r'"
end
@cmd.options[:install_dir] = "gf-path"
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
@@ -722,7 +722,7 @@ def test_execute_installs_deps_a_gemfile_into_a_path
assert File.file?("gf-path/specifications/r-2.0.gemspec"), "not installed"
end
- def test_execute_with_gemfile_path_ignores_system
+ def test_execute_with_gemdeps_path_ignores_system
q, q_gem = util_gem 'q', '1.0'
r, r_gem = util_gem 'r', '2.0', 'q' => nil
@@ -735,12 +735,12 @@ def test_execute_with_gemfile_path_ignores_system
Gem::Specification.add_specs q
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'r'"
end
@cmd.options[:install_dir] = "gf-path"
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
@@ -764,7 +764,7 @@ def test_execute_with_gemfile_path_ignores_system
assert File.file?("gf-path/specifications/r-2.0.gemspec"), "not installed"
end
- def test_execute_uses_deps_a_gemfile_with_a_path
+ def test_execute_uses_deps_a_gemdeps_with_a_path
q, q_gem = util_gem 'q', '1.0'
r, r_gem = util_gem 'r', '2.0', 'q' => nil
@@ -779,12 +779,12 @@ def test_execute_uses_deps_a_gemfile_with_a_path
assert File.file?("gf-path/specifications/q-1.0.gemspec"), "not installed"
- File.open @gemfile, "w" do |f|
+ File.open @gemdeps, "w" do |f|
f << "gem 'r'"
end
@cmd.options[:install_dir] = "gf-path"
- @cmd.options[:gemfile] = @gemfile
+ @cmd.options[:gemdeps] = @gemdeps
use_ui @ui do
e = assert_raises Gem::SystemExitException do
Please sign in to comment.
Something went wrong with that request. Please try again.