From b8ec905bb70000b4436b318e96acd9bb10d49996 Mon Sep 17 00:00:00 2001 From: Philip Harrison Date: Wed, 3 Mar 2021 12:04:36 +0000 Subject: [PATCH] Revert "Merge pull request #3196 from dependabot/feelepxyz/bundler2-spike" This reverts commit a0dd6035a4ab325ec802869235f2b69d23c93c22, reversing changes made to c93e297c91e860acbb6a08b294ff873c36c5bbe2. --- Dockerfile | 2 +- bundler/helpers/{v1 => }/build | 9 ---- bundler/helpers/{v1 => }/lib/functions.rb | 0 .../conflicting_dependency_resolver.rb | 0 .../lib/functions/dependency_source.rb | 0 .../{v1 => }/lib/functions/file_parser.rb | 0 .../{v1 => }/lib/functions/force_updater.rb | 0 .../lib/functions/lockfile_updater.rb | 0 .../lib/functions/version_resolver.rb | 0 .../definition_bundler_version_patch.rb | 0 .../definition_ruby_version_patch.rb | 0 .../monkey_patches/git_source_patch.rb | 0 bundler/helpers/{v1 => }/run.rb | 0 bundler/helpers/v1/.gitignore | 8 ---- bundler/helpers/v1/Gemfile | 16 ------- bundler/lib/dependabot/bundler/file_parser.rb | 13 ++--- .../lib/dependabot/bundler/file_updater.rb | 9 +--- .../bundler/file_updater/lockfile_updater.rb | 9 +--- bundler/lib/dependabot/bundler/helpers.rb | 16 ------- .../lib/dependabot/bundler/native_helpers.rb | 33 +------------ .../conflicting_dependency_resolver.rb | 11 +---- .../bundler/update_checker/force_updater.rb | 9 +--- .../dependency_source.rb | 24 +++------- .../update_checker/shared_bundler_helpers.rb | 13 ++--- .../update_checker/version_resolver.rb | 9 +--- .../latest_version_finder_spec.rb | 48 +++++++++---------- .../update_checker/version_resolver_spec.rb | 6 +-- .../dependabot/bundler/update_checker_spec.rb | 12 ++--- bundler/spec/native_spec_helper.rb | 4 +- common/lib/dependabot/shared_helpers.rb | 17 ++----- 30 files changed, 65 insertions(+), 203 deletions(-) rename bundler/helpers/{v1 => }/build (51%) rename bundler/helpers/{v1 => }/lib/functions.rb (100%) rename bundler/helpers/{v1 => }/lib/functions/conflicting_dependency_resolver.rb (100%) rename bundler/helpers/{v1 => }/lib/functions/dependency_source.rb (100%) rename bundler/helpers/{v1 => }/lib/functions/file_parser.rb (100%) rename bundler/helpers/{v1 => }/lib/functions/force_updater.rb (100%) rename bundler/helpers/{v1 => }/lib/functions/lockfile_updater.rb (100%) rename bundler/helpers/{v1 => }/lib/functions/version_resolver.rb (100%) rename bundler/helpers/{v1 => }/monkey_patches/definition_bundler_version_patch.rb (100%) rename bundler/helpers/{v1 => }/monkey_patches/definition_ruby_version_patch.rb (100%) rename bundler/helpers/{v1 => }/monkey_patches/git_source_patch.rb (100%) rename bundler/helpers/{v1 => }/run.rb (100%) delete mode 100644 bundler/helpers/v1/.gitignore delete mode 100644 bundler/helpers/v1/Gemfile delete mode 100644 bundler/lib/dependabot/bundler/helpers.rb diff --git a/Dockerfile b/Dockerfile index bc5c3cae1f..b10b783cea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -194,7 +194,7 @@ ENV DEPENDABOT_NATIVE_HELPERS_PATH="/opt" \ RUN bash /opt/terraform/helpers/build /opt/terraform && \ bash /opt/python/helpers/build /opt/python && \ bash /opt/dep/helpers/build /opt/dep && \ - bash /opt/bundler/helpers/v1/build /opt/bundler/v1 && \ + bash /opt/bundler/helpers/build /opt/bundler && \ bash /opt/go_modules/helpers/build /opt/go_modules && \ bash /opt/npm_and_yarn/helpers/build /opt/npm_and_yarn && \ bash /opt/hex/helpers/build /opt/hex && \ diff --git a/bundler/helpers/v1/build b/bundler/helpers/build similarity index 51% rename from bundler/helpers/v1/build rename to bundler/helpers/build index b492a36837..93f89bce2c 100755 --- a/bundler/helpers/v1/build +++ b/bundler/helpers/build @@ -8,20 +8,11 @@ if [ -z "$install_dir" ]; then exit 1 fi -if [ ! -d "$install_dir" ]; then - mkdir -p "$install_dir" -fi - helpers_dir="$(dirname "${BASH_SOURCE[0]}")" cp -r \ "$helpers_dir/lib" \ "$helpers_dir/monkey_patches" \ "$helpers_dir/run.rb" \ - "$helpers_dir/Gemfile" \ "$install_dir" cd "$install_dir" - -# NOTE: Sets `BUNDLED WITH` to match the installed v1 version in Gemfile.lock -# forcing specs and native helpers to run with the same version -BUNDLER_VERSION=1 bundle install diff --git a/bundler/helpers/v1/lib/functions.rb b/bundler/helpers/lib/functions.rb similarity index 100% rename from bundler/helpers/v1/lib/functions.rb rename to bundler/helpers/lib/functions.rb diff --git a/bundler/helpers/v1/lib/functions/conflicting_dependency_resolver.rb b/bundler/helpers/lib/functions/conflicting_dependency_resolver.rb similarity index 100% rename from bundler/helpers/v1/lib/functions/conflicting_dependency_resolver.rb rename to bundler/helpers/lib/functions/conflicting_dependency_resolver.rb diff --git a/bundler/helpers/v1/lib/functions/dependency_source.rb b/bundler/helpers/lib/functions/dependency_source.rb similarity index 100% rename from bundler/helpers/v1/lib/functions/dependency_source.rb rename to bundler/helpers/lib/functions/dependency_source.rb diff --git a/bundler/helpers/v1/lib/functions/file_parser.rb b/bundler/helpers/lib/functions/file_parser.rb similarity index 100% rename from bundler/helpers/v1/lib/functions/file_parser.rb rename to bundler/helpers/lib/functions/file_parser.rb diff --git a/bundler/helpers/v1/lib/functions/force_updater.rb b/bundler/helpers/lib/functions/force_updater.rb similarity index 100% rename from bundler/helpers/v1/lib/functions/force_updater.rb rename to bundler/helpers/lib/functions/force_updater.rb diff --git a/bundler/helpers/v1/lib/functions/lockfile_updater.rb b/bundler/helpers/lib/functions/lockfile_updater.rb similarity index 100% rename from bundler/helpers/v1/lib/functions/lockfile_updater.rb rename to bundler/helpers/lib/functions/lockfile_updater.rb diff --git a/bundler/helpers/v1/lib/functions/version_resolver.rb b/bundler/helpers/lib/functions/version_resolver.rb similarity index 100% rename from bundler/helpers/v1/lib/functions/version_resolver.rb rename to bundler/helpers/lib/functions/version_resolver.rb diff --git a/bundler/helpers/v1/monkey_patches/definition_bundler_version_patch.rb b/bundler/helpers/monkey_patches/definition_bundler_version_patch.rb similarity index 100% rename from bundler/helpers/v1/monkey_patches/definition_bundler_version_patch.rb rename to bundler/helpers/monkey_patches/definition_bundler_version_patch.rb diff --git a/bundler/helpers/v1/monkey_patches/definition_ruby_version_patch.rb b/bundler/helpers/monkey_patches/definition_ruby_version_patch.rb similarity index 100% rename from bundler/helpers/v1/monkey_patches/definition_ruby_version_patch.rb rename to bundler/helpers/monkey_patches/definition_ruby_version_patch.rb diff --git a/bundler/helpers/v1/monkey_patches/git_source_patch.rb b/bundler/helpers/monkey_patches/git_source_patch.rb similarity index 100% rename from bundler/helpers/v1/monkey_patches/git_source_patch.rb rename to bundler/helpers/monkey_patches/git_source_patch.rb diff --git a/bundler/helpers/v1/run.rb b/bundler/helpers/run.rb similarity index 100% rename from bundler/helpers/v1/run.rb rename to bundler/helpers/run.rb diff --git a/bundler/helpers/v1/.gitignore b/bundler/helpers/v1/.gitignore deleted file mode 100644 index 24563d85bc..0000000000 --- a/bundler/helpers/v1/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/.bundle/ -/.env -/tmp -/dependabot-*.gem -Gemfile.lock -spec/fixtures/projects/*/.bundle/ -!spec/fixtures/projects/**/Gemfile.lock -!spec/fixtures/projects/**/vendor diff --git a/bundler/helpers/v1/Gemfile b/bundler/helpers/v1/Gemfile deleted file mode 100644 index 3696ed2fd0..0000000000 --- a/bundler/helpers/v1/Gemfile +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -# TODO: Look into removing this. "find" used to get required from common's -# gemspec so we've added it here for backwards compatability during bundler 2 -# rollout. -# -# NOTE: If we don't require it and a customers `.gemspec` uses Find without -# requiring it, we'll start raising a DependencyFileNotEvaluatable error which -# is probably the right thing to do -require "find" - -source "https://rubygems.org" - -# NOTE: This is intentionally left blank as it's currently only used to force -# bundler to use v1 when executing native helpers by pointing the BUNDLE_GEMFILE -# env to this Gemfile in Dependabot::Bundler::NativeHelpers diff --git a/bundler/lib/dependabot/bundler/file_parser.rb b/bundler/lib/dependabot/bundler/file_parser.rb index 4ff7cac3d8..a045f32857 100644 --- a/bundler/lib/dependabot/bundler/file_parser.rb +++ b/bundler/lib/dependabot/bundler/file_parser.rb @@ -5,7 +5,6 @@ require "dependabot/file_parsers/base" require "dependabot/bundler/file_updater/lockfile_updater" require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" require "dependabot/bundler/version" require "dependabot/shared_helpers" require "dependabot/errors" @@ -130,8 +129,8 @@ def parsed_gemfile repo_contents_path) do write_temporary_dependency_files - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "parsed_gemfile", args: { gemfile_name: gemfile.name, @@ -160,8 +159,8 @@ def parsed_gemspec(file) repo_contents_path) do write_temporary_dependency_files - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "parsed_gemspec", args: { gemspec_name: file.name, @@ -299,10 +298,6 @@ def imported_ruby_files select { |f| f.name.end_with?(".rb") }. reject { |f| f.name == "gems.rb" } end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/file_updater.rb b/bundler/lib/dependabot/bundler/file_updater.rb index d22427f074..c9a88441a2 100644 --- a/bundler/lib/dependabot/bundler/file_updater.rb +++ b/bundler/lib/dependabot/bundler/file_updater.rb @@ -3,7 +3,6 @@ require "dependabot/file_updaters" require "dependabot/file_updaters/base" require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" require "dependabot/file_updaters/vendor_updater" module Dependabot @@ -76,8 +75,8 @@ def vendor_cache_dir return @vendor_cache_dir if defined?(@vendor_cache_dir) @vendor_cache_dir = - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "vendor_cache_dir", args: { dir: repo_contents_path @@ -160,10 +159,6 @@ def top_level_gemspecs select { |file| file.name.end_with?(".gemspec") }. reject(&:support_file?) end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/file_updater/lockfile_updater.rb b/bundler/lib/dependabot/bundler/file_updater/lockfile_updater.rb index ec2d6ec9b0..8d9a57ea2d 100644 --- a/bundler/lib/dependabot/bundler/file_updater/lockfile_updater.rb +++ b/bundler/lib/dependabot/bundler/file_updater/lockfile_updater.rb @@ -6,7 +6,6 @@ require "dependabot/errors" require "dependabot/bundler/file_updater" require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" module Dependabot module Bundler @@ -65,8 +64,8 @@ def build_updated_lockfile ) do |tmp_dir| write_temporary_dependency_files - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "update_lockfile", args: { gemfile_name: gemfile.name, @@ -302,10 +301,6 @@ def using_bundler2? lockfile.content.match?(/BUNDLED WITH\s+2/m) end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/helpers.rb b/bundler/lib/dependabot/bundler/helpers.rb deleted file mode 100644 index ef1e6b7ebe..0000000000 --- a/bundler/lib/dependabot/bundler/helpers.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Dependabot - module Bundler - module Helpers - V1 = "1" - V2 = "2" - - # TODO: Add support for bundler v2 - # return "v2" if lockfile.content.match?(/BUNDLED WITH\s+2/m) - def self.bundler_version(_lockfile) - V1 - end - end - end -end diff --git a/bundler/lib/dependabot/bundler/native_helpers.rb b/bundler/lib/dependabot/bundler/native_helpers.rb index 60eba25378..315fc55c42 100644 --- a/bundler/lib/dependabot/bundler/native_helpers.rb +++ b/bundler/lib/dependabot/bundler/native_helpers.rb @@ -1,39 +1,10 @@ # frozen_string_literal: true -require "dependabot/shared_helpers" - module Dependabot module Bundler module NativeHelpers - def self.run_bundler_subprocess(function:, args:, bundler_version:) - 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, - # Force bundler to use the helper Gemfile that has been bundled with - # v1, otherwise it will point to core's bundler/Gemfile which will - # be bundled with v2 once it's installed - "BUNDLE_GEMFILE" => File.join(versioned_helper_path(bundler_version: bundler_version), "Gemfile"), - # Unset ruby env set by running dependabot-core with bundle exec, - # forcing bundler to reset them from helpers/v1 - "RUBYLIB" => nil, - "RUBYOPT" => nil, - "GEM_PATH" => nil, - "GEM_HOME" => nil - } - ) - end - - def self.versioned_helper_path(bundler_version:) - native_helper_version = "v#{bundler_version}" - File.join(native_helpers_root, native_helper_version) - end - - def self.helper_path(bundler_version:) - "bundle exec ruby #{File.join(versioned_helper_path(bundler_version: bundler_version), 'run.rb')}" + def self.helper_path + "bundle exec ruby #{File.join(native_helpers_root, 'run.rb')}" end def self.native_helpers_root diff --git a/bundler/lib/dependabot/bundler/update_checker/conflicting_dependency_resolver.rb b/bundler/lib/dependabot/bundler/update_checker/conflicting_dependency_resolver.rb index a78c3544ca..4cf7fbef28 100644 --- a/bundler/lib/dependabot/bundler/update_checker/conflicting_dependency_resolver.rb +++ b/bundler/lib/dependabot/bundler/update_checker/conflicting_dependency_resolver.rb @@ -2,7 +2,6 @@ require "dependabot/bundler/update_checker" require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" require "dependabot/shared_helpers" module Dependabot @@ -29,8 +28,8 @@ def initialize(dependency_files:, repo_contents_path:, credentials:) # * requirement [String] the requirement on the target_dependency def conflicting_dependencies(dependency:, target_version:) in_a_native_bundler_context(error_handling: false) do |tmp_dir| - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "conflicting_dependencies", args: { dir: tmp_dir, @@ -43,12 +42,6 @@ def conflicting_dependencies(dependency:, target_version:) ) end end - - private - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/update_checker/force_updater.rb b/bundler/lib/dependabot/bundler/update_checker/force_updater.rb index cfd5f32c29..feeb0d1b78 100644 --- a/bundler/lib/dependabot/bundler/update_checker/force_updater.rb +++ b/bundler/lib/dependabot/bundler/update_checker/force_updater.rb @@ -3,7 +3,6 @@ require "dependabot/bundler/file_parser" require "dependabot/bundler/file_updater/lockfile_updater" require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" require "dependabot/bundler/update_checker" require "dependabot/bundler/update_checker/requirements_updater" require "dependabot/errors" @@ -44,8 +43,8 @@ def update_multiple_dependencies? def force_update in_a_native_bundler_context(error_handling: false) do |tmp_dir| - updated_deps, specs = NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + updated_deps, specs = SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "force_update", args: { dir: tmp_dir, @@ -147,10 +146,6 @@ def using_bundler2? lockfile.content.match?(/BUNDLED WITH\s+2/m) end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb b/bundler/lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb index 2943ba0b05..e51887e4f3 100644 --- a/bundler/lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb +++ b/bundler/lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" - module Dependabot module Bundler class UpdateChecker @@ -56,8 +53,8 @@ def latest_git_version_details SharedHelpers.with_git_configured(credentials: credentials) do in_a_native_bundler_context do |tmp_dir| - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "depencency_source_latest_git_version", args: { dir: tmp_dir, @@ -101,8 +98,8 @@ def dependency_rubygems_uri def private_registry_versions @private_registry_versions ||= in_a_native_bundler_context do |tmp_dir| - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "private_registry_versions", args: { dir: tmp_dir, @@ -121,8 +118,8 @@ def source_type return @source_type = RUBYGEMS unless gemfile @source_type = in_a_native_bundler_context do |tmp_dir| - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "dependency_source_type", args: { dir: tmp_dir, @@ -138,15 +135,6 @@ def gemfile dependency_files.find { |f| f.name == "Gemfile" } || dependency_files.find { |f| f.name == "gems.rb" } end - - def lockfile - dependency_files.find { |f| f.name == "Gemfile.lock" } || - dependency_files.find { |f| f.name == "gems.locked" } - end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/update_checker/shared_bundler_helpers.rb b/bundler/lib/dependabot/bundler/update_checker/shared_bundler_helpers.rb index 9583332300..a6c04a7da2 100644 --- a/bundler/lib/dependabot/bundler/update_checker/shared_bundler_helpers.rb +++ b/bundler/lib/dependabot/bundler/update_checker/shared_bundler_helpers.rb @@ -4,7 +4,6 @@ require "dependabot/bundler/update_checker" require "dependabot/bundler/native_helpers" -require "dependabot/bundler/helpers" require "dependabot/shared_helpers" require "dependabot/errors" @@ -164,8 +163,8 @@ def handle_bundler_errors(error) def inaccessible_git_dependencies in_a_native_bundler_context(error_handling: false) do |tmp_dir| - git_specs = NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + git_specs = SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "git_specs", args: { dir: tmp_dir, @@ -188,8 +187,8 @@ def inaccessible_git_dependencies def jfrog_source in_a_native_bundler_context(error_handling: false) do |dir| - NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "jfrog_source", args: { dir: dir, @@ -237,10 +236,6 @@ def using_bundler2? lockfile.content.match?(/BUNDLED WITH\s+2/m) end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/lib/dependabot/bundler/update_checker/version_resolver.rb b/bundler/lib/dependabot/bundler/update_checker/version_resolver.rb index a482b26967..3cdce23605 100644 --- a/bundler/lib/dependabot/bundler/update_checker/version_resolver.rb +++ b/bundler/lib/dependabot/bundler/update_checker/version_resolver.rb @@ -2,7 +2,6 @@ require "excon" -require "dependabot/bundler/helpers" require "dependabot/bundler/update_checker" require "dependabot/bundler/file_updater/lockfile_updater" require "dependabot/bundler/requirement" @@ -76,8 +75,8 @@ def fetch_latest_resolvable_version_details # some errors we want to handle specifically ourselves, including # potentially retrying in the case of the Ruby version being locked in_a_native_bundler_context(error_handling: false) do |tmp_dir| - details = NativeHelpers.run_bundler_subprocess( - bundler_version: bundler_version, + details = SharedHelpers.run_helper_subprocess( + command: NativeHelpers.helper_path, function: "resolve_version", args: { dependency_name: dependency.name, @@ -219,10 +218,6 @@ def using_bundler2? lockfile.content.match?(/BUNDLED WITH\s+2/m) end - - def bundler_version - @bundler_version ||= Helpers.bundler_version(lockfile) - end end end end diff --git a/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb b/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb index b831824a98..ecfe8bd7f9 100644 --- a/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker/latest_version_finder_spec.rb @@ -241,18 +241,18 @@ before do # We only need to stub out the version callout since it would # otherwise call out to the internet in a shell command - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "dependency_source_type", args: anything }).and_call_original - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). @@ -297,10 +297,10 @@ end before do - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). @@ -330,10 +330,10 @@ end before do - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). @@ -363,10 +363,10 @@ end before do - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). @@ -385,10 +385,10 @@ context "that doesn't have details of the gem" do before do - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). @@ -540,18 +540,18 @@ before do # We only need to stub out the version callout since it would # otherwise call out to the internet in a shell command - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "dependency_source_type", args: anything }).and_call_original - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). diff --git a/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb b/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb index cae7c00cde..13940479c5 100644 --- a/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker/version_resolver_spec.rb @@ -188,10 +188,10 @@ end before do - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "resolve_version", args: anything }). diff --git a/bundler/spec/dependabot/bundler/update_checker_spec.rb b/bundler/spec/dependabot/bundler/update_checker_spec.rb index c5a098d496..2176b7dd07 100644 --- a/bundler/spec/dependabot/bundler/update_checker_spec.rb +++ b/bundler/spec/dependabot/bundler/update_checker_spec.rb @@ -195,18 +195,18 @@ before do # We only need to stub out the version callout since it would # otherwise call out to the internet in a shell command - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "dependency_source_type", args: anything }).and_call_original - allow(Dependabot::Bundler::NativeHelpers). - to receive(:run_bundler_subprocess). + allow(Dependabot::SharedHelpers). + to receive(:run_helper_subprocess). with({ - bundler_version: "1", + command: Dependabot::Bundler::NativeHelpers.helper_path, function: "private_registry_versions", args: anything }). diff --git a/bundler/spec/native_spec_helper.rb b/bundler/spec/native_spec_helper.rb index 01d15ebfe7..39c1d77d11 100644 --- a/bundler/spec/native_spec_helper.rb +++ b/bundler/spec/native_spec_helper.rb @@ -2,8 +2,8 @@ require "spec_helper" -$LOAD_PATH.unshift(File.expand_path("../helpers/v1/lib", __dir__)) -$LOAD_PATH.unshift(File.expand_path("../helpers/v1/monkey_patches", __dir__)) +$LOAD_PATH.unshift(File.expand_path("../helpers/lib", __dir__)) +$LOAD_PATH.unshift(File.expand_path("../helpers/monkey_patches", __dir__)) # Bundler monkey patches require "definition_ruby_version_patch" diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index 82ea8e5fde..b6d0724016 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -75,17 +75,13 @@ def self.run_helper_subprocess(command:, function:, args:, env: nil, start = Time.now stdin_data = JSON.dump(function: function, args: args) cmd = allow_unsafe_shell_command ? command : escape_command(command) - - # NOTE: For debugging native helpers in specs and dry-run: outputs the - # bash command to run in the tmp directory created by - # in_a_temporary_directory + env_cmd = [env, cmd].compact if ENV["DEBUG_FUNCTION"] == function - puts helper_subprocess_bash_command(stdin_data: stdin_data, command: cmd, env: env) + escaped_stdin_data = stdin_data.gsub("\"", "\\\"") + puts "$ cd #{Dir.pwd} && echo \"#{escaped_stdin_data}\" | #{env_cmd.join(' ')}" # Pause execution so we can run helpers inside the temporary directory byebug # rubocop:disable Lint/Debugger end - - env_cmd = [env, cmd].compact stdout, stderr, process = Open3.capture3(*env_cmd, stdin_data: stdin_data) time_taken = Time.now - start @@ -290,12 +286,5 @@ def self.run_shell_command(command, allow_unsafe_shell_command: false) error_context: error_context ) end - - def self.helper_subprocess_bash_command(command:, stdin_data:, env:) - escaped_stdin_data = stdin_data.gsub("\"", "\\\"") - env_keys = env ? env.compact.map { |k, v| "#{k}=#{v}" }.join(" ") + " " : "" - "$ cd #{Dir.pwd} && echo \"#{escaped_stdin_data}\" | #{env_keys}#{command}" - end - private_class_method :helper_subprocess_bash_command end end