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 4df8106
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/language_pack/helpers/bundler_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,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
29 changes: 25 additions & 4 deletions lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ def self.use?
end

def self.bundler
@@bundler ||= LanguagePack::Helpers::BundlerWrapper.new.install
@@bundler ||= LanguagePack::Helpers::BundlerWrapper.new(gemfile_path: "./Gemfile.next").install
end

def bundler
self.class.bundler
end

def current_gemfile
"./Gemfile.next"
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 @@ -81,6 +93,8 @@ def best_practice_warnings

def compile
# check for new app at the beginning of the compile
warn("JUAN current 1", inline: true)
warn("JUAN starting compile #{ENV['BUNDLE_GEMFILE']}", inline: true)
new_app?
Dir.chdir(build_path)
remove_vendor_bundle
Expand All @@ -93,6 +107,7 @@ def compile
bundle_path: "vendor/bundle",
bundle_default_without: "development:test"
)
warn("JUAN starting compile allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
allow_git do
install_bundler_in_app(slug_vendor_base)
load_bundler_cache
Expand All @@ -102,12 +117,14 @@ def compile
install_binaries
run_assets_precompile_rake_task
end
warn("JUAN ending compile allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
config_detect
best_practice_warnings
warn_outdated_ruby
setup_profiled(ruby_layer_path: "$HOME", gem_layer_path: "$HOME") # $HOME is set to /app at run time
setup_export
cleanup
warn("JUAN ending compile #{ENV['BUNDLE_GEMFILE']}", inline: true)
super
rescue => e
warn_outdated_ruby
Expand All @@ -116,6 +133,7 @@ def compile


def build
warn("JUAN starting build #{ENV['BUNDLE_GEMFILE']}", inline: true)
new_app?
remove_vendor_bundle
warn_bad_binstubs
Expand All @@ -134,6 +152,7 @@ def build
bundle_path: "#{gem_layer.path}/vendor/bundle",
bundle_default_without: "development:test"
)
warn("JUAN starting build allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
allow_git do
# TODO install bundler in separate layer
topic "Loading Bundler Cache"
Expand All @@ -144,7 +163,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 All @@ -156,12 +175,14 @@ def build
install_binaries
run_assets_precompile_rake_task
end
warn("JUAN ending build allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
setup_profiled(ruby_layer_path: ruby_layer.path, gem_layer_path: gem_layer.path)
setup_export(gem_layer)
config_detect
best_practice_warnings
cleanup

warn("JUAN ending build #{ENV['BUNDLE_GEMFILE']}", inline: true)
super
end

Expand Down Expand Up @@ -779,7 +800,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 +837,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

0 comments on commit 4df8106

Please sign in to comment.