Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Make Bundler load Project's Gemfile dependencies (#703)
Browse files Browse the repository at this point in the history
* Make Bundler load Project's Gemfile dependencies

* Test over 9000

* So sad.

* After years and years of fighting...
  • Loading branch information
minuscorp committed Apr 20, 2018
1 parent ebd3db7 commit d7c923d
Showing 1 changed file with 49 additions and 20 deletions.
69 changes: 49 additions & 20 deletions app/features/build_runner/fastlane_build_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,50 @@ def run(new_line_block:, completion_block:)
# folder, and all the following code works
# This is needed to load other configuration files, and also find Xcode projects

original_gemfile = File.open(Bundler.default_gemfile, "rb")
original_gemfile_contents = original_gemfile.read
original_gemfile.close
original_lockfile = File.open(Bundler.default_lockfile, "rb")
original_lockfile_contents = original_lockfile.read
original_lockfile.close
# We call the safe (because is synchronized) Bundler's `chdir` and
# install all the dependencies, if any.
Bundler::SharedHelpers.chdir(File.expand_path("..", fast_file_path)) do
Bundler::SharedHelpers.chdir(repo.local_folder) do
ENV["FASTLANE_SKIP_DOCS"] = true.to_s

begin
options = {}
options[:local] = true if Bundler.app_cache.exist?

Bundler::Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?

definition = Bundler.definition
definition.validate_runtime!

Bundler::Installer.install(Bundler.root, definition, options)
Bundler.load.cache if Bundler.app_cache.exist? && !Bundler.frozen_bundle?
# rubocop:disable Metrics/LineLength
logger.info("Bundle complete! #{definition.dependencies.count} Gemfile dependencies, installed #{definition.specs.count} gems.")
# rubocop:enable Metrics/LineLength
rescue Bundler::GemfileNotFound => ex
logger.info(ex)
rescue StandardError => ex
logger.error(ex)
logger.error(ex.backtrace)
gemfile_found = Dir[File.join(Dir.pwd, "**", "Gemfile")].any?
if gemfile_found
begin
gemfile_dir = Dir[File.join(Dir.pwd, "**", "Gemfile")].first

builder = Bundler::Dsl.new
builder.eval_gemfile(gemfile_dir)

# We already use local fastlane, so don't try to install it.
project_dependencies = builder.dependencies.reject { |d| d.name == "fastlane" }

added = Bundler::Injector.inject(project_dependencies, {})
if added.any?
logger.info("Added to Gemfile:")
logger.info(added.map do |d|
name = "'#{d.name}'"
requirement = ", '#{d.requirement}'"
group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default)
source = ", :source => '#{d.source}'" unless d.source.nil?
%(gem #{name}#{requirement}#{group}#{source})
end.join("\n"))
end

Bundler::Installer.install(Bundler.root, Bundler.definition)
Bundler.require
rescue Bundler::GemfileNotFound, Bundler::GemNotFound => ex
logger.info(ex)
rescue Gem::LoadError => ex
logger.error(ex)
rescue StandardError => ex
logger.error(ex)
logger.error(ex.backtrace)
end
end

begin
Expand Down Expand Up @@ -153,6 +173,15 @@ def run(new_line_block:, completion_block:)
artifacts_paths = gather_build_artifact_paths(loggers: [verbose_log, info_log])

return
ensure
if gemfile_found
original_gemfile = File.open(Bundler.default_gemfile, "wb")
original_gemfile.write(original_gemfile_contents)
original_gemfile.close
original_lockfile = File.open(Bundler.default_lockfile, "wb")
original_lockfile.write(original_lockfile_contents)
original_lockfile.close
end
end
end

Expand Down

0 comments on commit d7c923d

Please sign in to comment.