bundler-prehistoric 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +100 -0
  5. data/CHANGELOG.md +1640 -0
  6. data/CONTRIBUTING.md +32 -0
  7. data/DEVELOPMENT.md +117 -0
  8. data/Gemfile +3 -0
  9. data/ISSUES.md +96 -0
  10. data/LICENSE.md +23 -0
  11. data/README.md +46 -0
  12. data/Rakefile +256 -0
  13. data/UPGRADING.md +103 -0
  14. data/bin/bundle +21 -0
  15. data/bin/bundle_ruby +56 -0
  16. data/bin/bundler +21 -0
  17. data/bundler.gemspec +33 -0
  18. data/lib/bundler.rb +442 -0
  19. data/lib/bundler/backports/time.rb +7 -0
  20. data/lib/bundler/capistrano.rb +16 -0
  21. data/lib/bundler/cli.rb +395 -0
  22. data/lib/bundler/cli/binstubs.rb +38 -0
  23. data/lib/bundler/cli/cache.rb +34 -0
  24. data/lib/bundler/cli/check.rb +35 -0
  25. data/lib/bundler/cli/clean.rb +19 -0
  26. data/lib/bundler/cli/common.rb +54 -0
  27. data/lib/bundler/cli/config.rb +84 -0
  28. data/lib/bundler/cli/console.rb +39 -0
  29. data/lib/bundler/cli/exec.rb +37 -0
  30. data/lib/bundler/cli/gem.rb +101 -0
  31. data/lib/bundler/cli/init.rb +33 -0
  32. data/lib/bundler/cli/inject.rb +33 -0
  33. data/lib/bundler/cli/install.rb +133 -0
  34. data/lib/bundler/cli/open.rb +23 -0
  35. data/lib/bundler/cli/outdated.rb +80 -0
  36. data/lib/bundler/cli/package.rb +36 -0
  37. data/lib/bundler/cli/platform.rb +43 -0
  38. data/lib/bundler/cli/show.rb +48 -0
  39. data/lib/bundler/cli/update.rb +73 -0
  40. data/lib/bundler/cli/viz.rb +27 -0
  41. data/lib/bundler/constants.rb +5 -0
  42. data/lib/bundler/current_ruby.rb +155 -0
  43. data/lib/bundler/definition.rb +604 -0
  44. data/lib/bundler/dep_proxy.rb +43 -0
  45. data/lib/bundler/dependency.rb +106 -0
  46. data/lib/bundler/deployment.rb +59 -0
  47. data/lib/bundler/deprecate.rb +15 -0
  48. data/lib/bundler/dsl.rb +305 -0
  49. data/lib/bundler/endpoint_specification.rb +76 -0
  50. data/lib/bundler/env.rb +56 -0
  51. data/lib/bundler/environment.rb +42 -0
  52. data/lib/bundler/fetcher.rb +396 -0
  53. data/lib/bundler/friendly_errors.rb +42 -0
  54. data/lib/bundler/gem_helper.rb +169 -0
  55. data/lib/bundler/gem_helpers.rb +25 -0
  56. data/lib/bundler/gem_installer.rb +9 -0
  57. data/lib/bundler/gem_path_manipulation.rb +8 -0
  58. data/lib/bundler/gem_tasks.rb +2 -0
  59. data/lib/bundler/graph.rb +169 -0
  60. data/lib/bundler/index.rb +184 -0
  61. data/lib/bundler/injector.rb +64 -0
  62. data/lib/bundler/installer.rb +332 -0
  63. data/lib/bundler/lazy_specification.rb +83 -0
  64. data/lib/bundler/lockfile_parser.rb +146 -0
  65. data/lib/bundler/match_platform.rb +13 -0
  66. data/lib/bundler/parallel_workers.rb +18 -0
  67. data/lib/bundler/parallel_workers/thread_worker.rb +30 -0
  68. data/lib/bundler/parallel_workers/unix_worker.rb +101 -0
  69. data/lib/bundler/parallel_workers/worker.rb +69 -0
  70. data/lib/bundler/psyched_yaml.rb +26 -0
  71. data/lib/bundler/remote_specification.rb +57 -0
  72. data/lib/bundler/resolver.rb +534 -0
  73. data/lib/bundler/retry.rb +60 -0
  74. data/lib/bundler/ruby_dsl.rb +11 -0
  75. data/lib/bundler/ruby_version.rb +117 -0
  76. data/lib/bundler/rubygems_ext.rb +171 -0
  77. data/lib/bundler/rubygems_integration.rb +578 -0
  78. data/lib/bundler/runtime.rb +310 -0
  79. data/lib/bundler/settings.rb +176 -0
  80. data/lib/bundler/setup.rb +23 -0
  81. data/lib/bundler/shared_helpers.rb +110 -0
  82. data/lib/bundler/similarity_detector.rb +63 -0
  83. data/lib/bundler/source.rb +29 -0
  84. data/lib/bundler/source/git.rb +289 -0
  85. data/lib/bundler/source/git/git_proxy.rb +158 -0
  86. data/lib/bundler/source/path.rb +225 -0
  87. data/lib/bundler/source/path/installer.rb +38 -0
  88. data/lib/bundler/source/rubygems.rb +334 -0
  89. data/lib/bundler/source/svn.rb +260 -0
  90. data/lib/bundler/source/svn/svn_proxy.rb +110 -0
  91. data/lib/bundler/spec_set.rb +154 -0
  92. data/lib/bundler/ssl_certs/.document +1 -0
  93. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  94. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  95. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  96. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  97. data/lib/bundler/ssl_certs/certificate_manager.rb +41 -0
  98. data/lib/bundler/templates/Executable +16 -0
  99. data/lib/bundler/templates/Executable.standalone +12 -0
  100. data/lib/bundler/templates/Gemfile +4 -0
  101. data/lib/bundler/templates/newgem/.travis.yml.tt +3 -0
  102. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  103. data/lib/bundler/templates/newgem/LICENSE.txt.tt +22 -0
  104. data/lib/bundler/templates/newgem/README.md.tt +31 -0
  105. data/lib/bundler/templates/newgem/Rakefile.tt +26 -0
  106. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  107. data/lib/bundler/templates/newgem/consolerc.tt +3 -0
  108. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  109. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  110. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  111. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  112. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  113. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  114. data/lib/bundler/templates/newgem/newgem.gemspec.tt +38 -0
  115. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  116. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  117. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  118. data/lib/bundler/templates/newgem/test/minitest_helper.rb.tt +4 -0
  119. data/lib/bundler/templates/newgem/test/test_newgem.rb.tt +11 -0
  120. data/lib/bundler/ui.rb +7 -0
  121. data/lib/bundler/ui/rg_proxy.rb +21 -0
  122. data/lib/bundler/ui/shell.rb +98 -0
  123. data/lib/bundler/ui/silent.rb +44 -0
  124. data/lib/bundler/vendor/.document +0 -0
  125. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  126. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  127. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  128. data/lib/bundler/vendor/thor.rb +480 -0
  129. data/lib/bundler/vendor/thor/actions.rb +319 -0
  130. data/lib/bundler/vendor/thor/actions/create_file.rb +103 -0
  131. data/lib/bundler/vendor/thor/actions/create_link.rb +59 -0
  132. data/lib/bundler/vendor/thor/actions/directory.rb +118 -0
  133. data/lib/bundler/vendor/thor/actions/empty_directory.rb +135 -0
  134. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +316 -0
  135. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +107 -0
  136. data/lib/bundler/vendor/thor/base.rb +656 -0
  137. data/lib/bundler/vendor/thor/command.rb +133 -0
  138. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  139. data/lib/bundler/vendor/thor/core_ext/io_binary_read.rb +10 -0
  140. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +98 -0
  141. data/lib/bundler/vendor/thor/error.rb +32 -0
  142. data/lib/bundler/vendor/thor/group.rb +281 -0
  143. data/lib/bundler/vendor/thor/invocation.rb +173 -0
  144. data/lib/bundler/vendor/thor/line_editor.rb +17 -0
  145. data/lib/bundler/vendor/thor/line_editor/basic.rb +35 -0
  146. data/lib/bundler/vendor/thor/line_editor/readline.rb +88 -0
  147. data/lib/bundler/vendor/thor/parser.rb +4 -0
  148. data/lib/bundler/vendor/thor/parser/argument.rb +73 -0
  149. data/lib/bundler/vendor/thor/parser/arguments.rb +175 -0
  150. data/lib/bundler/vendor/thor/parser/option.rb +121 -0
  151. data/lib/bundler/vendor/thor/parser/options.rb +218 -0
  152. data/lib/bundler/vendor/thor/rake_compat.rb +71 -0
  153. data/lib/bundler/vendor/thor/runner.rb +322 -0
  154. data/lib/bundler/vendor/thor/shell.rb +81 -0
  155. data/lib/bundler/vendor/thor/shell/basic.rb +420 -0
  156. data/lib/bundler/vendor/thor/shell/color.rb +149 -0
  157. data/lib/bundler/vendor/thor/shell/html.rb +126 -0
  158. data/lib/bundler/vendor/thor/util.rb +267 -0
  159. data/lib/bundler/vendor/thor/version.rb +3 -0
  160. data/lib/bundler/vendored_persistent.rb +3 -0
  161. data/lib/bundler/vendored_thor.rb +8 -0
  162. data/lib/bundler/version.rb +6 -0
  163. data/lib/bundler/vlad.rb +11 -0
  164. data/man/bundle-config.ronn +155 -0
  165. data/man/bundle-exec.ronn +136 -0
  166. data/man/bundle-install.ronn +372 -0
  167. data/man/bundle-package.ronn +59 -0
  168. data/man/bundle-platform.ronn +42 -0
  169. data/man/bundle-update.ronn +179 -0
  170. data/man/bundle.ronn +92 -0
  171. data/man/gemfile.5.ronn +369 -0
  172. data/man/index.txt +7 -0
  173. data/spec/bundler/bundler_spec.rb +74 -0
  174. data/spec/bundler/cli_spec.rb +16 -0
  175. data/spec/bundler/definition_spec.rb +21 -0
  176. data/spec/bundler/dsl_spec.rb +108 -0
  177. data/spec/bundler/friendly_errors_spec.rb +13 -0
  178. data/spec/bundler/gem_helper_spec.rb +225 -0
  179. data/spec/bundler/psyched_yaml_spec.rb +8 -0
  180. data/spec/bundler/retry_spec.rb +59 -0
  181. data/spec/bundler/settings_spec.rb +13 -0
  182. data/spec/bundler/source_spec.rb +25 -0
  183. data/spec/cache/gems_spec.rb +316 -0
  184. data/spec/cache/git_spec.rb +188 -0
  185. data/spec/cache/path_spec.rb +121 -0
  186. data/spec/cache/platform_spec.rb +53 -0
  187. data/spec/cache/svn_spec.rb +82 -0
  188. data/spec/commands/binstubs_spec.rb +246 -0
  189. data/spec/commands/check_spec.rb +278 -0
  190. data/spec/commands/clean_spec.rb +652 -0
  191. data/spec/commands/config_spec.rb +227 -0
  192. data/spec/commands/console_spec.rb +102 -0
  193. data/spec/commands/exec_spec.rb +367 -0
  194. data/spec/commands/help_spec.rb +39 -0
  195. data/spec/commands/init_spec.rb +39 -0
  196. data/spec/commands/inject_spec.rb +78 -0
  197. data/spec/commands/licenses_spec.rb +31 -0
  198. data/spec/commands/newgem_spec.rb +451 -0
  199. data/spec/commands/open_spec.rb +80 -0
  200. data/spec/commands/outdated_spec.rb +168 -0
  201. data/spec/commands/package_spec.rb +128 -0
  202. data/spec/commands/show_spec.rb +152 -0
  203. data/spec/install/binstubs_spec.rb +24 -0
  204. data/spec/install/bundler_spec.rb +146 -0
  205. data/spec/install/deploy_spec.rb +237 -0
  206. data/spec/install/gemfile/gemspec_spec.rb +170 -0
  207. data/spec/install/gemfile/git_spec.rb +967 -0
  208. data/spec/install/gemfile/path_spec.rb +480 -0
  209. data/spec/install/gemfile/svn_spec.rb +582 -0
  210. data/spec/install/gemfile_spec.rb +44 -0
  211. data/spec/install/gems/c_ext_spec.rb +48 -0
  212. data/spec/install/gems/dependency_api_spec.rb +580 -0
  213. data/spec/install/gems/env_spec.rb +107 -0
  214. data/spec/install/gems/flex_spec.rb +314 -0
  215. data/spec/install/gems/groups_spec.rb +308 -0
  216. data/spec/install/gems/mirror_spec.rb +39 -0
  217. data/spec/install/gems/platform_spec.rb +221 -0
  218. data/spec/install/gems/post_install_spec.rb +121 -0
  219. data/spec/install/gems/resolving_spec.rb +124 -0
  220. data/spec/install/gems/simple_case_spec.rb +386 -0
  221. data/spec/install/gems/standalone_spec.rb +260 -0
  222. data/spec/install/gems/sudo_spec.rb +136 -0
  223. data/spec/install/gems/win32_spec.rb +26 -0
  224. data/spec/install/gemspecs_spec.rb +50 -0
  225. data/spec/install/path_spec.rb +150 -0
  226. data/spec/install/post_bundle_message_spec.rb +142 -0
  227. data/spec/install/prereleases_spec.rb +43 -0
  228. data/spec/install/security_policy_spec.rb +77 -0
  229. data/spec/install/upgrade_spec.rb +26 -0
  230. data/spec/lock/git_spec.rb +34 -0
  231. data/spec/lock/lockfile_spec.rb +912 -0
  232. data/spec/lock/svn_spec.rb +35 -0
  233. data/spec/other/bundle_ruby_spec.rb +142 -0
  234. data/spec/other/cli_dispatch_spec.rb +21 -0
  235. data/spec/other/ext_spec.rb +60 -0
  236. data/spec/other/platform_spec.rb +1285 -0
  237. data/spec/other/ssl_cert_spec.rb +10 -0
  238. data/spec/quality_spec.rb +88 -0
  239. data/spec/realworld/dependency_api_spec.rb +60 -0
  240. data/spec/realworld/edgecases_spec.rb +177 -0
  241. data/spec/realworld/parallel_spec.rb +69 -0
  242. data/spec/resolver/basic_spec.rb +66 -0
  243. data/spec/resolver/platform_spec.rb +88 -0
  244. data/spec/runtime/executable_spec.rb +149 -0
  245. data/spec/runtime/load_spec.rb +107 -0
  246. data/spec/runtime/platform_spec.rb +90 -0
  247. data/spec/runtime/require_spec.rb +332 -0
  248. data/spec/runtime/setup_spec.rb +856 -0
  249. data/spec/runtime/with_clean_env_spec.rb +91 -0
  250. data/spec/spec_helper.rb +114 -0
  251. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  252. data/spec/support/artifice/endpoint.rb +71 -0
  253. data/spec/support/artifice/endpoint_500.rb +37 -0
  254. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  255. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  256. data/spec/support/artifice/endpoint_creds_diff_host.rb +38 -0
  257. data/spec/support/artifice/endpoint_extra.rb +31 -0
  258. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  259. data/spec/support/artifice/endpoint_fallback.rb +17 -0
  260. data/spec/support/artifice/endpoint_host_redirect.rb +15 -0
  261. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  262. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  263. data/spec/support/artifice/endpoint_strict_basic_authentication.rb +18 -0
  264. data/spec/support/artifice/endpoint_timeout.rb +13 -0
  265. data/spec/support/builders.rb +748 -0
  266. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  267. data/spec/support/fakeweb/windows.rb +23 -0
  268. data/spec/support/hax.rb +22 -0
  269. data/spec/support/helpers.rb +348 -0
  270. data/spec/support/indexes.rb +280 -0
  271. data/spec/support/less_than_proc.rb +14 -0
  272. data/spec/support/matchers.rb +77 -0
  273. data/spec/support/path.rb +81 -0
  274. data/spec/support/permissions.rb +10 -0
  275. data/spec/support/platforms.rb +94 -0
  276. data/spec/support/ruby_ext.rb +20 -0
  277. data/spec/support/rubygems_ext.rb +39 -0
  278. data/spec/support/streams.rb +13 -0
  279. data/spec/support/sudo.rb +16 -0
  280. data/spec/update/gems_spec.rb +201 -0
  281. data/spec/update/git_spec.rb +236 -0
  282. data/spec/update/source_spec.rb +63 -0
  283. data/spec/update/svn_spec.rb +100 -0
  284. metadata +486 -0
