bundler_package_git 1.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/.gitignore +22 -0
  2. data/.rvmrc +1 -0
  3. data/CHANGELOG.md +659 -0
  4. data/ISSUES.md +47 -0
  5. data/LICENSE +23 -0
  6. data/README.md +29 -0
  7. data/Rakefile +167 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +22 -0
  10. data/bundler.gemspec +30 -0
  11. data/lib/bundler.rb +283 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +490 -0
  14. data/lib/bundler/definition.rb +429 -0
  15. data/lib/bundler/dependency.rb +130 -0
  16. data/lib/bundler/deployment.rb +53 -0
  17. data/lib/bundler/dsl.rb +243 -0
  18. data/lib/bundler/environment.rb +47 -0
  19. data/lib/bundler/fetcher.rb +101 -0
  20. data/lib/bundler/gem_helper.rb +146 -0
  21. data/lib/bundler/graph.rb +130 -0
  22. data/lib/bundler/index.rb +131 -0
  23. data/lib/bundler/installer.rb +117 -0
  24. data/lib/bundler/lazy_specification.rb +71 -0
  25. data/lib/bundler/lockfile_parser.rb +108 -0
  26. data/lib/bundler/remote_specification.rb +57 -0
  27. data/lib/bundler/resolver.rb +470 -0
  28. data/lib/bundler/rubygems_ext.rb +226 -0
  29. data/lib/bundler/runtime.rb +201 -0
  30. data/lib/bundler/settings.rb +117 -0
  31. data/lib/bundler/setup.rb +16 -0
  32. data/lib/bundler/shared_helpers.rb +167 -0
  33. data/lib/bundler/source.rb +675 -0
  34. data/lib/bundler/spec_set.rb +134 -0
  35. data/lib/bundler/templates/Executable +16 -0
  36. data/lib/bundler/templates/Gemfile +4 -0
  37. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  38. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  39. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  40. data/lib/bundler/templates/newgem/gitignore.tt +4 -0
  41. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -0
  42. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  43. data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -0
  44. data/lib/bundler/ui.rb +73 -0
  45. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  46. data/lib/bundler/vendor/net/http/persistent.rb +464 -0
  47. data/lib/bundler/vendor/thor.rb +319 -0
  48. data/lib/bundler/vendor/thor/actions.rb +297 -0
  49. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  50. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  51. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  52. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +229 -0
  53. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +104 -0
  54. data/lib/bundler/vendor/thor/base.rb +556 -0
  55. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  56. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  57. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  58. data/lib/bundler/vendor/thor/error.rb +30 -0
  59. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  60. data/lib/bundler/vendor/thor/parser.rb +4 -0
  61. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  62. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  63. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  64. data/lib/bundler/vendor/thor/parser/options.rb +174 -0
  65. data/lib/bundler/vendor/thor/shell.rb +88 -0
  66. data/lib/bundler/vendor/thor/shell/basic.rb +275 -0
  67. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  68. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  69. data/lib/bundler/vendor/thor/task.rb +114 -0
  70. data/lib/bundler/vendor/thor/util.rb +229 -0
  71. data/lib/bundler/vendor/thor/version.rb +3 -0
  72. data/lib/bundler/version.rb +6 -0
  73. data/lib/bundler/vlad.rb +9 -0
  74. data/man/bundle-config.ronn +90 -0
  75. data/man/bundle-exec.ronn +111 -0
  76. data/man/bundle-install.ronn +314 -0
  77. data/man/bundle-package.ronn +59 -0
  78. data/man/bundle-update.ronn +176 -0
  79. data/man/bundle.ronn +80 -0
  80. data/man/gemfile.5.ronn +279 -0
  81. data/man/index.txt +6 -0
  82. data/spec/cache/gems_spec.rb +219 -0
  83. data/spec/cache/git_spec.rb +9 -0
  84. data/spec/cache/path_spec.rb +27 -0
  85. data/spec/cache/platform_spec.rb +57 -0
  86. data/spec/install/deploy_spec.rb +197 -0
  87. data/spec/install/deprecated_spec.rb +37 -0
  88. data/spec/install/gems/c_ext_spec.rb +48 -0
  89. data/spec/install/gems/dependency_api_spec.rb +85 -0
  90. data/spec/install/gems/env_spec.rb +107 -0
  91. data/spec/install/gems/flex_spec.rb +313 -0
  92. data/spec/install/gems/groups_spec.rb +245 -0
  93. data/spec/install/gems/packed_spec.rb +84 -0
  94. data/spec/install/gems/platform_spec.rb +208 -0
  95. data/spec/install/gems/resolving_spec.rb +72 -0
  96. data/spec/install/gems/simple_case_spec.rb +715 -0
  97. data/spec/install/gems/standalone_spec.rb +162 -0
  98. data/spec/install/gems/sudo_spec.rb +73 -0
  99. data/spec/install/gems/win32_spec.rb +26 -0
  100. data/spec/install/gemspec_spec.rb +108 -0
  101. data/spec/install/git_spec.rb +571 -0
  102. data/spec/install/invalid_spec.rb +17 -0
  103. data/spec/install/path_spec.rb +353 -0
  104. data/spec/install/upgrade_spec.rb +26 -0
  105. data/spec/lock/git_spec.rb +35 -0
  106. data/spec/lock/lockfile_spec.rb +683 -0
  107. data/spec/other/check_spec.rb +221 -0
  108. data/spec/other/clean_spec.rb +202 -0
  109. data/spec/other/config_spec.rb +40 -0
  110. data/spec/other/console_spec.rb +54 -0
  111. data/spec/other/exec_spec.rb +241 -0
  112. data/spec/other/ext_spec.rb +16 -0
  113. data/spec/other/gem_helper_spec.rb +128 -0
  114. data/spec/other/help_spec.rb +38 -0
  115. data/spec/other/init_spec.rb +40 -0
  116. data/spec/other/newgem_spec.rb +24 -0
  117. data/spec/other/open_spec.rb +35 -0
  118. data/spec/other/show_spec.rb +82 -0
  119. data/spec/pack/gems_spec.rb +54 -0
  120. data/spec/quality_spec.rb +58 -0
  121. data/spec/resolver/basic_spec.rb +20 -0
  122. data/spec/resolver/platform_spec.rb +82 -0
  123. data/spec/runtime/executable_spec.rb +110 -0
  124. data/spec/runtime/load_spec.rb +107 -0
  125. data/spec/runtime/platform_spec.rb +90 -0
  126. data/spec/runtime/require_spec.rb +231 -0
  127. data/spec/runtime/setup_spec.rb +688 -0
  128. data/spec/runtime/with_clean_env_spec.rb +15 -0
  129. data/spec/spec_helper.rb +85 -0
  130. data/spec/support/artifice/endpoint.rb +50 -0
  131. data/spec/support/artifice/endpoint_fallback.rb +22 -0
  132. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  133. data/spec/support/artifice/endpoint_redirect.rb +11 -0
  134. data/spec/support/builders.rb +574 -0
  135. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  136. data/spec/support/fakeweb/windows.rb +23 -0
  137. data/spec/support/helpers.rb +246 -0
  138. data/spec/support/indexes.rb +112 -0
  139. data/spec/support/matchers.rb +89 -0
  140. data/spec/support/path.rb +73 -0
  141. data/spec/support/platforms.rb +53 -0
  142. data/spec/support/ruby_ext.rb +20 -0
  143. data/spec/support/rubygems_ext.rb +35 -0
  144. data/spec/support/rubygems_hax/platform.rb +11 -0
  145. data/spec/support/sudo.rb +21 -0
  146. data/spec/update/gems_spec.rb +121 -0
  147. data/spec/update/git_spec.rb +196 -0
  148. data/spec/update/source_spec.rb +51 -0
  149. metadata +294 -0
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe "Bundler.with_clean_env" do
4
+
5
+ it "should reset and restore the environment" do
6
+ gem_path = ENV['GEM_PATH']
7
+
8
+ Bundler.with_clean_env do
9
+ `echo $GEM_PATH`.strip.should_not == gem_path
10
+ end
11
+
12
+ ENV['GEM_PATH'].should == gem_path
13
+ end
14
+
15
+ end
@@ -0,0 +1,85 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'fileutils'
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'rspec'
8
+
9
+ # Require the correct version of popen for the current platform
10
+ if RbConfig::CONFIG['host_os'] =~ /mingw|mswin/
11
+ begin
12
+ require 'win32/open3'
13
+ rescue LoadError
14
+ abort "Run `gem install win32-open3` to be able to run specs"
15
+ end
16
+ else
17
+ require 'open3'
18
+ end
19
+
20
+ Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
21
+ require file unless file =~ /fakeweb\/.*\.rb/
22
+ end
23
+
24
+ $debug = false
25
+ $show_err = true
26
+
27
+ Spec::Rubygems.setup
28
+ FileUtils.rm_rf(Spec::Path.gem_repo1)
29
+ ENV['RUBYOPT'] = "#{ENV['RUBYOPT']} -r#{Spec::Path.root}/spec/support/rubygems_hax/platform.rb"
30
+ ENV['BUNDLE_SPEC_RUN'] = "true"
31
+
32
+ RSpec.configure do |config|
33
+ config.include Spec::Builders
34
+ config.include Spec::Helpers
35
+ config.include Spec::Indexes
36
+ config.include Spec::Matchers
37
+ config.include Spec::Path
38
+ config.include Spec::Rubygems
39
+ config.include Spec::Platforms
40
+ config.include Spec::Sudo
41
+
42
+ config.filter_run :focused => true unless ENV['CI']
43
+ config.filter_run_excluding :sudo => true unless Spec::Sudo.test_sudo?
44
+ config.run_all_when_everything_filtered = true
45
+ config.alias_example_to :fit, :focused => true
46
+
47
+ original_wd = Dir.pwd
48
+ original_path = ENV['PATH']
49
+ original_gem_home = ENV['GEM_HOME']
50
+
51
+ def pending_jruby_shebang_fix
52
+ pending "JRuby executables do not have a proper shebang" if RUBY_PLATFORM == "java"
53
+ end
54
+
55
+ def check(*args)
56
+ # suppresses ruby warnings about "useless use of == in void context"
57
+ # e.g. check foo.should == bar
58
+ end
59
+
60
+ config.before :all do
61
+ build_repo1
62
+ end
63
+
64
+ config.before :each do
65
+ reset!
66
+ system_gems []
67
+ in_app_root
68
+ end
69
+
70
+ config.after :each do
71
+ Dir.chdir(original_wd)
72
+ # Reset ENV
73
+ ENV['PATH'] = original_path
74
+ ENV['GEM_HOME'] = original_gem_home
75
+ ENV['GEM_PATH'] = original_gem_home
76
+ ENV['BUNDLE_PATH'] = nil
77
+ ENV['BUNDLE_GEMFILE'] = nil
78
+ ENV['BUNDLER_TEST'] = nil
79
+ ENV['BUNDLE_FROZEN'] = nil
80
+ ENV['BUNDLER_SPEC_PLATFORM'] = nil
81
+ ENV['BUNDLER_SPEC_VERSION'] = nil
82
+ ENV['BUNDLE_APP_CONFIG'] = nil
83
+ end
84
+ end
85
+
@@ -0,0 +1,50 @@
1
+ require File.expand_path("../../path.rb", __FILE__)
2
+ include Spec::Path
3
+
4
+ # Set up pretend http gem server with FakeWeb
5
+ $LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/artifice*/lib")].first}"
6
+ $LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/rack-*/lib")].first}"
7
+ $LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/rack-*/lib")].last}"
8
+ $LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/tilt*/lib")].first}"
9
+ $LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/sinatra*/lib")].first}"
10
+ require 'artifice'
11
+ require 'sinatra/base'
12
+
13
+ class Endpoint < Sinatra::Base
14
+
15
+ helpers do
16
+ def dependencies_for(gem_names)
17
+ require 'rubygems'
18
+ Marshal.load(File.open(gem_repo1("Marshal.4.8")).read).map do |gem, spec|
19
+ if gem_names.include?(spec.name)
20
+ {
21
+ :name => spec.name,
22
+ :number => spec.version.version,
23
+ :platform => spec.platform.to_s,
24
+ :dependencies => spec.dependencies.select {|dep| dep.type == :runtime }.map do |dep|
25
+ [dep.name, dep.requirement.requirements.map {|a| a.join(" ") }.join(", ")]
26
+ end
27
+ }
28
+ end
29
+ end.compact
30
+ end
31
+ end
32
+
33
+ get "/quick/Marshal.4.8/:id" do
34
+ redirect "/fetch/actual/gem/#{params[:id]}"
35
+ end
36
+
37
+ get "/fetch/actual/gem/:id" do
38
+ File.read("#{gem_repo1}/quick/Marshal.4.8/#{params[:id]}")
39
+ end
40
+
41
+ get "/gems/:id" do
42
+ File.read("#{gem_repo1}/gems/#{params[:id]}")
43
+ end
44
+
45
+ get "/api/v1/dependencies" do
46
+ Marshal.dump(dependencies_for(params[:gems]))
47
+ end
48
+ end
49
+
50
+ Artifice.activate_with(Endpoint)
@@ -0,0 +1,22 @@
1
+ require File.expand_path("../endpoint", __FILE__)
2
+
3
+ Artifice.deactivate
4
+
5
+ class EndpointFallback < Endpoint
6
+ DEPENDENCY_LIMIT = 60
7
+
8
+ get "/specs.4.8.gz" do
9
+ File.read("#{gem_repo1}/specs.4.8.gz")
10
+ end
11
+
12
+ get "/api/v1/dependencies" do
13
+ if params[:gems].size <= DEPENDENCY_LIMIT
14
+ Marshal.dump(dependencies_for(params[:gems]))
15
+ else
16
+ status 413
17
+ "Too many gems to resolve, please request less than #{DEPENDENCY_LIMIT} gems"
18
+ end
19
+ end
20
+ end
21
+
22
+ Artifice.activate_with(EndpointFallback)
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../endpoint_fallback", __FILE__)
2
+
3
+ Artifice.deactivate
4
+
5
+ class EndpointMarshalFail < EndpointFallback
6
+ get "/api/v1/dependencies" do
7
+ "f0283y01hasf"
8
+ end
9
+ end
10
+
11
+ Artifice.activate_with(EndpointMarshalFail)
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../endpoint", __FILE__)
2
+
3
+ Artifice.deactivate
4
+
5
+ class EndpointRedirect < Endpoint
6
+ get "/fetch/actual/gem/:id" do
7
+ redirect "/fetch/actual/gem/#{params[:id]}"
8
+ end
9
+ end
10
+
11
+ Artifice.activate_with(EndpointRedirect)
@@ -0,0 +1,574 @@
1
+ module Spec
2
+ module Builders
3
+ def self.constantize(name)
4
+ name.gsub('-', '').upcase
5
+ end
6
+
7
+ def v(version)
8
+ Gem::Version.new(version)
9
+ end
10
+
11
+ def pl(platform)
12
+ Gem::Platform.new(platform)
13
+ end
14
+
15
+ def build_repo1
16
+ build_repo gem_repo1 do
17
+ build_gem "rack", %w(0.9.1 1.0.0) do |s|
18
+ s.executables = "rackup"
19
+ end
20
+
21
+ build_gem "thin" do |s|
22
+ s.add_dependency "rack"
23
+ end
24
+
25
+ build_gem "rack-obama" do |s|
26
+ s.add_dependency "rack"
27
+ end
28
+
29
+ build_gem "rack_middleware", "1.0" do |s|
30
+ s.add_dependency "rack", "0.9.1"
31
+ end
32
+
33
+ build_gem "rails", "2.3.2" do |s|
34
+ s.executables = "rails"
35
+ s.add_dependency "rake"
36
+ s.add_dependency "actionpack", "2.3.2"
37
+ s.add_dependency "activerecord", "2.3.2"
38
+ s.add_dependency "actionmailer", "2.3.2"
39
+ s.add_dependency "activeresource", "2.3.2"
40
+ end
41
+ build_gem "actionpack", "2.3.2" do |s|
42
+ s.add_dependency "activesupport", "2.3.2"
43
+ end
44
+ build_gem "activerecord", ["2.3.1", "2.3.2"] do |s|
45
+ s.add_dependency "activesupport", "2.3.2"
46
+ end
47
+ build_gem "actionmailer", "2.3.2" do |s|
48
+ s.add_dependency "activesupport", "2.3.2"
49
+ end
50
+ build_gem "activeresource", "2.3.2" do |s|
51
+ s.add_dependency "activesupport", "2.3.2"
52
+ end
53
+ build_gem "activesupport", %w(1.2.3 2.3.2 2.3.5)
54
+
55
+ build_gem "activemerchant" do |s|
56
+ s.add_dependency "activesupport", ">= 2.0.0"
57
+ end
58
+
59
+ build_gem "rails_fail" do |s|
60
+ s.add_dependency "activesupport", "= 1.2.3"
61
+ end
62
+
63
+ build_gem "missing_dep" do |s|
64
+ s.add_dependency "not_here"
65
+ end
66
+
67
+ build_gem "rspec", "1.2.7", :no_default => true do |s|
68
+ s.write "lib/spec.rb", "SPEC = '1.2.7'"
69
+ end
70
+
71
+ build_gem "rack-test", :no_default => true do |s|
72
+ s.write "lib/rack/test.rb", "RACK_TEST = '1.0'"
73
+ end
74
+
75
+ build_gem "platform_specific" do |s|
76
+ s.platform = Gem::Platform.local
77
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Gem::Platform.local}'"
78
+ end
79
+
80
+ build_gem "platform_specific" do |s|
81
+ s.platform = "java"
82
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 JAVA'"
83
+ end
84
+
85
+ build_gem "platform_specific" do |s|
86
+ s.platform = "ruby"
87
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'"
88
+ end
89
+
90
+ build_gem "platform_specific" do |s|
91
+ s.platform = "x86-mswin32"
92
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 MSWIN'"
93
+ end
94
+
95
+ build_gem "platform_specific" do |s|
96
+ s.platform = "x86-darwin-100"
97
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 x86-darwin-100'"
98
+ end
99
+
100
+ build_gem "only_java" do |s|
101
+ s.platform = "java"
102
+ end
103
+
104
+ build_gem "nokogiri", "1.4.2"
105
+ build_gem "nokogiri", "1.4.2" do |s|
106
+ s.platform = "java"
107
+ s.write "lib/nokogiri.rb", "NOKOGIRI = '1.4.2 JAVA'"
108
+ s.add_dependency "weakling", ">= 0.0.3"
109
+ end
110
+
111
+ build_gem "weakling", "0.0.3"
112
+
113
+ build_gem "multiple_versioned_deps" do |s|
114
+ s.add_dependency "weakling", ">= 0.0.1", "< 0.1"
115
+ end
116
+
117
+ build_gem "not_released", "1.0.pre"
118
+
119
+ build_gem "has_prerelease", "1.0"
120
+ build_gem "has_prerelease", "1.1.pre"
121
+
122
+ build_gem "with_development_dependency" do |s|
123
+ s.add_development_dependency "activesupport", "= 2.3.5"
124
+ end
125
+
126
+ build_gem "with_implicit_rake_dep" do |s|
127
+ s.extensions << "Rakefile"
128
+ s.write "Rakefile", <<-RUBY
129
+ task :default do
130
+ path = File.expand_path("../lib", __FILE__)
131
+ FileUtils.mkdir_p(path)
132
+ File.open("\#{path}/implicit_rake_dep.rb", "w") do |f|
133
+ f.puts "IMPLICIT_RAKE_DEP = 'YES'"
134
+ end
135
+ end
136
+ RUBY
137
+ end
138
+
139
+ build_gem "another_implicit_rake_dep" do |s|
140
+ s.extensions << "Rakefile"
141
+ s.write "Rakefile", <<-RUBY
142
+ task :default do
143
+ path = File.expand_path("../lib", __FILE__)
144
+ FileUtils.mkdir_p(path)
145
+ File.open("\#{path}/another_implicit_rake_dep.rb", "w") do |f|
146
+ f.puts "ANOTHER_IMPLICIT_RAKE_DEP = 'YES'"
147
+ end
148
+ end
149
+ RUBY
150
+ end
151
+
152
+ build_gem "very_simple_binary" do |s|
153
+ s.add_c_extension
154
+ end
155
+
156
+ build_gem "bundler", "0.9" do |s|
157
+ s.executables = "bundle"
158
+ s.write "bin/bundle", "puts 'FAIL'"
159
+ end
160
+
161
+ # The bundler 0.8 gem has a rubygems plugin that always loads :(
162
+ build_gem "bundler", "0.8.1" do |s|
163
+ s.write "lib/bundler/omg.rb", ""
164
+ s.write "lib/rubygems_plugin.rb", "require 'bundler/omg' ; puts 'FAIL'"
165
+ end
166
+
167
+ # The yard gem iterates over Gem.source_index looking for plugins
168
+ build_gem "yard" do |s|
169
+ s.write "lib/yard.rb", <<-Y
170
+ Gem.source_index.find_name('').each do |gem|
171
+ puts gem.full_name
172
+ end
173
+ Y
174
+ end
175
+
176
+ # The rcov gem is platform mswin32, but has no arch
177
+ build_gem "rcov" do |s|
178
+ s.platform = Gem::Platform.new([nil, "mswin32", nil])
179
+ s.write "lib/rcov.rb", "RCOV = '1.0.0'"
180
+ end
181
+
182
+ build_gem "net-ssh"
183
+ build_gem "net-sftp", "1.1.1" do |s|
184
+ s.add_dependency "net-ssh", ">= 1.0.0", "< 1.99.0"
185
+ end
186
+
187
+ # Test comlicated gem dependencies for install
188
+ build_gem "net_a" do |s|
189
+ s.add_dependency "net_b"
190
+ s.add_dependency "net_build_extensions"
191
+ end
192
+
193
+ build_gem "net_b"
194
+
195
+ build_gem "net_build_extensions" do |s|
196
+ s.add_dependency "rake"
197
+ s.extensions << "Rakefile"
198
+ s.write "Rakefile", <<-RUBY
199
+ task :default do
200
+ path = File.expand_path("../lib", __FILE__)
201
+ FileUtils.mkdir_p(path)
202
+ File.open("\#{path}/net_build_extensions.rb", "w") do |f|
203
+ f.puts "NET_BUILD_EXTENSIONS = 'YES'"
204
+ end
205
+ end
206
+ RUBY
207
+ end
208
+
209
+ build_gem "net_c" do |s|
210
+ s.add_dependency "net_a"
211
+ s.add_dependency "net_d"
212
+ end
213
+
214
+ build_gem "net_d"
215
+
216
+ build_gem "net_e" do |s|
217
+ s.add_dependency "net_d"
218
+ end
219
+
220
+ build_gem "foo"
221
+ end
222
+ end
223
+
224
+ def build_repo2(&blk)
225
+ FileUtils.rm_rf gem_repo2
226
+ FileUtils.cp_r gem_repo1, gem_repo2
227
+ update_repo2(&blk) if block_given?
228
+ end
229
+
230
+ def build_repo3
231
+ build_repo gem_repo3 do
232
+ build_gem "rack"
233
+ end
234
+ FileUtils.rm_rf Dir[gem_repo3("prerelease*")]
235
+ end
236
+
237
+ def update_repo2
238
+ update_repo gem_repo2 do
239
+ build_gem "rack", "1.2" do |s|
240
+ s.executables = "rackup"
241
+ end
242
+ yield if block_given?
243
+ end
244
+ end
245
+
246
+ def build_repo(path, &blk)
247
+ return if File.directory?(path)
248
+ rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first
249
+ if rake_path
250
+ FileUtils.mkdir_p("#{path}/gems")
251
+ FileUtils.cp rake_path, "#{path}/gems/"
252
+ else
253
+ abort "You need to `rm -rf #{tmp}`"
254
+ end
255
+ update_repo(path, &blk)
256
+ end
257
+
258
+ def update_repo(path)
259
+ @_build_path = "#{path}/gems"
260
+ yield
261
+ @_build_path = nil
262
+ with_gem_path_as Path.base_system_gems do
263
+ Dir.chdir(path) { gem_command :generate_index }
264
+ end
265
+ end
266
+
267
+ def build_index(&block)
268
+ index = Bundler::Index.new
269
+ IndexBuilder.run(index, &block) if block_given?
270
+ index
271
+ end
272
+
273
+ def build_spec(name, version, platform = nil, &block)
274
+ Array(version).map do |v|
275
+ Gem::Specification.new do |s|
276
+ s.name = name
277
+ s.version = Gem::Version.new(v)
278
+ s.platform = platform
279
+ DepBuilder.run(s, &block) if block_given?
280
+ end
281
+ end
282
+ end
283
+
284
+ def build_dep(name, requirements = Gem::Requirement.default, type = :runtime)
285
+ Bundler::Dependency.new(name, :version => requirements)
286
+ end
287
+
288
+ def build_lib(name, *args, &blk)
289
+ build_with(LibBuilder, name, args, &blk)
290
+ end
291
+
292
+ def build_gem(name, *args, &blk)
293
+ build_with(GemBuilder, name, args, &blk)
294
+ end
295
+
296
+ def build_git(name, *args, &block)
297
+ opts = args.last.is_a?(Hash) ? args.last : {}
298
+ builder = opts[:bare] ? GitBareBuilder : GitBuilder
299
+ spec = build_with(builder, name, args, &block)
300
+ GitReader.new(opts[:path] || lib_path(spec.full_name))
301
+ end
302
+
303
+ def update_git(name, *args, &block)
304
+ build_with(GitUpdater, name, args, &block)
305
+ end
306
+
307
+ private
308
+
309
+ def build_with(builder, name, args, &blk)
310
+ @_build_path ||= nil
311
+ options = args.last.is_a?(Hash) ? args.pop : {}
312
+ versions = args.last || "1.0"
313
+ spec = nil
314
+
315
+ options[:path] ||= @_build_path
316
+
317
+ Array(versions).each do |version|
318
+ spec = builder.new(self, name, version)
319
+ yield spec if block_given?
320
+ spec._build(options)
321
+ end
322
+
323
+ spec
324
+ end
325
+
326
+ class IndexBuilder
327
+ include Builders
328
+
329
+ def self.run(index, &block)
330
+ new(index).run(&block)
331
+ end
332
+
333
+ def initialize(index)
334
+ @index = index
335
+ end
336
+
337
+ def run(&block)
338
+ instance_eval(&block)
339
+ end
340
+
341
+ def gem(*args, &block)
342
+ build_spec(*args, &block).each do |s|
343
+ @index << s
344
+ end
345
+ end
346
+
347
+ def platforms(platforms)
348
+ platforms.split(/\s+/).each do |platform|
349
+ platform.gsub!(/^(mswin32)$/, 'x86-\1')
350
+ yield Gem::Platform.new(platform)
351
+ end
352
+ end
353
+
354
+ def versions(versions)
355
+ versions.split(/\s+/).each { |version| yield v(version) }
356
+ end
357
+ end
358
+
359
+ class DepBuilder
360
+ include Builders
361
+
362
+ def self.run(spec, &block)
363
+ new(spec).run(&block)
364
+ end
365
+
366
+ def initialize(spec)
367
+ @spec = spec
368
+ end
369
+
370
+ def run(&block)
371
+ instance_eval(&block)
372
+ end
373
+
374
+ def runtime(name, requirements)
375
+ @spec.add_runtime_dependency(name, requirements)
376
+ end
377
+
378
+ alias dep runtime
379
+ end
380
+
381
+ class LibBuilder
382
+ def initialize(context, name, version)
383
+ @context = context
384
+ @name = name
385
+ @spec = Gem::Specification.new do |s|
386
+ s.name = name
387
+ s.version = version
388
+ s.summary = "This is just a fake gem for testing"
389
+ end
390
+ @files = {}
391
+ end
392
+
393
+ def method_missing(*args, &blk)
394
+ @spec.send(*args, &blk)
395
+ end
396
+
397
+ def write(file, source = "")
398
+ @files[file] = source
399
+ end
400
+
401
+ def executables=(val)
402
+ Array(val).each do |file|
403
+ write "bin/#{file}", "require '#{@name}' ; puts #{@name.upcase}"
404
+ end
405
+ @spec.executables = Array(val)
406
+ end
407
+
408
+ def add_c_extension
409
+ require_paths << 'ext'
410
+ extensions << "ext/extconf.rb"
411
+ write "ext/extconf.rb", <<-RUBY
412
+ require "mkmf"
413
+
414
+ # exit 1 unless with_config("simple")
415
+
416
+ extension_name = "very_simple_binary_c"
417
+ dir_config extension_name
418
+ create_makefile extension_name
419
+ RUBY
420
+ write "ext/very_simple_binary.c", <<-C
421
+ #include "ruby.h"
422
+
423
+ void Init_very_simple_binary_c() {
424
+ rb_define_module("VerySimpleBinaryInC");
425
+ }
426
+ C
427
+ end
428
+
429
+ def _build(options)
430
+ path = options[:path] || _default_path
431
+
432
+ if options[:rubygems_version]
433
+ @spec.rubygems_version = options[:rubygems_version]
434
+ def @spec.mark_version; end
435
+ def @spec.validate; end
436
+ end
437
+
438
+ case options[:gemspec]
439
+ when false
440
+ # do nothing
441
+ when :yaml
442
+ @files["#{name}.gemspec"] = @spec.to_yaml
443
+ else
444
+ @files["#{name}.gemspec"] = @spec.to_ruby
445
+ end
446
+
447
+ unless options[:no_default]
448
+ @files = _default_files.merge(@files)
449
+ end
450
+
451
+ @files.each do |file, source|
452
+ file = Pathname.new(path).join(file)
453
+ FileUtils.mkdir_p(file.dirname)
454
+ File.open(file, 'w') { |f| f.puts source }
455
+ end
456
+ @spec.files = @files.keys
457
+ path
458
+ end
459
+
460
+ def _default_files
461
+ @_default_files ||= { "lib/#{name}.rb" => "#{Builders.constantize(name)} = '#{version}'" }
462
+ end
463
+
464
+ def _default_path
465
+ @context.tmp('libs', @spec.full_name)
466
+ end
467
+ end
468
+
469
+ class GitBuilder < LibBuilder
470
+ def _build(options)
471
+ path = options[:path] || _default_path
472
+ super(options.merge(:path => path))
473
+ Dir.chdir(path) do
474
+ `git init`
475
+ `git add *`
476
+ `git commit -m 'OMG INITIAL COMMIT'`
477
+ end
478
+ end
479
+ end
480
+
481
+ class GitBareBuilder < LibBuilder
482
+ def _build(options)
483
+ path = options[:path] || _default_path
484
+ super(options.merge(:path => path))
485
+ Dir.chdir(path) do
486
+ `git init --bare`
487
+ end
488
+ end
489
+ end
490
+
491
+ class GitUpdater < LibBuilder
492
+ WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
493
+ NULL = WINDOWS ? "NUL" : "/dev/null"
494
+
495
+ def silently(str)
496
+ `#{str} 2>#{NULL}`
497
+ end
498
+
499
+ def _build(options)
500
+ libpath = options[:path] || _default_path
501
+
502
+ Dir.chdir(libpath) do
503
+ silently "git checkout master"
504
+
505
+ if branch = options[:branch]
506
+ raise "You can't specify `master` as the branch" if branch == "master"
507
+
508
+ if `git branch | grep #{branch}`.empty?
509
+ silently("git branch #{branch}")
510
+ end
511
+
512
+ silently("git checkout #{branch}")
513
+ elsif tag = options[:tag]
514
+ `git tag #{tag}`
515
+ elsif options[:remote]
516
+ silently("git remote add origin file://#{options[:remote]}")
517
+ elsif options[:push]
518
+ silently("git push origin #{options[:push]}")
519
+ end
520
+
521
+ current_ref = `git rev-parse HEAD`.strip
522
+ _default_files.keys.each do |path|
523
+ _default_files[path] << "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'"
524
+ end
525
+ super(options.merge(:path => libpath))
526
+ `git add *`
527
+ `git commit -m "BUMP"`
528
+ end
529
+ end
530
+ end
531
+
532
+ class GitReader
533
+ attr_reader :path
534
+
535
+ def initialize(path)
536
+ @path = path
537
+ end
538
+
539
+ def ref_for(ref, len = nil)
540
+ ref = git "rev-parse #{ref}"
541
+ ref = ref[0..len] if len
542
+ ref
543
+ end
544
+
545
+ private
546
+
547
+ def git(cmd)
548
+ Dir.chdir(@path) { `git #{cmd}`.strip }
549
+ end
550
+
551
+ end
552
+
553
+ class GemBuilder < LibBuilder
554
+
555
+ def _build(opts)
556
+ lib_path = super(opts.merge(:path => @context.tmp(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default]))
557
+ Dir.chdir(lib_path) do
558
+ destination = opts[:path] || _default_path
559
+ FileUtils.mkdir_p(destination)
560
+ Gem::Builder.new(@spec).build
561
+ if opts[:to_system]
562
+ `gem install --ignore-dependencies #{@spec.full_name}.gem`
563
+ else
564
+ FileUtils.mv("#{@spec.full_name}.gem", opts[:path] || _default_path)
565
+ end
566
+ end
567
+ end
568
+
569
+ def _default_path
570
+ @context.gem_repo1('gems')
571
+ end
572
+ end
573
+ end
574
+ end