Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
De-couple BundlerWrapper from LanguagePack::Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Feb 6, 2019
1 parent 42cecd3 commit 45981c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
36 changes: 20 additions & 16 deletions lib/language_pack/helpers/bundler_wrapper.rb
@@ -1,5 +1,9 @@
require 'language_pack/fetcher'

# This class is responsible for installing and maintaining a
# reference to bundler. It contains access to bundler internals
# that are used to introspect a project such as detecting presence
# of gems and their versions.
class LanguagePack::Helpers::BundlerWrapper
include LanguagePack::ShellHelpers

Expand All @@ -11,24 +15,20 @@ def initialize(error)
end
end

VENDOR_URL = LanguagePack::Base::VENDOR_URL # coupling
DEFAULT_FETCHER = LanguagePack::Fetcher.new(VENDOR_URL) # coupling
BUNDLER_DIR_NAME = LanguagePack::Ruby::BUNDLER_GEM_PATH # coupling
BUNDLER_PATH = File.expand_path("../../../../tmp/#{BUNDLER_DIR_NAME}", __FILE__)
GEMFILE_PATH = Pathname.new "./Gemfile"

attr_reader :bundler_path
attr_reader :bundler_path

def initialize(options = {})
@fetcher = options[:fetcher] || DEFAULT_FETCHER
@version = "1.15.2"
@bundler_tmp = Dir.mktmpdir
@bundler_path = options[:bundler_path] || File.join(@bundler_tmp, "#{BUNDLER_DIR_NAME}")
@gemfile_path = options[:gemfile_path] || GEMFILE_PATH
@bundler_tar = options[:bundler_tar] || "#{BUNDLER_DIR_NAME}.tgz"
@fetcher = options[:fetcher] || LanguagePack::Fetcher.new(LanguagePack::Base::VENDOR_URL) # coupling
@bundler_path = options[:bundler_path] || File.join(@bundler_tmp, "#{dir_name}")
@gemfile_path = options[:gemfile_path] || Pathname.new("./Gemfile")
@bundler_tar = options[:bundler_tar] || "#{dir_name}.tgz"

@gemfile_lock_path = "#{@gemfile_path}.lock"
@orig_bundle_gemfile = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = @gemfile_path.to_s
@path = Pathname.new "#{@bundler_path}/gems/#{BUNDLER_DIR_NAME}/lib"
@path = Pathname.new "#{@bundler_path}/gems/#{dir_name}/lib"
end

def install
Expand All @@ -42,7 +42,7 @@ def clean
ENV['BUNDLE_GEMFILE'] = @orig_bundle_gemfile
FileUtils.remove_entry_secure(@bundler_tmp) if Dir.exist?(@bundler_tmp)

if LanguagePack::Ruby::BUNDLER_VERSION == "1.7.12"
if version == "1.7.12"
# Hack to cleanup after pre 1.8 versions of bundler. See https://github.com/bundler/bundler/pull/3277/
Dir["#{Dir.tmpdir}/bundler*"].each do |dir|
FileUtils.remove_entry_secure(dir) if Dir.exist?(dir) && File.stat(dir).writable?
Expand Down Expand Up @@ -71,15 +71,19 @@ def windows_gemfile_lock?
end

def specs
@specs ||= lockfile_parser.specs.each_with_object({}) {|spec, hash| hash[spec.name] = spec }
@specs ||= lockfile_parser.specs.each_with_object({}) {|spec, hash| hash[spec.name] = spec }
end

def platforms
@platforms ||= lockfile_parser.platforms
end

def version
Bundler::VERSION
@version
end

def dir_name
"bundler-#{version}"
end

