diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 55f656e3f3afd0..f5977863ddcc26 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -120,20 +120,28 @@ def cli_help self.class.send(:class_options_help, shell) end + desc "install_or_cli_help", "Tries to run bundle install but prints a summary of bundler commands if there is no Gemfile", hide: true + def install_or_cli_help + invoke_other_command("install") + rescue GemfileNotFound => error + Bundler.ui.error error.message, wrap: true + invoke_other_command("cli_help") + end + def self.default_command(meth = nil) return super if meth - default_cli_command = Bundler.settings[:default_cli_command] - return default_cli_command if default_cli_command - - Bundler.ui.warn(<<~MSG) - In the next version of Bundler, running `bundle` without argument will no longer run `bundle install`. - Instead, the `help` command will be displayed. - - If you'd like to keep the previous behaviour please run `bundle config set default_cli_command install --global`. - MSG + unless Bundler.settings[:default_cli_command] + Bundler.ui.info <<-MSG + In the feature version of Bundler, running `bundle` without argument will no longer run `bundle install`. + Instead, the `cli_help` command will be displayed. Please use `bundle install` explicitly for scripts like CI/CD. + If you wish to use feature behavior now with `bundle config set default_cli_command cli_help --global` + or you can continue to use the old behavior with `bundle config set default_cli_command install_or_cli_help --global`. + This message will be removed after a default_cli_command value is set. + MSG + end - "install" + Bundler.settings[:default_cli_command] || "install_or_cli_help" end class_option "no-color", type: :boolean, desc: "Disable colorization in output" @@ -723,6 +731,19 @@ def current_command config[:current_command] end + def invoke_other_command(name) + _, _, config = @_initializer + original_command = config[:current_command] + command = self.class.all_commands[name] + config[:current_command] = command + send(name) + ensure + config[:current_command] = original_command + end + + def current_command=(command) + end + def print_command return unless Bundler.ui.debug? cmd = current_command diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 437390f3ec448b..2fa7d0d277943b 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -539,6 +539,8 @@ def unlocking? end def add_checksums + require "rubygems/package" + @locked_checksums = true setup_domain!(add_checksums: true) diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb index bfd9f5c91412ab..945bdbd5515fe5 100644 --- a/lib/bundler/vendor/thor/lib/thor.rb +++ b/lib/bundler/vendor/thor/lib/thor.rb @@ -625,7 +625,7 @@ def normalize_command_name(meth) #:nodoc: # alias name. def find_command_possibilities(meth) len = meth.to_s.length - possibilities = all_commands.merge(map).keys.select { |n| meth == n[0, len] }.sort + possibilities = all_commands.reject { |_k, c| c.hidden? }.merge(map).keys.select { |n| meth == n[0, len] }.sort unique_possibilities = possibilities.map { |k| map[k] || k }.uniq if possibilities.include?(meth) diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index ec2fa59412df64..bc70ed67fb8604 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -40,6 +40,9 @@ def self.build(extension, dest_path, results, args = [], lib_dir = nil, extensio end ENV["DESTDIR"] = nil + unless RbConfig::CONFIG["MAKE"]&.include?("nmake") + ENV["MAKEFLAGS"] ||= "-j#{Etc.nprocessors + 1}" + end make dest_path, results, extension_dir, tmp_dest_relative, target_rbconfig: target_rbconfig diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index ee3c0d0fd50ff5..ac6b77ad7483bf 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -87,16 +87,11 @@ def out_with_macos_man_workaround end context "with no arguments" do - it "installs and log a warning by default" do + it "tries to installs by default but print help on missing Gemfile" do bundle "", raise_on_error: false - expect(err).to include("running `bundle` without argument will no longer run `bundle install`.") expect(err).to include("Could not locate Gemfile") - end + expect(out).to include("In the feature version of Bundler") - it "prints a concise help message when default_cli_command set to cli_help" do - bundle "config set default_cli_command cli_help" - bundle "" - expect(err).to be_empty expect(out).to include("Bundler version #{Bundler::VERSION}"). and include("\n\nBundler commands:\n\n"). and include("\n\n Primary commands:\n"). @@ -105,8 +100,9 @@ def out_with_macos_man_workaround end it "runs bundle install when default_cli_command set to install" do - bundle "config set default_cli_command install" + bundle "config set default_cli_command install_or_cli_help" bundle "", raise_on_error: false + expect(out).to_not include("In the feature version of Bundler") expect(err).to include("Could not locate Gemfile") end end diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index ab1926734c1e78..c8af9c8dd404fb 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -2035,6 +2035,56 @@ L end + it "adds checksums when source is not specified" do + system_gems(%w[myrack-1.0.0], path: default_bundle_path) + + gemfile <<-G + gem "myrack" + G + + lockfile <<~L + GEM + specs: + myrack (1.0.0) + + PLATFORMS + ruby + x86_64-linux + + DEPENDENCIES + myrack + + BUNDLED WITH + #{Bundler::VERSION} + L + + simulate_platform "x86_64-linux" do + bundle "lock --add-checksums" + end + + # myrack is coming from gem_repo1 + # but it's simulated to install in the system gems path + checksums = checksums_section do |c| + c.checksum gem_repo1, "myrack", "1.0.0" + end + + expect(lockfile).to eq <<~L + GEM + specs: + myrack (1.0.0) + + PLATFORMS + ruby + x86_64-linux + + DEPENDENCIES + myrack + #{checksums} + BUNDLED WITH + #{Bundler::VERSION} + L + end + it "adds checksums to an existing lockfile, when gems are already installed" do build_repo4 do build_gem "nokogiri", "1.14.2" diff --git a/spec/bundler/other/cli_dispatch_spec.rb b/spec/bundler/other/cli_dispatch_spec.rb index 1039737b993983..a2c745b0703d24 100644 --- a/spec/bundler/other/cli_dispatch_spec.rb +++ b/spec/bundler/other/cli_dispatch_spec.rb @@ -15,6 +15,6 @@ it "print a friendly error when ambiguous" do bundle "in", raise_on_error: false - expect(err).to eq("Ambiguous command in matches [info, init, inject, install]") + expect(err).to eq("Ambiguous command in matches [info, init, install]") end end