Skip to content

Commit

Permalink
Add Next Gemfile Support
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
JuanVqz committed Mar 21, 2024
1 parent 7866d1e commit abbb90d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
5 changes: 4 additions & 1 deletion bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ APP_DIR=$(pwd)
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)

# legacy buildpack uses $STACK
# legacy buildpack uses $STACK
export STACK=$CNB_STACK_ID

echo "-----> build JUAN"
printenv

source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"

Expand Down
1 change: 1 addition & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CACHE_DIR=$2
ENV_DIR=$3
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)
echo "-----> compile JUAN"

source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"
Expand Down
1 change: 1 addition & 0 deletions bin/support/ruby_compile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require "language_pack/shell_helpers"

begin
LanguagePack::ShellHelpers.initialize_env(ARGV[2])
puts "RUBY_COMPILE: #{ARGV.inspect}"
if pack = LanguagePack.detect(ARGV[0], ARGV[1])
pack.topic("Compiling #{pack.name}")
pack.log("compile") do
Expand Down
8 changes: 6 additions & 2 deletions lib/language_pack/helpers/bundler_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def initialize(version_hash, major_minor)
def initialize(options = {})
@bundler_tmp = Pathname.new(Dir.mktmpdir)
@fetcher = options[:fetcher] || LanguagePack::Fetcher.new(LanguagePack::Base::VENDOR_URL) # coupling
@gemfile_path = options[:gemfile_path] || Pathname.new("./Gemfile")
@gemfile_path = options[:gemfile_path] || Pathname.new(ENV["BUNDLE_GEMFILE"] || "./Gemfile")
@gemfile_lock_path = Pathname.new("#{@gemfile_path}.lock")

@version = self.class.detect_bundler_version(contents: @gemfile_lock_path.read(mode: "rt"))
Expand All @@ -114,7 +114,9 @@ def initialize(options = {})
end

def install
warn("install start #{ENV['BUNDLE_GEMFILE']} #{env('BUNDLE_GEMFILE')}")
ENV['BUNDLE_GEMFILE'] = @gemfile_path.to_s
warn("install end #{ENV['BUNDLE_GEMFILE']} #{env('BUNDLE_GEMFILE')}")

fetch_bundler
$LOAD_PATH << @path
Expand All @@ -123,7 +125,9 @@ def install
end

def clean
warn("clean start #{ENV['BUNDLE_GEMFILE']} #{env('BUNDLE_GEMFILE')}")
ENV['BUNDLE_GEMFILE'] = @orig_bundle_gemfile
warn("clean end #{ENV['BUNDLE_GEMFILE']} #{env('BUNDLE_GEMFILE')}")
@bundler_tmp.rmtree if @bundler_tmp.directory?
end

Expand Down Expand Up @@ -223,7 +227,7 @@ def needs_ruby_global_append_path?
end

def bundler_version_escape_valve!
topic("Removing BUNDLED WITH version in the Gemfile.lock")
topic("Removing BUNDLED WITH version in the #{@gemfile_lock_path}")
contents = File.read(@gemfile_lock_path, mode: "rt")
File.open(@gemfile_lock_path, "w") do |f|
f.write contents.sub(/^BUNDLED WITH$(\r?\n) (?<major>\d+)\.\d+\.\d+/m, '')
Expand Down
19 changes: 16 additions & 3 deletions lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,26 @@ def self.use?
end

def self.bundler
warn("setting bundler #{env('BUNDLER_ORIG_BUNDLE_GEMFILE')} #{env('BUNDLE_GEMFILE')}", inline: true)
@@bundler ||= LanguagePack::Helpers::BundlerWrapper.new.install
end

def bundler
self.class.bundler
end

def current_gemfile
ENV["BUNDLE_GEMFILE"] || "Gemfile"
end

def gemfile_path
Pathname.new(current_gemfile)
end

def gemfile_lock_path
Pathname.new("#{current_gemfile}.lock")
end

def initialize(*args)
super(*args)
@fetchers[:mri] = LanguagePack::Fetcher.new(VENDOR_URL, @stack)
Expand Down Expand Up @@ -144,7 +157,7 @@ def build
build_bundler
# TODO post_bundler might need to be done in a new layer
bundler.clean
gem_layer.metadata[:gems] = Digest::SHA2.hexdigest(File.read("Gemfile.lock"))
gem_layer.metadata[:gems] = Digest::SHA2.hexdigest(File.read(gemfile_lock_path))
gem_layer.metadata[:stack] = @stack
gem_layer.metadata[:ruby_version] = run_stdout(%q(ruby -v)).strip
gem_layer.metadata[:rubygems_version] = run_stdout(%q(gem -v)).strip
Expand Down Expand Up @@ -779,7 +792,7 @@ def build_bundler
if bundler.windows_gemfile_lock?
log("bundle", "has_windows_gemfile_lock")

File.unlink("Gemfile.lock")
File.unlink(gemfile_lock_path)
ENV.delete("BUNDLE_DEPLOYMENT")

warn(<<~WARNING, inline: true)
Expand Down Expand Up @@ -816,7 +829,7 @@ def build_bundler

# we need to set BUNDLE_CONFIG and BUNDLE_GEMFILE for
# codon since it uses bundler.
env_vars["BUNDLE_GEMFILE"] = "#{pwd}/Gemfile"
env_vars["BUNDLE_GEMFILE"] = "#{pwd}/#{gemfile_path}"
env_vars["BUNDLE_CONFIG"] = "#{pwd}/.bundle/config"
env_vars["CPATH"] = noshellescape("#{yaml_include}:$CPATH")
env_vars["CPPATH"] = noshellescape("#{yaml_include}:$CPPATH")
Expand Down
1 change: 1 addition & 0 deletions lib/language_pack/shell_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def self.blacklist?(key)

def self.initialize_env(path)
env_dir = Pathname.new("#{path}")
puts "self.initialize_env: #{env_dir}"
if env_dir.exist? && env_dir.directory?
env_dir.each_child do |file|
key = file.basename.to_s
Expand Down

0 comments on commit abbb90d

Please sign in to comment.