def instrument(*args, &block)
Expand All @@ -89,7 +93,7 @@ def instrument(*args, &block)
def ruby_version
instrument 'detect_ruby_version' do
env = { "PATH" => "#{bundler_path}/bin:#{ENV['PATH']}",
"RUBYLIB" => File.join(bundler_path, "gems", BUNDLER_DIR_NAME, "lib"),
"RUBYLIB" => File.join(bundler_path, "gems", dir_name, "lib"),
"GEM_PATH" => "#{bundler_path}:#{ENV["GEM_PATH"]}",
"BUNDLE_DISABLE_VERSION_CHECK" => "true"
}
Expand Down
14 changes: 6 additions & 8 deletions lib/language_pack/ruby.rb
Expand Up @@ -16,8 +16,6 @@ class LanguagePack::Ruby < LanguagePack::Base
NAME = "ruby"
LIBYAML_VERSION = "0.1.7"
LIBYAML_PATH = "libyaml-#{LIBYAML_VERSION}"
BUNDLER_VERSION = "1.15.2"
BUNDLER_GEM_PATH = "bundler-#{BUNDLER_VERSION}"
RBX_BASE_URL = "http://binaries.rubini.us/heroku"
NODE_BP_PATH = "vendor/node/bin"

Expand Down Expand Up @@ -126,9 +124,9 @@ def config_detect
def warn_bundler_upgrade
old_bundler_version = @metadata.read("bundler_version").chomp if @metadata.exists?("bundler_version")

if old_bundler_version && old_bundler_version != BUNDLER_VERSION
if old_bundler_version && old_bundler_version != bundler.version
puts(<<-WARNING)
Your app was upgraded to bundler #{ BUNDLER_VERSION }.
Your app was upgraded to bundler #{ bundler.version }.
Previously you had a successful deploy with bundler #{ old_bundler_version }.
If you see problems related to the bundler version please refer to:
Expand Down Expand Up @@ -596,7 +594,7 @@ def bundler_binstubs_path
end

def bundler_path
@bundler_path ||= "#{slug_vendor_base}/gems/#{BUNDLER_GEM_PATH}"
@bundler_path ||= "#{slug_vendor_base}/gems/#{bundler.dir_name}"
end

def write_bundler_shim(path)
Expand All @@ -607,7 +605,7 @@ def write_bundler_shim(path)
#!/usr/bin/env ruby
require 'rubygems'
version = "#{BUNDLER_VERSION}"
version = "#{bundler.version}"
if ARGV.first
str = ARGV.first
Expand Down Expand Up @@ -678,7 +676,7 @@ def build_bundler(default_bundle_without)
yaml_include = File.expand_path("#{libyaml_dir}/include").shellescape
yaml_lib = File.expand_path("#{libyaml_dir}/lib").shellescape
pwd = Dir.pwd
bundler_path = "#{pwd}/#{slug_vendor_base}/gems/#{BUNDLER_GEM_PATH}/lib"
bundler_path = "#{pwd}/#{slug_vendor_base}/gems/#{bundler.dir_name}/lib"
# we need to set BUNDLE_CONFIG and BUNDLE_GEMFILE for
# codon since it uses bundler.
env_vars = {
Expand Down Expand Up @@ -1081,7 +1079,7 @@ def load_bundler_cache
FileUtils.mkdir_p(heroku_metadata)
@metadata.write(ruby_version_cache, full_ruby_version, false)
@metadata.write(buildpack_version_cache, BUILDPACK_VERSION, false)
@metadata.write(bundler_version_cache, BUNDLER_VERSION, false)
@metadata.write(bundler_version_cache, bundler.version, false)
@metadata.write(rubygems_version_cache, rubygems_version, false)
@metadata.write(stack_cache, @stack, false)
@metadata.save
Expand Down
5 changes: 2 additions & 3 deletions spec/helpers/fetcher_spec.rb
@@ -1,15 +1,14 @@
require 'spec_helper'

describe "Fetches" do

it "bundler" do
Dir.mktmpdir do |dir|
Dir.chdir(dir) do

fetcher = LanguagePack::Fetcher.new(LanguagePack::Base::VENDOR_URL)
fetcher.fetch_untar("#{LanguagePack::Ruby::BUNDLER_GEM_PATH}.tgz")
fetcher.fetch_untar("#{LanguagePack::Helpers::BundlerWrapper.new.dir_name}.tgz")
expect(`ls bin`).to match("bundle")
end
end
end
end

0 comments on commit 45981c0

Please sign in to comment.