bundler 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bundler might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3111 -0
- data/LICENSE.md +23 -0
- data/README.md +63 -0
- data/bundler.gemspec +65 -0
- data/exe/bundle +31 -0
- data/exe/bundle_ruby +60 -0
- data/exe/bundler +4 -0
- data/lib/bundler.rb +567 -0
- data/lib/bundler/build_metadata.rb +53 -0
- data/lib/bundler/capistrano.rb +22 -0
- data/lib/bundler/cli.rb +792 -0
- data/lib/bundler/cli/add.rb +35 -0
- data/lib/bundler/cli/binstubs.rb +49 -0
- data/lib/bundler/cli/cache.rb +36 -0
- data/lib/bundler/cli/check.rb +38 -0
- data/lib/bundler/cli/clean.rb +25 -0
- data/lib/bundler/cli/common.rb +102 -0
- data/lib/bundler/cli/config.rb +119 -0
- data/lib/bundler/cli/console.rb +43 -0
- data/lib/bundler/cli/doctor.rb +140 -0
- data/lib/bundler/cli/exec.rb +105 -0
- data/lib/bundler/cli/gem.rb +252 -0
- data/lib/bundler/cli/info.rb +50 -0
- data/lib/bundler/cli/init.rb +47 -0
- data/lib/bundler/cli/inject.rb +60 -0
- data/lib/bundler/cli/install.rb +218 -0
- data/lib/bundler/cli/issue.rb +40 -0
- data/lib/bundler/cli/list.rb +58 -0
- data/lib/bundler/cli/lock.rb +63 -0
- data/lib/bundler/cli/open.rb +26 -0
- data/lib/bundler/cli/outdated.rb +266 -0
- data/lib/bundler/cli/package.rb +49 -0
- data/lib/bundler/cli/platform.rb +46 -0
- data/lib/bundler/cli/plugin.rb +24 -0
- data/lib/bundler/cli/pristine.rb +47 -0
- data/lib/bundler/cli/remove.rb +18 -0
- data/lib/bundler/cli/show.rb +75 -0
- data/lib/bundler/cli/update.rb +91 -0
- data/lib/bundler/cli/viz.rb +31 -0
- data/lib/bundler/compact_index_client.rb +109 -0
- data/lib/bundler/compact_index_client/cache.rb +118 -0
- data/lib/bundler/compact_index_client/updater.rb +116 -0
- data/lib/bundler/compatibility_guard.rb +13 -0
- data/lib/bundler/constants.rb +7 -0
- data/lib/bundler/current_ruby.rb +94 -0
- data/lib/bundler/definition.rb +995 -0
- data/lib/bundler/dep_proxy.rb +48 -0
- data/lib/bundler/dependency.rb +139 -0
- data/lib/bundler/deployment.rb +69 -0
- data/lib/bundler/deprecate.rb +44 -0
- data/lib/bundler/dsl.rb +615 -0
- data/lib/bundler/endpoint_specification.rb +141 -0
- data/lib/bundler/env.rb +149 -0
- data/lib/bundler/environment_preserver.rb +59 -0
- data/lib/bundler/errors.rb +158 -0
- data/lib/bundler/feature_flag.rb +75 -0
- data/lib/bundler/fetcher.rb +312 -0
- data/lib/bundler/fetcher/base.rb +52 -0
- data/lib/bundler/fetcher/compact_index.rb +126 -0
- data/lib/bundler/fetcher/dependency.rb +82 -0
- data/lib/bundler/fetcher/downloader.rb +84 -0
- data/lib/bundler/fetcher/index.rb +52 -0
- data/lib/bundler/friendly_errors.rb +131 -0
- data/lib/bundler/gem_helper.rb +217 -0
- data/lib/bundler/gem_helpers.rb +101 -0
- data/lib/bundler/gem_remote_fetcher.rb +43 -0
- data/lib/bundler/gem_tasks.rb +7 -0
- data/lib/bundler/gem_version_promoter.rb +190 -0
- data/lib/bundler/gemdeps.rb +29 -0
- data/lib/bundler/graph.rb +152 -0
- data/lib/bundler/index.rb +213 -0
- data/lib/bundler/injector.rb +253 -0
- data/lib/bundler/inline.rb +74 -0
- data/lib/bundler/installer.rb +318 -0
- data/lib/bundler/installer/gem_installer.rb +85 -0
- data/lib/bundler/installer/parallel_installer.rb +229 -0
- data/lib/bundler/installer/standalone.rb +53 -0
- data/lib/bundler/lazy_specification.rb +123 -0
- data/lib/bundler/lockfile_generator.rb +95 -0
- data/lib/bundler/lockfile_parser.rb +256 -0
- data/lib/bundler/match_platform.rb +24 -0
- data/lib/bundler/mirror.rb +223 -0
- data/lib/bundler/plugin.rb +294 -0
- data/lib/bundler/plugin/api.rb +81 -0
- data/lib/bundler/plugin/api/source.rb +306 -0
- data/lib/bundler/plugin/dsl.rb +53 -0
- data/lib/bundler/plugin/events.rb +61 -0
- data/lib/bundler/plugin/index.rb +165 -0
- data/lib/bundler/plugin/installer.rb +96 -0
- data/lib/bundler/plugin/installer/git.rb +38 -0
- data/lib/bundler/plugin/installer/rubygems.rb +27 -0
- data/lib/bundler/plugin/source_list.rb +27 -0
- data/lib/bundler/process_lock.rb +24 -0
- data/lib/bundler/psyched_yaml.rb +37 -0
- data/lib/bundler/remote_specification.rb +114 -0
- data/lib/bundler/resolver.rb +373 -0
- data/lib/bundler/resolver/spec_group.rb +106 -0
- data/lib/bundler/retry.rb +66 -0
- data/lib/bundler/ruby_dsl.rb +18 -0
- data/lib/bundler/ruby_version.rb +152 -0
- data/lib/bundler/rubygems_ext.rb +209 -0
- data/lib/bundler/rubygems_gem_installer.rb +99 -0
- data/lib/bundler/rubygems_integration.rb +915 -0
- data/lib/bundler/runtime.rb +322 -0
- data/lib/bundler/settings.rb +464 -0
- data/lib/bundler/settings/validator.rb +102 -0
- data/lib/bundler/setup.rb +28 -0
- data/lib/bundler/shared_helpers.rb +386 -0
- data/lib/bundler/similarity_detector.rb +63 -0
- data/lib/bundler/source.rb +94 -0
- data/lib/bundler/source/gemspec.rb +18 -0
- data/lib/bundler/source/git.rb +329 -0
- data/lib/bundler/source/git/git_proxy.rb +262 -0
- data/lib/bundler/source/metadata.rb +62 -0
- data/lib/bundler/source/path.rb +249 -0
- data/lib/bundler/source/path/installer.rb +74 -0
- data/lib/bundler/source/rubygems.rb +539 -0
- data/lib/bundler/source/rubygems/remote.rb +69 -0
- data/lib/bundler/source_list.rb +186 -0
- data/lib/bundler/spec_set.rb +208 -0
- data/lib/bundler/ssl_certs/.document +1 -0
- data/lib/bundler/ssl_certs/certificate_manager.rb +66 -0
- data/lib/bundler/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +21 -0
- data/lib/bundler/ssl_certs/rubygems.global.ssl.fastly.net/DigiCertHighAssuranceEVRootCA.pem +23 -0
- data/lib/bundler/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem +25 -0
- data/lib/bundler/stub_specification.rb +108 -0
- data/lib/bundler/templates/.document +1 -0
- data/lib/bundler/templates/Executable +29 -0
- data/lib/bundler/templates/Executable.bundler +105 -0
- data/lib/bundler/templates/Executable.standalone +14 -0
- data/lib/bundler/templates/Gemfile +7 -0
- data/lib/bundler/templates/gems.rb +8 -0
- data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +74 -0
- data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
- data/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
- data/lib/bundler/templates/newgem/README.md.tt +47 -0
- data/lib/bundler/templates/newgem/Rakefile.tt +29 -0
- data/lib/bundler/templates/newgem/bin/console.tt +14 -0
- data/lib/bundler/templates/newgem/bin/setup.tt +8 -0
- data/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
- data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
- data/lib/bundler/templates/newgem/gitignore.tt +20 -0
- data/lib/bundler/templates/newgem/lib/newgem.rb.tt +13 -0
- data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
- data/lib/bundler/templates/newgem/newgem.gemspec.tt +50 -0
- data/lib/bundler/templates/newgem/rspec.tt +3 -0
- data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +9 -0
- data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +14 -0
- data/lib/bundler/templates/newgem/test/newgem_test.rb.tt +11 -0
- data/lib/bundler/templates/newgem/test/test_helper.rb.tt +8 -0
- data/lib/bundler/templates/newgem/travis.yml.tt +7 -0
- data/lib/bundler/ui.rb +9 -0
- data/lib/bundler/ui/rg_proxy.rb +19 -0
- data/lib/bundler/ui/shell.rb +146 -0
- data/lib/bundler/ui/silent.rb +69 -0
- data/lib/bundler/uri_credentials_filter.rb +37 -0
- data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1741 -0
- data/lib/bundler/vendor/fileutils/lib/fileutils/version.rb +5 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo.rb +12 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/compatibility.rb +26 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +81 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +223 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +36 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +66 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +62 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +63 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +61 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +126 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +46 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +36 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +136 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +143 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +6 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +101 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +67 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +837 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +46 -0
- data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +58 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/faster.rb +27 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1233 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse.rb +129 -0
- data/lib/bundler/vendor/thor/lib/thor.rb +509 -0
- data/lib/bundler/vendor/thor/lib/thor/actions.rb +331 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +104 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +60 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +118 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +143 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +373 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/bundler/vendor/thor/lib/thor/base.rb +678 -0
- data/lib/bundler/vendor/thor/lib/thor/command.rb +135 -0
- data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
- data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
- data/lib/bundler/vendor/thor/lib/thor/error.rb +114 -0
- data/lib/bundler/vendor/thor/lib/thor/group.rb +281 -0
- data/lib/bundler/vendor/thor/lib/thor/invocation.rb +177 -0
- data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
- data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +37 -0
- data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
- data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +70 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +175 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +146 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +226 -0
- data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +71 -0
- data/lib/bundler/vendor/thor/lib/thor/runner.rb +324 -0
- data/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +482 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +149 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +126 -0
- data/lib/bundler/vendor/thor/lib/thor/util.rb +268 -0
- data/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/bundler/vendored_fileutils.rb +9 -0
- data/lib/bundler/vendored_molinillo.rb +4 -0
- data/lib/bundler/vendored_persistent.rb +52 -0
- data/lib/bundler/vendored_thor.rb +8 -0
- data/lib/bundler/version.rb +28 -0
- data/lib/bundler/version_ranges.rb +76 -0
- data/lib/bundler/vlad.rb +17 -0
- data/lib/bundler/worker.rb +106 -0
- data/lib/bundler/yaml_serializer.rb +90 -0
- data/man/bundle-add.1 +58 -0
- data/man/bundle-add.1.txt +52 -0
- data/man/bundle-add.ronn +40 -0
- data/man/bundle-binstubs.1 +40 -0
- data/man/bundle-binstubs.1.txt +48 -0
- data/man/bundle-binstubs.ronn +43 -0
- data/man/bundle-check.1 +31 -0
- data/man/bundle-check.1.txt +33 -0
- data/man/bundle-check.ronn +26 -0
- data/man/bundle-clean.1 +24 -0
- data/man/bundle-clean.1.txt +26 -0
- data/man/bundle-clean.ronn +18 -0
- data/man/bundle-config.1 +497 -0
- data/man/bundle-config.1.txt +529 -0
- data/man/bundle-config.ronn +397 -0
- data/man/bundle-doctor.1 +44 -0
- data/man/bundle-doctor.1.txt +44 -0
- data/man/bundle-doctor.ronn +33 -0
- data/man/bundle-exec.1 +165 -0
- data/man/bundle-exec.1.txt +178 -0
- data/man/bundle-exec.ronn +152 -0
- data/man/bundle-gem.1 +80 -0
- data/man/bundle-gem.1.txt +91 -0
- data/man/bundle-gem.ronn +78 -0
- data/man/bundle-info.1 +20 -0
- data/man/bundle-info.1.txt +21 -0
- data/man/bundle-info.ronn +17 -0
- data/man/bundle-init.1 +25 -0
- data/man/bundle-init.1.txt +34 -0
- data/man/bundle-init.ronn +29 -0
- data/man/bundle-inject.1 +33 -0
- data/man/bundle-inject.1.txt +32 -0
- data/man/bundle-inject.ronn +22 -0
- data/man/bundle-install.1 +308 -0
- data/man/bundle-install.1.txt +396 -0
- data/man/bundle-install.ronn +378 -0
- data/man/bundle-list.1 +50 -0
- data/man/bundle-list.1.txt +43 -0
- data/man/bundle-list.ronn +33 -0
- data/man/bundle-lock.1 +84 -0
- data/man/bundle-lock.1.txt +93 -0
- data/man/bundle-lock.ronn +94 -0
- data/man/bundle-open.1 +32 -0
- data/man/bundle-open.1.txt +29 -0
- data/man/bundle-open.ronn +19 -0
- data/man/bundle-outdated.1 +155 -0
- data/man/bundle-outdated.1.txt +131 -0
- data/man/bundle-outdated.ronn +111 -0
- data/man/bundle-package.1 +55 -0
- data/man/bundle-package.1.txt +79 -0
- data/man/bundle-package.ronn +72 -0
- data/man/bundle-platform.1 +61 -0
- data/man/bundle-platform.1.txt +57 -0
- data/man/bundle-platform.ronn +42 -0
- data/man/bundle-pristine.1 +34 -0
- data/man/bundle-pristine.1.txt +44 -0
- data/man/bundle-pristine.ronn +34 -0
- data/man/bundle-remove.1 +31 -0
- data/man/bundle-remove.1.txt +34 -0
- data/man/bundle-remove.ronn +23 -0
- data/man/bundle-show.1 +23 -0
- data/man/bundle-show.1.txt +27 -0
- data/man/bundle-show.ronn +21 -0
- data/man/bundle-update.1 +394 -0
- data/man/bundle-update.1.txt +391 -0
- data/man/bundle-update.ronn +350 -0
- data/man/bundle-viz.1 +39 -0
- data/man/bundle-viz.1.txt +39 -0
- data/man/bundle-viz.ronn +30 -0
- data/man/bundle.1 +136 -0
- data/man/bundle.1.txt +116 -0
- data/man/bundle.ronn +111 -0
- data/man/gemfile.5 +689 -0
- data/man/gemfile.5.ronn +521 -0
- data/man/gemfile.5.txt +653 -0
- data/man/index.txt +25 -0
- metadata +463 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
module Bundler
|
6
|
+
class CLI::Doctor
|
7
|
+
DARWIN_REGEX = /\s+(.+) \(compatibility /
|
8
|
+
LDD_REGEX = /\t\S+ => (\S+) \(\S+\)/
|
9
|
+
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def otool_available?
|
17
|
+
Bundler.which("otool")
|
18
|
+
end
|
19
|
+
|
20
|
+
def ldd_available?
|
21
|
+
Bundler.which("ldd")
|
22
|
+
end
|
23
|
+
|
24
|
+
def dylibs_darwin(path)
|
25
|
+
output = `/usr/bin/otool -L "#{path}"`.chomp
|
26
|
+
dylibs = output.split("\n")[1..-1].map {|l| l.match(DARWIN_REGEX).captures[0] }.uniq
|
27
|
+
# ignore @rpath and friends
|
28
|
+
dylibs.reject {|dylib| dylib.start_with? "@" }
|
29
|
+
end
|
30
|
+
|
31
|
+
def dylibs_ldd(path)
|
32
|
+
output = `/usr/bin/ldd "#{path}"`.chomp
|
33
|
+
output.split("\n").map do |l|
|
34
|
+
match = l.match(LDD_REGEX)
|
35
|
+
next if match.nil?
|
36
|
+
match.captures[0]
|
37
|
+
end.compact
|
38
|
+
end
|
39
|
+
|
40
|
+
def dylibs(path)
|
41
|
+
case RbConfig::CONFIG["host_os"]
|
42
|
+
when /darwin/
|
43
|
+
return [] unless otool_available?
|
44
|
+
dylibs_darwin(path)
|
45
|
+
when /(linux|solaris|bsd)/
|
46
|
+
return [] unless ldd_available?
|
47
|
+
dylibs_ldd(path)
|
48
|
+
else # Windows, etc.
|
49
|
+
Bundler.ui.warn("Dynamic library check not supported on this platform.")
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def bundles_for_gem(spec)
|
55
|
+
Dir.glob("#{spec.full_gem_path}/**/*.bundle")
|
56
|
+
end
|
57
|
+
|
58
|
+
def check!
|
59
|
+
require "bundler/cli/check"
|
60
|
+
Bundler::CLI::Check.new({}).run
|
61
|
+
end
|
62
|
+
|
63
|
+
def run
|
64
|
+
Bundler.ui.level = "error" if options[:quiet]
|
65
|
+
Bundler.settings.validate!
|
66
|
+
check!
|
67
|
+
|
68
|
+
definition = Bundler.definition
|
69
|
+
broken_links = {}
|
70
|
+
|
71
|
+
definition.specs.each do |spec|
|
72
|
+
bundles_for_gem(spec).each do |bundle|
|
73
|
+
bad_paths = dylibs(bundle).select {|f| !File.exist?(f) }
|
74
|
+
if bad_paths.any?
|
75
|
+
broken_links[spec] ||= []
|
76
|
+
broken_links[spec].concat(bad_paths)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
permissions_valid = check_home_permissions
|
82
|
+
|
83
|
+
if broken_links.any?
|
84
|
+
message = "The following gems are missing OS dependencies:"
|
85
|
+
broken_links.map do |spec, paths|
|
86
|
+
paths.uniq.map do |path|
|
87
|
+
"\n * #{spec.name}: #{path}"
|
88
|
+
end
|
89
|
+
end.flatten.sort.each {|m| message += m }
|
90
|
+
raise ProductionError, message
|
91
|
+
elsif !permissions_valid
|
92
|
+
Bundler.ui.info "No issues found with the installed bundle"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def check_home_permissions
|
99
|
+
require "find"
|
100
|
+
files_not_readable_or_writable = []
|
101
|
+
files_not_rw_and_owned_by_different_user = []
|
102
|
+
files_not_owned_by_current_user_but_still_rw = []
|
103
|
+
Find.find(Bundler.home.to_s).each do |f|
|
104
|
+
if !File.writable?(f) || !File.readable?(f)
|
105
|
+
if File.stat(f).uid != Process.uid
|
106
|
+
files_not_rw_and_owned_by_different_user << f
|
107
|
+
else
|
108
|
+
files_not_readable_or_writable << f
|
109
|
+
end
|
110
|
+
elsif File.stat(f).uid != Process.uid
|
111
|
+
files_not_owned_by_current_user_but_still_rw << f
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
ok = true
|
116
|
+
if files_not_owned_by_current_user_but_still_rw.any?
|
117
|
+
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
|
118
|
+
"user, but are still readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
|
119
|
+
|
120
|
+
ok = false
|
121
|
+
end
|
122
|
+
|
123
|
+
if files_not_rw_and_owned_by_different_user.any?
|
124
|
+
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
|
125
|
+
"user, and are not readable/writable. These files are:\n - #{files_not_rw_and_owned_by_different_user.join("\n - ")}"
|
126
|
+
|
127
|
+
ok = false
|
128
|
+
end
|
129
|
+
|
130
|
+
if files_not_readable_or_writable.any?
|
131
|
+
Bundler.ui.warn "Files exist in the Bundler home that are not " \
|
132
|
+
"readable/writable by the current user. These files are:\n - #{files_not_readable_or_writable.join("\n - ")}"
|
133
|
+
|
134
|
+
ok = false
|
135
|
+
end
|
136
|
+
|
137
|
+
ok
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/current_ruby"
|
4
|
+
|
5
|
+
module Bundler
|
6
|
+
class CLI::Exec
|
7
|
+
attr_reader :options, :args, :cmd
|
8
|
+
|
9
|
+
TRAPPED_SIGNALS = %w[INT].freeze
|
10
|
+
|
11
|
+
def initialize(options, args)
|
12
|
+
@options = options
|
13
|
+
@cmd = args.shift
|
14
|
+
@args = args
|
15
|
+
|
16
|
+
if Bundler.current_ruby.ruby_2? && !Bundler.current_ruby.jruby?
|
17
|
+
@args << { :close_others => !options.keep_file_descriptors? }
|
18
|
+
elsif options.keep_file_descriptors?
|
19
|
+
Bundler.ui.warn "Ruby version #{RUBY_VERSION} defaults to keeping non-standard file descriptors on Kernel#exec."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
validate_cmd!
|
25
|
+
SharedHelpers.set_bundle_environment
|
26
|
+
if bin_path = Bundler.which(cmd)
|
27
|
+
if !Bundler.settings[:disable_exec_load] && ruby_shebang?(bin_path)
|
28
|
+
return kernel_load(bin_path, *args)
|
29
|
+
end
|
30
|
+
# First, try to exec directly to something in PATH
|
31
|
+
if Bundler.current_ruby.jruby_18?
|
32
|
+
kernel_exec(bin_path, *args)
|
33
|
+
else
|
34
|
+
kernel_exec([bin_path, cmd], *args)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
# exec using the given command
|
38
|
+
kernel_exec(cmd, *args)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def validate_cmd!
|
45
|
+
return unless cmd.nil?
|
46
|
+
Bundler.ui.error "bundler: exec needs a command to run"
|
47
|
+
exit 128
|
48
|
+
end
|
49
|
+
|
50
|
+
def kernel_exec(*args)
|
51
|
+
ui = Bundler.ui
|
52
|
+
Bundler.ui = nil
|
53
|
+
Kernel.exec(*args)
|
54
|
+
rescue Errno::EACCES, Errno::ENOEXEC
|
55
|
+
Bundler.ui = ui
|
56
|
+
Bundler.ui.error "bundler: not executable: #{cmd}"
|
57
|
+
exit 126
|
58
|
+
rescue Errno::ENOENT
|
59
|
+
Bundler.ui = ui
|
60
|
+
Bundler.ui.error "bundler: command not found: #{cmd}"
|
61
|
+
Bundler.ui.warn "Install missing gem executables with `bundle install`"
|
62
|
+
exit 127
|
63
|
+
end
|
64
|
+
|
65
|
+
def kernel_load(file, *args)
|
66
|
+
args.pop if args.last.is_a?(Hash)
|
67
|
+
ARGV.replace(args)
|
68
|
+
$0 = file
|
69
|
+
Process.setproctitle(process_title(file, args)) if Process.respond_to?(:setproctitle)
|
70
|
+
ui = Bundler.ui
|
71
|
+
Bundler.ui = nil
|
72
|
+
require "bundler/setup"
|
73
|
+
TRAPPED_SIGNALS.each {|s| trap(s, "DEFAULT") }
|
74
|
+
Kernel.load(file)
|
75
|
+
rescue SystemExit, SignalException
|
76
|
+
raise
|
77
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
78
|
+
Bundler.ui = ui
|
79
|
+
Bundler.ui.error "bundler: failed to load command: #{cmd} (#{file})"
|
80
|
+
backtrace = e.backtrace ? e.backtrace.take_while {|bt| !bt.start_with?(__FILE__) } : []
|
81
|
+
abort "#{e.class}: #{e.message}\n #{backtrace.join("\n ")}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def process_title(file, args)
|
85
|
+
"#{file} #{args.join(" ")}".strip
|
86
|
+
end
|
87
|
+
|
88
|
+
def ruby_shebang?(file)
|
89
|
+
possibilities = [
|
90
|
+
"#!/usr/bin/env ruby\n",
|
91
|
+
"#!/usr/bin/env jruby\n",
|
92
|
+
"#!/usr/bin/env truffleruby\n",
|
93
|
+
"#!#{Gem.ruby}\n",
|
94
|
+
]
|
95
|
+
|
96
|
+
if File.zero?(file)
|
97
|
+
Bundler.ui.warn "#{file} is empty"
|
98
|
+
return false
|
99
|
+
end
|
100
|
+
|
101
|
+
first_line = File.open(file, "rb") {|f| f.read(possibilities.map(&:size).max) }
|
102
|
+
possibilities.any? {|shebang| first_line.start_with?(shebang) }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module Bundler
|
6
|
+
class CLI
|
7
|
+
Bundler.require_thor_actions
|
8
|
+
include Thor::Actions
|
9
|
+
end
|
10
|
+
|
11
|
+
class CLI::Gem
|
12
|
+
TEST_FRAMEWORK_VERSIONS = {
|
13
|
+
"rspec" => "3.0",
|
14
|
+
"minitest" => "5.0"
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
attr_reader :options, :gem_name, :thor, :name, :target
|
18
|
+
|
19
|
+
def initialize(options, gem_name, thor)
|
20
|
+
@options = options
|
21
|
+
@gem_name = resolve_name(gem_name)
|
22
|
+
|
23
|
+
@thor = thor
|
24
|
+
thor.behavior = :invoke
|
25
|
+
thor.destination_root = nil
|
26
|
+
|
27
|
+
@name = @gem_name
|
28
|
+
@target = SharedHelpers.pwd.join(gem_name)
|
29
|
+
|
30
|
+
validate_ext_name if options[:ext]
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
Bundler.ui.confirm "Creating gem '#{name}'..."
|
35
|
+
|
36
|
+
underscored_name = name.tr("-", "_")
|
37
|
+
namespaced_path = name.tr("-", "/")
|
38
|
+
constant_name = name.gsub(/-[_-]*(?![_-]|$)/) { "::" }.gsub(/([_-]+|(::)|^)(.|$)/) { $2.to_s + $3.upcase }
|
39
|
+
constant_array = constant_name.split("::")
|
40
|
+
|
41
|
+
git_installed = Bundler.git_present?
|
42
|
+
|
43
|
+
git_author_name = git_installed ? `git config user.name`.chomp : ""
|
44
|
+
github_username = git_installed ? `git config github.user`.chomp : ""
|
45
|
+
git_user_email = git_installed ? `git config user.email`.chomp : ""
|
46
|
+
|
47
|
+
config = {
|
48
|
+
:name => name,
|
49
|
+
:underscored_name => underscored_name,
|
50
|
+
:namespaced_path => namespaced_path,
|
51
|
+
:makefile_path => "#{underscored_name}/#{underscored_name}",
|
52
|
+
:constant_name => constant_name,
|
53
|
+
:constant_array => constant_array,
|
54
|
+
:author => git_author_name.empty? ? "TODO: Write your name" : git_author_name,
|
55
|
+
:email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
|
56
|
+
:test => options[:test],
|
57
|
+
:ext => options[:ext],
|
58
|
+
:exe => options[:exe],
|
59
|
+
:bundler_version => bundler_dependency_version,
|
60
|
+
:github_username => github_username.empty? ? "[USERNAME]" : github_username
|
61
|
+
}
|
62
|
+
ensure_safe_gem_name(name, constant_array)
|
63
|
+
|
64
|
+
templates = {
|
65
|
+
"Gemfile.tt" => "Gemfile",
|
66
|
+
"lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb",
|
67
|
+
"lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb",
|
68
|
+
"newgem.gemspec.tt" => "#{name}.gemspec",
|
69
|
+
"Rakefile.tt" => "Rakefile",
|
70
|
+
"README.md.tt" => "README.md",
|
71
|
+
"bin/console.tt" => "bin/console",
|
72
|
+
"bin/setup.tt" => "bin/setup"
|
73
|
+
}
|
74
|
+
|
75
|
+
executables = %w[
|
76
|
+
bin/console
|
77
|
+
bin/setup
|
78
|
+
]
|
79
|
+
|
80
|
+
templates.merge!("gitignore.tt" => ".gitignore") if Bundler.git_present?
|
81
|
+
|
82
|
+
if test_framework = ask_and_set_test_framework
|
83
|
+
config[:test] = test_framework
|
84
|
+
config[:test_framework_version] = TEST_FRAMEWORK_VERSIONS[test_framework]
|
85
|
+
|
86
|
+
templates.merge!("travis.yml.tt" => ".travis.yml")
|
87
|
+
|
88
|
+
case test_framework
|
89
|
+
when "rspec"
|
90
|
+
templates.merge!(
|
91
|
+
"rspec.tt" => ".rspec",
|
92
|
+
"spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
|
93
|
+
"spec/newgem_spec.rb.tt" => "spec/#{namespaced_path}_spec.rb"
|
94
|
+
)
|
95
|
+
when "minitest"
|
96
|
+
templates.merge!(
|
97
|
+
"test/test_helper.rb.tt" => "test/test_helper.rb",
|
98
|
+
"test/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb"
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
config[:test_task] = config[:test] == "minitest" ? "test" : "spec"
|
104
|
+
|
105
|
+
if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
|
106
|
+
"This means that any other developer or company will be legally allowed to use your code " \
|
107
|
+
"for free as long as they admit you created it. You can read more about the MIT license " \
|
108
|
+
"at https://choosealicense.com/licenses/mit.")
|
109
|
+
config[:mit] = true
|
110
|
+
Bundler.ui.info "MIT License enabled in config"
|
111
|
+
templates.merge!("LICENSE.txt.tt" => "LICENSE.txt")
|
112
|
+
end
|
113
|
+
|
114
|
+
if ask_and_set(:coc, "Do you want to include a code of conduct in gems you generate?",
|
115
|
+
"Codes of conduct can increase contributions to your project by contributors who " \
|
116
|
+
"prefer collaborative, safe spaces. You can read more about the code of conduct at " \
|
117
|
+
"contributor-covenant.org. Having a code of conduct means agreeing to the responsibility " \
|
118
|
+
"of enforcing it, so be sure that you are prepared to do that. Be sure that your email " \
|
119
|
+
"address is specified as a contact in the generated code of conduct so that people know " \
|
120
|
+
"who to contact in case of a violation. For suggestions about " \
|
121
|
+
"how to enforce codes of conduct, see https://bit.ly/coc-enforcement.")
|
122
|
+
config[:coc] = true
|
123
|
+
Bundler.ui.info "Code of conduct enabled in config"
|
124
|
+
templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md")
|
125
|
+
end
|
126
|
+
|
127
|
+
templates.merge!("exe/newgem.tt" => "exe/#{name}") if config[:exe]
|
128
|
+
|
129
|
+
if options[:ext]
|
130
|
+
templates.merge!(
|
131
|
+
"ext/newgem/extconf.rb.tt" => "ext/#{name}/extconf.rb",
|
132
|
+
"ext/newgem/newgem.h.tt" => "ext/#{name}/#{underscored_name}.h",
|
133
|
+
"ext/newgem/newgem.c.tt" => "ext/#{name}/#{underscored_name}.c"
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
templates.each do |src, dst|
|
138
|
+
destination = target.join(dst)
|
139
|
+
SharedHelpers.filesystem_access(destination) do
|
140
|
+
thor.template("newgem/#{src}", destination, config)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
executables.each do |file|
|
145
|
+
SharedHelpers.filesystem_access(target.join(file)) do |path|
|
146
|
+
executable = (path.stat.mode | 0o111)
|
147
|
+
path.chmod(executable)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
if Bundler.git_present?
|
152
|
+
Bundler.ui.info "Initializing git repo in #{target}"
|
153
|
+
Dir.chdir(target) do
|
154
|
+
`git init`
|
155
|
+
`git add .`
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Open gemspec in editor
|
160
|
+
open_editor(options["edit"], target.join("#{name}.gemspec")) if options[:edit]
|
161
|
+
|
162
|
+
Bundler.ui.info "Gem '#{name}' was successfully created. " \
|
163
|
+
"For more information on making a RubyGem visit https://bundler.io/guides/creating_gem.html"
|
164
|
+
rescue Errno::EEXIST => e
|
165
|
+
raise GenericSystemCallError.new(e, "There was a conflict while creating the new gem.")
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def resolve_name(name)
|
171
|
+
SharedHelpers.pwd.join(name).basename.to_s
|
172
|
+
end
|
173
|
+
|
174
|
+
def ask_and_set(key, header, message)
|
175
|
+
choice = options[key]
|
176
|
+
choice = Bundler.settings["gem.#{key}"] if choice.nil?
|
177
|
+
|
178
|
+
if choice.nil?
|
179
|
+
Bundler.ui.confirm header
|
180
|
+
choice = Bundler.ui.yes? "#{message} y/(n):"
|
181
|
+
Bundler.settings.set_global("gem.#{key}", choice)
|
182
|
+
end
|
183
|
+
|
184
|
+
choice
|
185
|
+
end
|
186
|
+
|
187
|
+
def validate_ext_name
|
188
|
+
return unless gem_name.index("-")
|
189
|
+
|
190
|
+
Bundler.ui.error "You have specified a gem name which does not conform to the \n" \
|
191
|
+
"naming guidelines for C extensions. For more information, \n" \
|
192
|
+
"see the 'Extension Naming' section at the following URL:\n" \
|
193
|
+
"http://guides.rubygems.org/gems-with-extensions/\n"
|
194
|
+
exit 1
|
195
|
+
end
|
196
|
+
|
197
|
+
def ask_and_set_test_framework
|
198
|
+
test_framework = options[:test] || Bundler.settings["gem.test"]
|
199
|
+
|
200
|
+
if test_framework.nil?
|
201
|
+
Bundler.ui.confirm "Do you want to generate tests with your gem?"
|
202
|
+
result = Bundler.ui.ask "Type 'rspec' or 'minitest' to generate those test files now and " \
|
203
|
+
"in the future. rspec/minitest/(none):"
|
204
|
+
if result =~ /rspec|minitest/
|
205
|
+
test_framework = result
|
206
|
+
else
|
207
|
+
test_framework = false
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
if Bundler.settings["gem.test"].nil?
|
212
|
+
Bundler.settings.set_global("gem.test", test_framework)
|
213
|
+
end
|
214
|
+
|
215
|
+
test_framework
|
216
|
+
end
|
217
|
+
|
218
|
+
def bundler_dependency_version
|
219
|
+
v = Gem::Version.new(Bundler::VERSION)
|
220
|
+
req = v.segments[0..1]
|
221
|
+
req << "a" if v.prerelease?
|
222
|
+
req.join(".")
|
223
|
+
end
|
224
|
+
|
225
|
+
def ensure_safe_gem_name(name, constant_array)
|
226
|
+
if name =~ /^\d/
|
227
|
+
Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
|
228
|
+
exit 1
|
229
|
+
end
|
230
|
+
|
231
|
+
constant_name = constant_array.join("::")
|
232
|
+
|
233
|
+
existing_constant = constant_array.inject(Object) do |c, s|
|
234
|
+
defined = begin
|
235
|
+
c.const_defined?(s)
|
236
|
+
rescue NameError
|
237
|
+
Bundler.ui.error "Invalid gem name #{name} -- `#{constant_name}` is an invalid constant name"
|
238
|
+
exit 1
|
239
|
+
end
|
240
|
+
(defined && c.const_get(s)) || break
|
241
|
+
end
|
242
|
+
|
243
|
+
return unless existing_constant
|
244
|
+
Bundler.ui.error "Invalid gem name #{name} constant #{constant_name} is already in use. Please choose another gem name."
|
245
|
+
exit 1
|
246
|
+
end
|
247
|
+
|
248
|
+
def open_editor(editor, file)
|
249
|
+
thor.run(%(#{editor} "#{file}"))
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|