Module: Dependabot::Bundler::NativeHelpers

Defined in:
lib/dependabot/bundler/native_helpers.rb

Defined Under Namespace

Classes: BundleCommand

Class Method Summary collapse

Class Method Details

.native_helpers_rootObject



68
69
70
71
72
73
# File 'lib/dependabot/bundler/native_helpers.rb', line 68

def self.native_helpers_root
  helpers_root = ENV["DEPENDABOT_NATIVE_HELPERS_PATH"]
  return File.join(helpers_root, "bundler") unless helpers_root.nil?

  File.join(__dir__, "../../../helpers")
end

.run_bundler_subprocess(function:, args:, bundler_version:, options: {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dependabot/bundler/native_helpers.rb', line 36

def self.run_bundler_subprocess(function:, args:, bundler_version:, options: {})
  # Run helper suprocess with all bundler-related ENV variables removed
  bundler_major_version = bundler_version.split(".").first
  helpers_path = versioned_helper_path(bundler_version: bundler_major_version)
  ::Bundler.with_original_env do
    command = BundleCommand.
              new(options[:timeout_per_operation_seconds]).
              build(File.join(helpers_path, "run.rb"))
    SharedHelpers.run_helper_subprocess(
      command: command,
      function: function,
      args: args,
      env: {
        # Bundler will pick the matching installed major version
        "BUNDLER_VERSION" => bundler_version,
        "BUNDLE_GEMFILE" => File.join(helpers_path, "Gemfile"),
        # Prevent the GEM_HOME from being set to a folder owned by root
        "GEM_HOME" => File.join(helpers_path, ".bundle")
      }
    )
  rescue SharedHelpers::HelperSubprocessFailed => e
    # TODO: Remove once we stop stubbing out the V2 native helper
    raise Dependabot::NotImplemented, e.message if e.error_class == "Functions::NotImplementedError"

    raise
  end
end

.versioned_helper_path(bundler_version:) ⇒ Object



64
65
66
# File 'lib/dependabot/bundler/native_helpers.rb', line 64

def self.versioned_helper_path(bundler_version:)
  File.join(native_helpers_root, "v#{bundler_version}")
end