|
1 # Add a vendor_dir for gems at vendor_ruby/gems/<ruby lib version>, to the end |
|
2 # of GEM PATHS, so gem will search the vendor directory for gems. |
|
3 # We can use this directory to install Solaris Ruby modules |
|
4 # that we want to package as gems. |
|
5 # |
|
6 # This is a subset of changes made to Rubygems 2.4.0 |
|
7 # to fix rubygems issue #943 site_ruby/vendor_ruby equivalent for rubygems |
|
8 # https://github.com/rubygems/rubygems/issues/943 |
|
9 # We do not add the --vendor option to the gem command, |
|
10 # nor do we change the default gem installation directory. |
|
11 |
|
12 diff -ru ruby-2.1.5-orig//lib/rubygems/defaults.rb ruby-2.1.5/lib/rubygems/defaults.rb |
|
13 --- ruby-2.1.5-orig//lib/rubygems/defaults.rb Wed Feb 5 18:59:36 2014 |
|
14 +++ ruby-2.1.5/lib/rubygems/defaults.rb Thu Jan 15 14:56:45 2015 |
|
15 @@ -89,11 +89,11 @@ |
|
16 # Default gem load path |
|
17 |
|
18 def self.default_path |
|
19 - if Gem.user_home && File.exist?(Gem.user_home) then |
|
20 - [user_dir, default_dir] |
|
21 - else |
|
22 - [default_dir] |
|
23 - end |
|
24 + path = [] |
|
25 + path << user_dir if user_home && File.exist?(user_home) |
|
26 + path << default_dir |
|
27 + path << vendor_dir if vendor_dir and File.directory? vendor_dir |
|
28 + path |
|
29 end |
|
30 |
|
31 ## |
|
32 @@ -160,4 +160,12 @@ |
|
33 true |
|
34 end |
|
35 |
|
36 + ## |
|
37 + # Directory where vendor gems are installed. |
|
38 + |
|
39 + def self.vendor_dir # :nodoc: |
|
40 + File.join RbConfig::CONFIG['vendordir'], 'gems', |
|
41 + RbConfig::CONFIG['ruby_version'] |
|
42 + end |
|
43 + |
|
44 end |
|
45 diff -ru ruby-2.1.5-orig//test/rubygems/test_gem.rb ruby-2.1.5/test/rubygems/test_gem.rb |
|
46 --- ruby-2.1.5-orig//test/rubygems/test_gem.rb Wed Feb 5 18:59:36 2014 |
|
47 +++ ruby-2.1.5/test/rubygems/test_gem.rb Thu Jan 15 15:40:32 2015 |
|
48 @@ -216,6 +216,45 @@ |
|
49 end |
|
50 end |
|
51 |
|
52 + def test_default_path |
|
53 + orig_vendordir = RbConfig::CONFIG['vendordir'] |
|
54 + RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor' |
|
55 + |
|
56 + FileUtils.rm_rf Gem.user_home |
|
57 + |
|
58 + expected = [Gem.default_dir] |
|
59 + |
|
60 + assert_equal expected, Gem.default_path |
|
61 + ensure |
|
62 + RbConfig::CONFIG['vendordir'] = orig_vendordir |
|
63 + end |
|
64 + |
|
65 + def test_default_path_user_home |
|
66 + orig_vendordir = RbConfig::CONFIG['vendordir'] |
|
67 + RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor' |
|
68 + |
|
69 + expected = [Gem.user_dir, Gem.default_dir] |
|
70 + |
|
71 + assert_equal expected, Gem.default_path |
|
72 + ensure |
|
73 + RbConfig::CONFIG['vendordir'] = orig_vendordir |
|
74 + end |
|
75 + |
|
76 + def test_default_path_vendor_dir |
|
77 + orig_vendordir = RbConfig::CONFIG['vendordir'] |
|
78 + RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor' |
|
79 + |
|
80 + FileUtils.mkdir_p Gem.vendor_dir |
|
81 + |
|
82 + FileUtils.rm_rf Gem.user_home |
|
83 + |
|
84 + expected = [Gem.default_dir, Gem.vendor_dir] |
|
85 + |
|
86 + assert_equal expected, Gem.default_path |
|
87 + ensure |
|
88 + RbConfig::CONFIG['vendordir'] = orig_vendordir |
|
89 + end |
|
90 + |
|
91 def test_self_default_sources |
|
92 assert_equal %w[https://rubygems.org/], Gem.default_sources |
|
93 end |
|
94 @@ -951,6 +990,14 @@ |
|
95 end |
|
96 end |
|
97 |
|
98 + def test_self_vendor_dir |
|
99 + expected = |
|
100 + File.join RbConfig::CONFIG['vendordir'], 'gems', |
|
101 + RbConfig::CONFIG['ruby_version'] |
|
102 + |
|
103 + assert_equal expected, Gem.vendor_dir |
|
104 + end |
|
105 + |
|
106 def test_load_plugins |
|
107 skip 'Insecure operation - chdir' if RUBY_VERSION <= "1.8.7" |
|
108 plugin_path = File.join "lib", "rubygems_plugin.rb" |