@@ -0,0 +1,64 @@
1
+ module Bundler
2
+ class Injector
3
+ def self.inject(new_deps)
4
+ injector = new(new_deps)
5
+ injector.inject(Bundler.default_gemfile, Bundler.default_lockfile)
6
+ end
7
+
8
+ def initialize(new_deps)
9
+ @new_deps = new_deps
10
+ end
11
+
12
+ def inject(gemfile_path, lockfile_path)
13
+ if Bundler.settings[:frozen]
14
+ # ensure the lock and Gemfile are synced
15
+ Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true)
16
+ # temporarily remove frozen while we inject
17
+ frozen = Bundler.settings.delete(:frozen)
18
+ end
19
+
20
+ # evaluate the Gemfile we have now
21
+ builder = Dsl.new
22
+ builder.eval_gemfile(gemfile_path)
23
+
24
+ # don't inject any gems that are already in the Gemfile
25
+ @new_deps -= builder.dependencies
26
+
27
+ # add new deps to the end of the in-memory Gemfile
28
+ builder.eval_gemfile("injected gems", new_gem_lines) if @new_deps.any?
29
+
30
+ # resolve to see if the new deps broke anything
31
+ definition = builder.to_definition(lockfile_path, {})
32
+ definition.resolve_remotely!
33
+
34
+ # since nothing broke, we can add those gems to the gemfile
35
+ append_to(gemfile_path) if @new_deps.any?
36
+
37
+ # since we resolved successfully, write out the lockfile
38
+ definition.lock(Bundler.default_lockfile)
39
+
40
+ # return an array of the deps that we added
41
+ return @new_deps
42
+ ensure
43
+ Bundler.settings[:frozen] = '1' if frozen
44
+ end
45
+
46
+ private
47
+
48
+ def new_gem_lines
49
+ @new_deps.map do |d|
50
+ %|gem '#{d.name}', '#{d.requirement}'|
51
+ end.join("\n")
52
+ end
53
+
54
+ def append_to(gemfile_path)
55
+ gemfile_path.open("a") do |f|
56
+ f.puts
57
+ f.puts "# Added at #{Time.now} by #{`whoami`.chomp}:"
58
+ f.puts new_gem_lines
59
+ end
60
+ end
61
+
62
+
63
+ end
64
+ end
@@ -0,0 +1,332 @@
1
+ require 'erb'
2
+ require 'rubygems/dependency_installer'
3
+ require 'bundler/parallel_workers'
4
+
5
+ module Bundler
6
+ class Installer < Environment
7
+ class << self
8
+ attr_accessor :post_install_messages
9
+ end
10
+
11
+ # Begins the installation process for Bundler.
12
+ # For more information see the #run method on this class.
13
+ def self.install(root, definition, options = {})
14
+ installer = new(root, definition)
15
+ installer.run(options)
16
+ installer
17
+ end
18
+
19
+ # Runs the install procedures for a specific Gemfile.
20
+ #
21
+ # Firstly, this method will check to see if Bundler.bundle_path exists
22
+ # and if not then will create it. This is usually the location of gems
23
+ # on the system, be it RVM or at a system path.
24
+ #
25
+ # Secondly, it checks if Bundler has been configured to be "frozen"
26
+ # Frozen ensures that the Gemfile and the Gemfile.lock file are matching.
27
+ # This stops a situation where a developer may update the Gemfile but may not run
28
+ # `bundle install`, which leads to the Gemfile.lock file not being correctly updated.
29
+ # If this file is not correctly updated then any other developer running
30
+ # `bundle install` will potentially not install the correct gems.
31
+ #
32
+ # Thirdly, Bundler checks if there are any dependencies specified in the Gemfile using
33
+ # Bundler::Environment#dependencies. If there are no dependencies specified then
34
+ # Bundler returns a warning message stating so and this method returns.
35
+ #
36
+ # Fourthly, Bundler checks if the default lockfile (Gemfile.lock) exists, and if so
37
+ # then proceeds to set up a defintion based on the default gemfile (Gemfile) and the
38
+ # default lock file (Gemfile.lock). However, this is not the case if the platform is different
39
+ # to that which is specified in Gemfile.lock, or if there are any missing specs for the gems.
40
+ #
41
+ # Fifthly, Bundler resolves the dependencies either through a cache of gems or by remote.
42
+ # This then leads into the gems being installed, along with stubs for their executables,
43
+ # but only if the --binstubs option has been passed or Bundler.options[:bin] has been set
44
+ # earlier.
45
+ #
46
+ # Sixthly, a new Gemfile.lock is created from the installed gems to ensure that the next time
47
+ # that a user runs `bundle install` they will receive any updates from this process.
48
+ #
49
+ # Finally: TODO add documentation for how the standalone process works.
50
+ def run(options)
51
+ create_bundle_path
52
+
53
+ if Bundler.settings[:frozen]
54
+ @definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment])
55
+ end
56
+
57
+ if dependencies.empty?
58
+ Bundler.ui.warn "The Gemfile specifies no dependencies"
59
+ lock
60
+ return
61
+ end
62
+
63
+ if Bundler.default_lockfile.exist? && !options["update"]
64
+ local = Bundler.ui.silence do
65
+ begin
66
+ tmpdef = Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, nil)
67
+ true unless tmpdef.new_platform? || tmpdef.missing_specs.any?
68
+ rescue BundlerError
69
+ end
70
+ end
71
+ end
72
+
73
+ # Since we are installing, we can resolve the definition
74
+ # using remote specs
75
+ unless local
76
+ options["local"] ? @definition.resolve_with_cache! : @definition.resolve_remotely!
77
+ end
78
+ # Must install gems in the order that the resolver provides
79
+ # as dependencies might actually affect the installation of
80
+ # the gem.
81
+ Installer.post_install_messages = {}
82
+
83
+ # the order that the resolver provides is significant, since
84
+ # dependencies might actually affect the installation of a gem.
85
+ # that said, it's a rare situation (other than rake), and parallel
86
+ # installation is just SO MUCH FASTER. so we let people opt in.
87
+ jobs = [Bundler.settings[:jobs].to_i-1, 1].max
88
+ if jobs > 1 && can_install_parallely?
89
+ install_in_parallel jobs, options[:standalone]
90
+ else
91
+ install_sequentially options[:standalone]
92
+ end
93
+
94
+ lock unless Bundler.settings[:frozen]
95
+ generate_standalone(options[:standalone]) if options[:standalone]
96
+ end
97
+
98
+ def install_gem_from_spec(spec, standalone = false, worker = 0)
99
+ # Fetch the build settings, if there are any
100
+ settings = Bundler.settings["build.#{spec.name}"]
101
+ install_message = nil
102
+ post_install_message = nil
103
+ debug_message = nil
104
+ Bundler.rubygems.with_build_args [settings] do
105
+ install_message, post_install_message, debug_message = spec.source.install(spec)
106
+ if install_message.include? 'Installing'
107
+ Bundler.ui.confirm install_message
108
+ else
109
+ Bundler.ui.info install_message
110
+ end
111
+ Bundler.ui.debug debug_message if debug_message
112
+ Bundler.ui.debug "#{worker}: #{spec.name} (#{spec.version}) from #{spec.loaded_from}"
113
+ end
114
+
115
+ if Bundler.settings[:bin] && standalone
116
+ generate_standalone_bundler_executable_stubs(spec)
117
+ elsif Bundler.settings[:bin]
118
+ generate_bundler_executable_stubs(spec, :force => true)
119
+ end
120
+
121
+ post_install_message
122
+ rescue Exception => e
123
+ # if install hook failed or gem signature is bad, just die
124
+ raise e if e.is_a?(Bundler::InstallHookError) || e.is_a?(Bundler::SecurityError)
125
+
126
+ # other failure, likely a native extension build failure
127
+ Bundler.ui.info ""
128
+ Bundler.ui.warn "#{e.class}: #{e.message}"
129
+ msg = "An error occurred while installing #{spec.name} (#{spec.version}),"
130
+ msg << " and Bundler cannot continue."
131
+
132
+ unless spec.source.options["git"]
133
+ msg << "\nMake sure that `gem install"
134
+ msg << " #{spec.name} -v '#{spec.version}'` succeeds before bundling."
135
+ end
136
+ Bundler.ui.debug e.backtrace.join("\n")
137
+ raise Bundler::InstallError, msg
138
+ end
139
+
140
+ def generate_bundler_executable_stubs(spec, options = {})
141
+ if options[:binstubs_cmd] && spec.executables.empty?
142
+ options = {}
143
+ spec.runtime_dependencies.each do |dep|
144
+ bins = @definition.specs[dep].first.executables
145
+ options[dep.name] = bins unless bins.empty?
146
+ end
147
+ if options.any?
148
+ Bundler.ui.warn "#{spec.name} has no executables, but you may want " +
149
+ "one from a gem it depends on."
150
+ options.each{|name,bins| Bundler.ui.warn " #{name} has: #{bins.join(', ')}" }
151
+ else
152
+ Bundler.ui.warn "There are no executables for the gem #{spec.name}."
153
+ end
154
+ return
155
+ end
156
+
157
+ # double-assignment to avoid warnings about variables that will be used by ERB
158
+ bin_path = bin_path = Bundler.bin_path
159
+ template = template = File.read(File.expand_path('../templates/Executable', __FILE__))
160
+ relative_gemfile_path = relative_gemfile_path = Bundler.default_gemfile.relative_path_from(bin_path)
161
+ ruby_command = ruby_command = Thor::Util.ruby_command
162
+
163
+ exists = []
164
+ spec.executables.each do |executable|
165
+ next if executable == "bundle"
166
+
167
+ binstub_path = "#{bin_path}/#{executable}"
168
+ if File.exist?(binstub_path) && !options[:force]
169
+ exists << executable
170
+ next
171
+ end
172
+
173
+ File.open(binstub_path, 'w', 0777 & ~File.umask) do |f|
174
+ f.puts ERB.new(template, nil, '-').result(binding)
175
+ end
176
+ end
177
+
178
+ if options[:binstubs_cmd] && exists.any?
179
+ case exists.size
180
+ when 1
181
+ Bundler.ui.warn "Skipped #{exists[0]} since it already exists."
182
+ when 2
183
+ Bundler.ui.warn "Skipped #{exists.join(' and ')} since they already exist."
184
+ else
185
+ items = exists[0...-1].empty? ? nil : exists[0...-1].join(', ')
186
+ skipped = [items, exists[-1]].compact.join(' and ')
187
+ Bundler.ui.warn "Skipped #{skipped} since they already exist."
188
+ end
189
+ Bundler.ui.warn "If you want to overwrite skipped stubs, use --force."
190
+ end
191
+ end
192
+
193
+ private
194
+
195
+ def can_install_parallely?
196
+ min_rubygems = "2.0.7"
197
+ if Bundler.current_ruby.mri? || Bundler.rubygems.provides?(">= #{min_rubygems}")
198
+ true
199
+ else
200
+ Bundler.ui.warn "Rubygems #{Gem::VERSION} is not threadsafe, so your "\
201
+ "gems must be installed one at a time. Upgrade to Rubygems " \
202
+ "#{min_rubygems} or higher to enable parallel gem installation."
203
+ false
204
+ end
205
+ end
206
+
207
+ def generate_standalone_bundler_executable_stubs(spec)
208
+ # double-assignment to avoid warnings about variables that will be used by ERB
209
+ bin_path = Bundler.bin_path
210
+ template = File.read(File.expand_path('../templates/Executable.standalone', __FILE__))
211
+ ruby_command = ruby_command = Thor::Util.ruby_command
212
+
213
+ spec.executables.each do |executable|
214
+ next if executable == "bundle"
215
+ standalone_path = standalone_path = Pathname(Bundler.settings[:path]).expand_path.relative_path_from(bin_path)
216
+ executable_path = executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
217
+ File.open "#{bin_path}/#{executable}", 'w', 0755 do |f|
218
+ f.puts ERB.new(template, nil, '-').result(binding)
219
+ end
220
+ end
221
+ end
222
+
223
+ def generate_standalone(groups)
224
+ standalone_path = Bundler.settings[:path]
225
+ bundler_path = File.join(standalone_path, "bundler")
226
+ FileUtils.mkdir_p(bundler_path)
227
+
228
+ paths = []
229
+
230
+ if groups.empty?
231
+ specs = @definition.requested_specs
232
+ else
233
+ specs = @definition.specs_for groups.map { |g| g.to_sym }
234
+ end
235
+
236
+ specs.each do |spec|
237
+ next if spec.name == "bundler"
238
+ next if spec.require_paths.nil? # builtin gems
239
+
240
+ spec.require_paths.each do |path|
241
+ full_path = File.join(spec.full_gem_path, path)
242
+ gem_path = Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path))
243
+ paths << gem_path.to_s.sub("#{Bundler.ruby_version.engine}/#{RbConfig::CONFIG['ruby_version']}", '#{ruby_engine}/#{ruby_version}')
244
+ end
245
+ end
246
+
247
+
248
+ File.open File.join(bundler_path, "setup.rb"), "w" do |file|
249
+ file.puts "require 'rbconfig'"
250
+ file.puts "# ruby 1.8.7 doesn't define RUBY_ENGINE"
251
+ file.puts "ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'"
252
+ file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]"
253
+ file.puts "path = File.expand_path('..', __FILE__)"
254
+ paths.each do |path|
255
+ file.puts %{$:.unshift "\#{path}/#{path}"}
256
+ end
257
+ end
258
+ end
259
+
260
+ def install_sequentially(standalone)
261
+ specs.each do |spec|
262
+ message = install_gem_from_spec spec, standalone, 0
263
+ if message
264
+ Installer.post_install_messages[spec.name] = message
265
+ end
266
+ end
267
+ end
268
+
269
+ def install_in_parallel(size, standalone)
270
+ name2spec = {}
271
+ remains = {}
272
+ enqueued = {}
273
+ specs.each do |spec|
274
+ name2spec[spec.name] = spec
275
+ remains[spec.name] = true
276
+ end
277
+
278
+ worker_pool = ParallelWorkers.worker_pool size, lambda { |name, worker|
279
+ spec = name2spec[name]
280
+ message = install_gem_from_spec spec, standalone, worker
281
+ { :name => spec.name, :post_install => message }
282
+ }
283
+
284
+ # Keys in the remains hash represent uninstalled gems specs.
285
+ # We enqueue all gem specs that do not have any dependencies.
286
+ # Later we call this lambda again to install specs that depended on
287
+ # previously installed specifications. We continue until all specs
288
+ # are installed.
289
+ enqueue_remaining_specs = lambda do
290
+ remains.keys.each do |name|
291
+ next if enqueued[name]
292
+ spec = name2spec[name]
293
+ if ready_to_install?(spec, remains)
294
+ worker_pool.enq name
295
+ enqueued[name] = true
296
+ end
297
+ end
298
+ end
299
+ enqueue_remaining_specs.call
300
+
301
+ until remains.empty?
302
+ message = worker_pool.deq
303
+ remains.delete message[:name]
304
+ if message[:post_install]
305
+ Installer.post_install_messages[message[:name]] = message[:post_install]
306
+ end
307
+ enqueue_remaining_specs.call
308
+ end
309
+ message
310
+ ensure
311
+ worker_pool && worker_pool.stop
312
+ end
313
+
314
+ # We only want to install a gem spec if all its dependencies are met.
315
+ # If the dependency is no longer in the `remains` hash then it has been met.
316
+ # If a dependency is only development or is self referential it can be ignored.
317
+ def ready_to_install?(spec, remains)
318
+ spec.dependencies.none? do |dep|
319
+ next if dep.type == :development || dep.name == spec.name
320
+ remains[dep.name]
321
+ end
322
+ end
323
+
324
+ def create_bundle_path
325
+ Bundler.mkdir_p(Bundler.bundle_path.to_s) unless Bundler.bundle_path.exist?
326
+ rescue Errno::EEXIST
327
+ raise PathError, "Could not install to path `#{Bundler.settings[:path]}` " +
328
+ "because of an invalid symlink. Remove the symlink so the directory can be created."
329
+ end
330
+
331
+ end
332
+ end
@@ -0,0 +1,83 @@
1
+ require "uri"
2
+ require "rubygems/spec_fetcher"
3
+ require "bundler/match_platform"
4
+
5
+ module Bundler
6
+ class LazySpecification
7
+ include MatchPlatform
8
+
9
+ attr_reader :name, :version, :dependencies, :platform
10
+ attr_accessor :source, :source_uri
11
+
12
+ def initialize(name, version, platform, source = nil)
13
+ @name = name
14
+ @version = version
15
+ @dependencies = []
16
+ @platform = platform
17
+ @source = source
18
+ @specification = nil
19
+ end
20
+
21
+ def full_name
22
+ if platform == Gem::Platform::RUBY or platform.nil? then
23
+ "#{@name}-#{@version}"
24
+ else
25
+ "#{@name}-#{@version}-#{platform}"
26
+ end
27
+ end
28
+
29
+ def ==(other)
30
+ identifier == other.identifier
31
+ end
32
+
33
+ def satisfies?(dependency)
34
+ @name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version))
35
+ end
36
+
37
+ def to_lock
38
+ if platform == Gem::Platform::RUBY or platform.nil?
39
+ out = " #{name} (#{version})\n"
40
+ else
41
+ out = " #{name} (#{version}-#{platform})\n"
42
+ end
43
+
44
+ dependencies.sort_by {|d| d.to_s }.each do |dep|
45
+ next if dep.type == :development
46
+ out << " #{dep.to_lock}\n"
47
+ end
48
+
49
+ out
50
+ end
51
+
52
+ def __materialize__
53
+ @specification = source.specs.search(Gem::Dependency.new(name, version)).last
54
+ end
55
+
56
+ def respond_to?(*args)
57
+ super || @specification.respond_to?(*args)
58
+ end
59
+
60
+ def to_s
61
+ @__to_s ||= "#{name} (#{version})"
62
+ end
63
+
64
+ def identifier
65
+ @__identifier ||= [name, version, source, platform, dependencies].hash
66
+ end
67
+
68
+ private
69
+
70
+ def to_ary
71
+ nil
72
+ end
73
+
74
+ def method_missing(method, *args, &blk)
75
+ raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification
76
+
77
+ return super unless respond_to?(method)
78
+
79
+ @specification.send(method, *args, &blk)
80
+ end
81
+
82
+ end
83
+ end