[前][次][番号順一覧][スレッド一覧]

ruby-changes:26039

From: drbrain <ko1@a...>
Date: Sat, 1 Dec 2012 10:01:07 +0900 (JST)
Subject: [ruby-changes:26039] drbrain:r38097 (trunk): * lib/rubygems.rb: Search for gem deps file up the directory tree.

drbrain	2012-12-01 09:42:36 +0900 (Sat, 01 Dec 2012)

  New Revision: 38097

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38097

  Log:
    * lib/rubygems.rb:  Search for gem deps file up the directory tree.
    * test/rubygems/test_gem.rb:  Test for above.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rubygems.rb
    trunk/test/rubygems/test_gem.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38096)
+++ ChangeLog	(revision 38097)
@@ -1,3 +1,8 @@
+Sat Dec  1 09:42:13 2012  Eric Hodel  <drbrain@s...>
+
+	* lib/rubygems.rb:  Search for gem deps file up the directory tree.
+	* test/rubygems/test_gem.rb:  Test for above.
+
 Sat Dec  1 09:33:32 2012  Eric Hodel  <drbrain@s...>
 
 	* test/runner.rb:  Set GEM_HOME, GEM_PATH and GEM_SKIP to empty set.
Index: lib/rubygems.rb
===================================================================
--- lib/rubygems.rb	(revision 38096)
+++ lib/rubygems.rb	(revision 38097)
@@ -187,9 +187,28 @@
       path = path.dup.untaint
 
       if path == "-"
-        path = GEM_DEP_FILES.find { |f| File.exists?(f) }
+        here = Dir.pwd
+        start = here
 
-        return unless path
+        begin
+          while true
+            path = GEM_DEP_FILES.find { |f| File.exists?(f) }
+
+            if path
+              path = File.join here, path
+              break
+            end
+
+            Dir.chdir ".."
+
+            # If we're at a toplevel, stop.
+            return if Dir.pwd == here
+
+            here = Dir.pwd
+          end
+        ensure
+          Dir.chdir start
+        end
       end
 
       return unless File.exists? path
Index: test/rubygems/test_gem.rb
===================================================================
--- test/rubygems/test_gem.rb	(revision 38096)
+++ test/rubygems/test_gem.rb	(revision 38097)
@@ -1402,6 +1402,41 @@
     assert_equal '["a-1", "b-1", "c-1"]', out.strip
   end
 
+  def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir
+    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
+
+    path = File.join(@tempdir, "gd-tmp")
+    install_gem a, :install_dir => path
+    install_gem b, :install_dir => path
+    install_gem c, :install_dir => path
+
+    ENV['GEM_PATH'] = path
+    ENV['RUBYGEMS_GEMDEPS'] = "-"
+
+    Dir.mkdir "sub1"
+    out = Dir.chdir "sub1" do
+      `#{Gem.ruby.untaint} -I #{LIB_PATH.untaint} -rubygems -e "p Gem.loaded_specs.values.map(&:full_name).sort"`
+    end
+
+    Dir.rmdir "sub1"
+
+    assert_equal '["a-1", "b-1", "c-1"]', out.strip
+  end
+
   def with_plugin(path)
     test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
                                         @@project_dir)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]