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,146 @@
1
+ require "strscan"
2
+
3
+ # Some versions of the Bundler 1.1 RC series introduced corrupted
4
+ # lockfiles. There were two major problems:
5
+ #
6
+ # * multiple copies of the same GIT section appeared in the lockfile
7
+ # * when this happened, those sections got multiple copies of gems
8
+ # in those sections.
9
+ #
10
+ # As a result, Bundler 1.1 contains code that fixes the earlier
11
+ # corruption. We will remove this fix-up code in Bundler 1.2.
12
+
13
+ module Bundler
14
+ class LockfileParser
15
+ attr_reader :sources, :dependencies, :specs, :platforms
16
+
17
+ DEPENDENCIES = "DEPENDENCIES"
18
+ PLATFORMS = "PLATFORMS"
19
+ GIT = "GIT"
20
+ GEM = "GEM"
21
+ PATH = "PATH"
22
+ SVN = "SVN"
23
+ SPECS = " specs:"
24
+ OPTIONS = /^ ([a-z]+): (.*)$/i
25
+
26
+ def initialize(lockfile)
27
+ @platforms = []
28
+ @sources = []
29
+ @dependencies = []
30
+ @state = :source
31
+ @specs = {}
32
+
33
+ if lockfile.match(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
34
+ raise LockfileError, "Your Gemfile.lock contains merge conflicts.\n" \
35
+ "Run `git checkout HEAD -- Gemfile.lock` first to get a clean lock."
36
+ end
37
+
38
+ lockfile.split(/(?:\r?\n)+/).each do |line|
39
+ if line == DEPENDENCIES
40
+ @state = :dependency
41
+ elsif line == PLATFORMS
42
+ @state = :platform
43
+ else
44
+ send("parse_#{@state}", line)
45
+ end
46
+ end
47
+ @specs = @specs.values
48
+ end
49
+
50
+ private
51
+
52
+ TYPES = {
53
+ "GIT" => Bundler::Source::Git,
54
+ "GEM" => Bundler::Source::Rubygems,
55
+ "PATH" => Bundler::Source::Path,
56
+ "SVN" => Bundler::Source::SVN
57
+ }
58
+
59
+ def parse_source(line)
60
+ case line
61
+ when GIT, GEM, PATH, SVN
62
+ @current_source = nil
63
+ @opts, @type = {}, line
64
+ when SPECS
65
+ @current_source = TYPES[@type].from_lock(@opts)
66
+
67
+ # Strip out duplicate GIT / SVN sections
68
+ if @sources.include?(@current_source) && (@current_source.is_a?(Bundler::Source::Git) || @current_source.is_a?(Bundler::Source::SVN))
69
+ @current_source = @sources.find { |s| s == @current_source }
70
+ end
71
+
72
+ @sources << @current_source
73
+ when OPTIONS
74
+ value = $2
75
+ value = true if value == "true"
76
+ value = false if value == "false"
77
+
78
+ key = $1
79
+
80
+ if @opts[key]
81
+ @opts[key] = Array(@opts[key])
82
+ @opts[key] << value
83
+ else
84
+ @opts[key] = value
85
+ end
86
+ else
87
+ parse_spec(line)
88
+ end
89
+ end
90
+
91
+ NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'
92
+ NAME_VERSION_2 = %r{^ {2}#{NAME_VERSION}(!)?$}
93
+ NAME_VERSION_4 = %r{^ {4}#{NAME_VERSION}$}
94
+ NAME_VERSION_6 = %r{^ {6}#{NAME_VERSION}$}
95
+
96
+ def parse_dependency(line)
97
+ if line =~ NAME_VERSION_2
98
+ name, version, pinned = $1, $2, $4
99
+ version = version.split(",").map { |d| d.strip } if version
100
+
101
+ dep = Bundler::Dependency.new(name, version)
102
+
103
+ if pinned && dep.name != 'bundler'
104
+ spec = @specs.find {|k, v| v.name == dep.name }
105
+ dep.source = spec.last.source if spec
106
+
107
+ # Path sources need to know what the default name / version
108
+ # to use in the case that there are no gemspecs present. A fake
109
+ # gemspec is created based on the version set on the dependency
110
+ # TODO: Use the version from the spec instead of from the dependency
111
+ if version && version.size == 1 && version.first =~ /^\s*= (.+)\s*$/ && dep.source.is_a?(Bundler::Source::Path)
112
+ dep.source.name = name
113
+ dep.source.version = $1
114
+ end
115
+ end
116
+
117
+ @dependencies << dep
118
+ end
119
+ end
120
+
121
+ def parse_spec(line)
122
+ if line =~ NAME_VERSION_4
123
+ name, version = $1, Gem::Version.new($2)
124
+ platform = $3 ? Gem::Platform.new($3) : Gem::Platform::RUBY
125
+ @current_spec = LazySpecification.new(name, version, platform)
126
+ @current_spec.source = @current_source
127
+
128
+ # Avoid introducing multiple copies of the same spec (caused by
129
+ # duplicate GIT sections)
130
+ @specs[@current_spec.identifier] ||= @current_spec
131
+ elsif line =~ NAME_VERSION_6
132
+ name, version = $1, $2
133
+ version = version.split(',').map { |d| d.strip } if version
134
+ dep = Gem::Dependency.new(name, version)
135
+ @current_spec.dependencies << dep
136
+ end
137
+ end
138
+
139
+ def parse_platform(line)
140
+ if line =~ /^ (.*)$/
141
+ @platforms << Gem::Platform.new($1)
142
+ end
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_helpers'
2
+
3
+ module Bundler
4
+ module MatchPlatform
5
+ include GemHelpers
6
+
7
+ def match_platform(p)
8
+ Gem::Platform::RUBY == platform or
9
+ platform.nil? or p == platform or
10
+ generic(Gem::Platform.new(platform)) == p
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'thread'
2
+
3
+ require "bundler/parallel_workers/worker"
4
+
5
+ module Bundler
6
+ module ParallelWorkers
7
+ autoload :UnixWorker, "bundler/parallel_workers/unix_worker"
8
+ autoload :ThreadWorker, "bundler/parallel_workers/thread_worker"
9
+
10
+ def self.worker_pool(size, job)
11
+ if Bundler.current_ruby.mswin? || Bundler.current_ruby.jruby? || Bundler.current_ruby.rbx?
12
+ ThreadWorker.new(size, job)
13
+ else
14
+ UnixWorker.new(size, job)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Bundler
2
+ module ParallelWorkers
3
+ class ThreadWorker < Worker
4
+
5
+ private
6
+
7
+ # On platforms where fork is not available
8
+ # use Threads for parallely downloading gems
9
+ #
10
+ # @param size [Integer] Size of thread worker pool
11
+ # @param func [Proc] Job to be run inside thread worker pool
12
+ def prepare_workers(size, func)
13
+ @threads = size.times.map do |i|
14
+ Thread.start do
15
+ loop do
16
+ obj = @request_queue.deq
17
+ break if obj.equal? POISON
18
+ begin
19
+ @response_queue.enq func.call(obj, i)
20
+ rescue Exception => e
21
+ @response_queue.enq(WrappedException.new(e))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,101 @@
1
+ module Bundler
2
+ module ParallelWorkers
3
+ # UnixWorker is used only on platforms where fork is available. The way
4
+ # this code works is, it forks a preconfigured number of workers and then
5
+ # It starts preconfigured number of threads that write to the connected pipe.
6
+ class UnixWorker < Worker
7
+
8
+ class JobHandler < Struct.new(:pid, :io_r, :io_w)
9
+ def work(obj)
10
+ Marshal.dump obj, io_w
11
+ Marshal.load io_r
12
+ rescue IOError, Errno::EPIPE
13
+ nil
14
+ end
15
+ end
16
+
17
+ def initialize(size, job)
18
+ # Close the persistent connections for the main thread before forking
19
+ Net::HTTP::Persistent.new('bundler', :ENV).shutdown
20
+ super
21
+ end
22
+
23
+ private
24
+
25
+ # Start forked workers for downloading gems. This version of worker
26
+ # is only used on platforms where fork is available.
27
+ #
28
+ # @param size [Integer] Size of worker pool
29
+ # @param func [Proc] Job that should be executed in the worker
30
+ def prepare_workers(size, func)
31
+ @workers = size.times.map do |num|
32
+ child_read, parent_write = IO.pipe
33
+ parent_read, child_write = IO.pipe
34
+
35
+ pid = Process.fork do
36
+ begin
37
+ parent_read.close
38
+ parent_write.close
39
+
40
+ while !child_read.eof?
41
+ obj = Marshal.load child_read
42
+ Marshal.dump func.call(obj, num), child_write
43
+ end
44
+ rescue Exception => e
45
+ begin
46
+ Marshal.dump WrappedException.new(e), child_write
47
+ rescue Errno::EPIPE
48
+ nil
49
+ end
50
+ ensure
51
+ child_read.close
52
+ child_write.close
53
+ end
54
+ end
55
+
56
+ child_read.close
57
+ child_write.close
58
+ JobHandler.new pid, parent_read, parent_write
59
+ end
60
+ end
61
+
62
+ # Start the threads whose job is basically to wait for incoming messages
63
+ # on request queue and write that message to the connected pipe. Also retrieve
64
+ # messages from child worker via connected pipe and write the message to response queue
65
+ #
66
+ # @param size [Integer] Number of threads to be started
67
+ def prepare_threads(size)
68
+ @threads = size.times.map do |i|
69
+ Thread.start do
70
+ worker = @workers[i]
71
+ loop do
72
+ obj = @request_queue.deq
73
+ break if obj.equal? POISON
74
+ @response_queue.enq worker.work(obj)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ # Kill the forked workers by sending SIGINT to them
81
+ def stop_workers
82
+ @workers.each do |worker|
83
+ worker.io_r.close unless worker.io_r.closed?
84
+ worker.io_w.close unless worker.io_w.closed?
85
+ begin
86
+ Process.kill :INT, worker.pid
87
+ rescue Errno::ESRCH
88
+ nil
89
+ end
90
+ end
91
+ @workers.each do |worker|
92
+ begin
93
+ Process.waitpid worker.pid
94
+ rescue Errno::ECHILD
95
+ nil
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,69 @@
1
+ module Bundler
2
+ module ParallelWorkers
3
+ class Worker
4
+ POISON = Object.new
5
+
6
+ class WrappedException < StandardError
7
+ attr_reader :exception
8
+ def initialize(exn)
9
+ @exception = exn
10
+ end
11
+ end
12
+
13
+ # Creates a worker pool of specified size
14
+ #
15
+ # @param size [Integer] Size of pool
16
+ # @param func [Proc] job to run in inside the worker pool
17
+ def initialize(size, func)
18
+ @request_queue = Queue.new
19
+ @response_queue = Queue.new
20
+ prepare_workers size, func
21
+ prepare_threads size
22
+ trap("INT") { @threads.each {|i| i.exit }; stop_workers; exit 1 }
23
+ end
24
+
25
+ # Enqueue a request to be executed in the worker pool
26
+ #
27
+ # @param obj [String] mostly it is name of spec that should be downloaded
28
+ def enq(obj)
29
+ @request_queue.enq obj
30
+ end
31
+
32
+ # Retrieves results of job function being executed in worker pool
33
+ def deq
34
+ result = @response_queue.deq
35
+ if result.is_a?(WrappedException)
36
+ raise result.exception
37
+ end
38
+ result
39
+ end
40
+
41
+ # Stop the forked workers and started threads
42
+ def stop
43
+ stop_threads
44
+ stop_workers
45
+ end
46
+
47
+ private
48
+ # Stop the worker threads by sending a poison object down the request queue
49
+ # so as worker threads after retrieving it, shut themselves down
50
+ def stop_threads
51
+ @threads.each do
52
+ @request_queue.enq POISON
53
+ end
54
+ @threads.each do |thread|
55
+ thread.join
56
+ end
57
+ end
58
+
59
+ # To be overridden by child classes
60
+ def prepare_threads(size)
61
+ end
62
+
63
+ # To be overridden by child classes
64
+ def stop_workers
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,26 @@
1
+ # Psych could be a gem, so try to ask for it
2
+ begin
3
+ gem 'psych'
4
+ rescue LoadError
5
+ end if defined?(gem)
6
+
7
+ # Psych could just be in the stdlib
8
+ # but it's too late if Syck is already loaded
9
+ begin
10
+ require 'psych' unless defined?(Syck)
11
+ rescue LoadError
12
+ # Apparently Psych wasn't available. Oh well.
13
+ end
14
+
15
+ # At least load the YAML stdlib, whatever that may be
16
+ require 'yaml' unless defined?(YAML.dump)
17
+
18
+ module Bundler
19
+ # On encountering invalid YAML,
20
+ # Psych raises Psych::SyntaxError
21
+ if defined?(::Psych::SyntaxError)
22
+ YamlSyntaxError = ::Psych::SyntaxError
23
+ else # Syck raises ArgumentError
24
+ YamlSyntaxError = ::ArgumentError
25
+ end
26
+ end
@@ -0,0 +1,57 @@
1
+ require "uri"
2
+ require "rubygems/spec_fetcher"
3
+
4
+ module Bundler
5
+ # Represents a lazily loaded gem specification, where the full specification
6
+ # is on the source server in rubygems' "quick" index. The proxy object is to
7
+ # be seeded with what we're given from the source's abbreviated index - the
8
+ # full specification will only be fetched when necessary.
9
+ class RemoteSpecification
10
+ include MatchPlatform
11
+
12
+ attr_reader :name, :version, :platform
13
+ attr_accessor :source, :source_uri
14
+
15
+ def initialize(name, version, platform, spec_fetcher)
16
+ @name = name
17
+ @version = version
18
+ @platform = platform
19
+ @spec_fetcher = spec_fetcher
20
+ end
21
+
22
+ # Needed before installs, since the arch matters then and quick
23
+ # specs don't bother to include the arch in the platform string
24
+ def fetch_platform
25
+ @platform = _remote_specification.platform
26
+ end
27
+
28
+ def full_name
29
+ if platform == Gem::Platform::RUBY or platform.nil? then
30
+ "#{@name}-#{@version}"
31
+ else
32
+ "#{@name}-#{@version}-#{platform}"
33
+ end
34
+ end
35
+
36
+ # Because Rubyforge cannot be trusted to provide valid specifications
37
+ # once the remote gem is downloaded, the backend specification will
38
+ # be swapped out.
39
+ def __swap__(spec)
40
+ @specification = spec
41
+ end
42
+
43
+ private
44
+
45
+ def _remote_specification
46
+ @specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform])
47
+ end
48
+
49
+ def method_missing(method, *args, &blk)
50
+ if Gem::Specification.new.respond_to?(method)
51
+ _remote_specification.send(method, *args, &blk)
52
+ else
53
+ super
54
+ end
55
+ end
56
+ end
57
+ end