summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorJosef Šimánek <josef.simanek@gmail.com>2022-12-17 14:34:49 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-12-20 13:15:02 +0900
commit8eb66180137e3cba030d43fba21980efa5f58bb3 (patch)
treec4fd3b0fb975aa7fb9d1b8311d637c83c894e5df /lib/bundler
parenteaf0157dd1ad6cfbecedd9ff4158954418c1331c (diff)
[rubygems/rubygems] Turn `--ext` option into string. Deprecate usage without explicit value.
- this is preparation for onboarding Rust based extension gem generator https://github.com/rubygems/rubygems/commit/d32801bdbc
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6966
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/cli.rb37
-rw-r--r--lib/bundler/cli/gem.rb10
-rw-r--r--lib/bundler/man/bundle-gem.12
-rw-r--r--lib/bundler/man/bundle-gem.1.ronn2
4 files changed, 44 insertions, 7 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 3395e74556..9c164b09f4 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -10,6 +10,7 @@ module Bundler
AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean].freeze
PARSEABLE_COMMANDS = %w[check config help exec platform show version].freeze
+ EXTENSIONS = ["c"].freeze
COMMAND_ALIASES = {
"check" => "c",
@@ -22,6 +23,8 @@ module Bundler
}.freeze
def self.start(*)
+ check_deprecated_ext_option(ARGV) if ARGV.include?("--ext")
+
super
ensure
Bundler::SharedHelpers.print_major_deprecations!
@@ -576,7 +579,7 @@ module Bundler
method_option :edit, :type => :string, :aliases => "-e", :required => false, :banner => "EDITOR",
:lazy_default => [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? },
:desc => "Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)"
- method_option :ext, :type => :boolean, :default => false, :desc => "Generate the boilerplate for C extension code"
+ method_option :ext, :type => :string, :desc => "Generate the boilerplate for C extension code.", :enum => EXTENSIONS
method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library."
method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set --global gem.mit true`."
method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set --global gem.rubocop true`."
@@ -755,6 +758,38 @@ module Bundler
end
end
+ def self.check_deprecated_ext_option(arguments)
+ # when deprecated version of `--ext` is called
+ # print out deprecation warning and pretend `--ext=c` was provided
+ if deprecated_ext_value?(arguments)
+ SharedHelpers.major_deprecation 2, "Option `--ext` without explicit value is deprecated. Please pass value like `--ext=c` for C extension. Pretending `--ext=c` was used for now."
+ arguments[arguments.index("--ext")] = "--ext=c"
+ end
+ end
+
+ def self.deprecated_ext_value?(arguments)
+ index = arguments.index("--ext")
+ next_argument = arguments[index+1]
+
+ # it is ok when --ext is followed with valid extension value
+ # for example `bundle gem hello --ext c`
+ return false if EXTENSIONS.include?(next_argument)
+
+ # deprecated call when --ext is called with no value in last position
+ # for example `bundle gem hello_gem --ext`
+ return true if next_argument.nil?
+
+ # deprecated call when --ext is followed by other parameter
+ # for example `bundle gem --ext --no-ci hello_gem`
+ return true if next_argument.start_with?("-")
+
+ # deprecated call when --ext is followed by gem name
+ # for example `bundle gem --ext hello_gem`
+ return true if next_argument
+
+ false
+ end
+
private
# Automatically invoke `bundle install` and resume if
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 135bfde038..584b28d67d 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -15,7 +15,7 @@ module Bundler
"test-unit" => "3.0",
}.freeze
- attr_reader :options, :gem_name, :thor, :name, :target
+ attr_reader :options, :gem_name, :thor, :name, :target, :extension
def initialize(options, gem_name, thor)
@options = options
@@ -28,7 +28,9 @@ module Bundler
@name = @gem_name
@target = SharedHelpers.pwd.join(gem_name)
- validate_ext_name if options[:ext]
+ @extension = options[:ext]
+
+ validate_ext_name if @extension
end
def run
@@ -64,7 +66,7 @@ module Bundler
:author => git_author_name.empty? ? "TODO: Write your name" : git_author_name,
:email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
:test => options[:test],
- :ext => options[:ext],
+ :ext => extension,
:exe => options[:exe],
:bundler_version => bundler_dependency_version,
:git => use_git,
@@ -188,7 +190,7 @@ module Bundler
templates.merge!("exe/newgem.tt" => "exe/#{name}") if config[:exe]
- if options[:ext]
+ if extension
templates.merge!(
"ext/newgem/extconf.rb.tt" => "ext/#{name}/extconf.rb",
"ext/newgem/newgem.h.tt" => "ext/#{name}/#{underscored_name}.h",
diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1
index 8a82dfdd2a..e32a03daf4 100644
--- a/lib/bundler/man/bundle-gem.1
+++ b/lib/bundler/man/bundle-gem.1
@@ -48,7 +48,7 @@ Add a \fBCODE_OF_CONDUCT\.md\fR file to the root of the generated project\. If t
Do not create a \fBCODE_OF_CONDUCT\.md\fR (overrides \fB\-\-coc\fR specified in the global config)\.
.
.TP
-\fB\-\-ext\fR
+\fB\-\-ext=c\fR
Add boilerplate for C extension code to the generated project\. This behavior is disabled by default\.
.
.TP
diff --git a/lib/bundler/man/bundle-gem.1.ronn b/lib/bundler/man/bundle-gem.1.ronn
index 61c741fb24..6169175f3c 100644
--- a/lib/bundler/man/bundle-gem.1.ronn
+++ b/lib/bundler/man/bundle-gem.1.ronn
@@ -41,7 +41,7 @@ configuration file using the following names:
Do not create a `CODE_OF_CONDUCT.md` (overrides `--coc` specified in the
global config).
-* `--ext`:
+* `--ext=c`:
Add boilerplate for C extension code to the generated project. This behavior
is disabled by default.