Module: Dependabot::Bundler::NativeHelpers

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

Class Method Summary collapse

Class Method Details

.helper_path(bundler_version:) ⇒ Object


38
39
40
# File 'lib/dependabot/bundler/native_helpers.rb', line 38

def self.helper_path(bundler_version:)
  "ruby #{File.join(versioned_helper_path(bundler_version: bundler_version), 'run.rb')}"
end

.native_helpers_rootObject


42
43
44
45
46
47
# File 'lib/dependabot/bundler/native_helpers.rb', line 42

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:) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dependabot/bundler/native_helpers.rb', line 9

def self.run_bundler_subprocess(function:, args:, bundler_version:)
  # Run helper suprocess with all bundler-related ENV variables removed
  ::Bundler.with_original_env do
    SharedHelpers.run_helper_subprocess(
      command: helper_path(bundler_version: bundler_version),
      function: function,
      args: args,
      env: {
        # Bundler will pick the matching installed major version
        "BUNDLER_VERSION" => bundler_version,
        "BUNDLE_GEMFILE" => File.join(versioned_helper_path(bundler_version: bundler_version), "Gemfile"),
        "BUNDLE_PATH" => File.join(versioned_helper_path(bundler_version: bundler_version), ".bundle"),
        # Prevent the GEM_HOME from being set to a folder owned by root
        "GEM_HOME" => File.join(versioned_helper_path(bundler_version: bundler_version), ".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


33
34
35
36
# File 'lib/dependabot/bundler/native_helpers.rb', line 33

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