summaryrefslogtreecommitdiff
path: root/lib/bundler/env.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-08 08:45:41 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-08 08:45:41 +0000
commit8598f8c2dc78c6d1ae87cb6ae19c34ba2cb29241 (patch)
tree0bbd28f684e745cb212761b7c74fe08668f85cc8 /lib/bundler/env.rb
parentf2e04b77aa8a363d7e36ce5a9cdb60714a537a3c (diff)
Merge bundler to standard libraries.
rubygems 2.7.x depends bundler-1.15.x. This is preparation for rubygems and bundler migration. * lib/bundler.rb, lib/bundler/*: files of bundler-1.15.4 * spec/bundler/*: rspec examples of bundler-1.15.4. I applied patches. * https://github.com/bundler/bundler/pull/6007 * Exclude not working examples on ruby repository. * Fake ruby interpriter instead of installed ruby. * Makefile.in: Added test task named `test-bundler`. This task is only working macOS/linux yet. I'm going to support Windows environment later. * tool/sync_default_gems.rb: Added sync task for bundler. [Feature #12733][ruby-core:77172] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/bundler/env.rb')
-rw-r--r--lib/bundler/env.rb94
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb
new file mode 100644
index 0000000000..8b990baf40
--- /dev/null
+++ b/lib/bundler/env.rb
@@ -0,0 +1,94 @@
+# frozen_string_literal: true
+require "bundler/rubygems_integration"
+require "bundler/source/git/git_proxy"
+
+module Bundler
+ class Env
+ def write(io)
+ io.write report
+ end
+
+ def report(options = {})
+ print_gemfile = options.delete(:print_gemfile) { true }
+ print_gemspecs = options.delete(:print_gemspecs) { true }
+
+ out = String.new("## Environment\n\n```\n")
+ out << "Bundler #{Bundler::VERSION}\n"
+ out << "Rubygems #{Gem::VERSION}\n"
+ out << "Ruby #{ruby_version}"
+ out << "GEM_HOME #{ENV["GEM_HOME"]}\n" unless ENV["GEM_HOME"].nil? || ENV["GEM_HOME"].empty?
+ out << "GEM_PATH #{ENV["GEM_PATH"]}\n" unless ENV["GEM_PATH"] == ENV["GEM_HOME"]
+ out << "RVM #{ENV["rvm_version"]}\n" if ENV["rvm_version"]
+ out << "Git #{git_version}\n"
+ out << "Platform #{Gem::Platform.local}\n"
+ out << "OpenSSL #{OpenSSL::OPENSSL_VERSION}\n" if defined?(OpenSSL::OPENSSL_VERSION)
+ %w(rubygems-bundler open_gem).each do |name|
+ specs = Bundler.rubygems.find_name(name)
+ out << "#{name} (#{specs.map(&:version).join(",")})\n" unless specs.empty?
+ end
+
+ out << "```\n"
+
+ unless Bundler.settings.all.empty?
+ out << "\n## Bundler settings\n\n```\n"
+ Bundler.settings.all.each do |setting|
+ out << setting << "\n"
+ Bundler.settings.pretty_values_for(setting).each do |line|
+ out << " " << line << "\n"
+ end
+ end
+ out << "```\n"
+ end
+
+ return out unless SharedHelpers.in_bundle?
+
+ if print_gemfile
+ out << "\n## Gemfile\n"
+ out << "\n### #{Bundler.default_gemfile.relative_path_from(SharedHelpers.pwd)}\n\n"
+ out << "```ruby\n" << read_file(Bundler.default_gemfile).chomp << "\n```\n"
+
+ out << "\n### #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}\n\n"
+ out << "```\n" << read_file(Bundler.default_lockfile).chomp << "\n```\n"
+ end
+
+ if print_gemspecs
+ dsl = Dsl.new.tap {|d| d.eval_gemfile(Bundler.default_gemfile) }
+ out << "\n## Gemspecs\n" unless dsl.gemspecs.empty?
+ dsl.gemspecs.each do |gs|
+ out << "\n### #{File.basename(gs.loaded_from)}"
+ out << "\n\n```ruby\n" << read_file(gs.loaded_from).chomp << "\n```\n"
+ end
+ end
+
+ out
+ end
+
+ private
+
+ def read_file(filename)
+ File.read(filename.to_s).strip
+ rescue Errno::ENOENT
+ "<No #{filename} found>"
+ rescue => e
+ "#{e.class}: #{e.message}"
+ end
+
+ def ruby_version
+ str = String.new("#{RUBY_VERSION}")
+ if RUBY_VERSION < "1.9"
+ str << " (#{RUBY_RELEASE_DATE}"
+ str << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
+ str << ") [#{RUBY_PLATFORM}]\n"
+ else
+ str << "p#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
+ str << " (#{RUBY_RELEASE_DATE} revision #{RUBY_REVISION}) [#{RUBY_PLATFORM}]\n"
+ end
+ end
+
+ def git_version
+ Bundler::Source::Git::GitProxy.new(nil, nil, nil).full_version
+ rescue Bundler::Source::Git::GitNotInstalledError
+ "not installed"
+ end
+ end
+end