c99b38
From f4061357d812e9033f07ae3f8f44c4e26839f1e5 Mon Sep 17 00:00:00 2001
c99b38
From: bronzdoc <lsagastume1990@gmail.com>
c99b38
Date: Mon, 14 Jan 2019 09:46:29 -0600
c99b38
Subject: [PATCH] Restore gem build behavior and introdcue the "-C" flag to gem
c99b38
 build
c99b38
c99b38
---
c99b38
 lib/rubygems/commands/build_command.rb        | 41 +++++++++++++------
c99b38
 .../test_gem_commands_build_command.rb        |  1 +
c99b38
 2 files changed, 29 insertions(+), 13 deletions(-)
c99b38
c99b38
diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb
c99b38
index e59471e976..761b80ee94 100644
c99b38
--- a/lib/rubygems/commands/build_command.rb
c99b38
+++ b/lib/rubygems/commands/build_command.rb
c99b38
@@ -18,6 +18,10 @@ def initialize
c99b38
     add_option '-o', '--output FILE', 'output gem with the given filename' do |value, options|
c99b38
       options[:output] = value
c99b38
     end
c99b38
+
c99b38
+    add_option '-C PATH', '', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options|
c99b38
+      options[:build_path] = value
c99b38
+    end
c99b38
   end
c99b38
 
c99b38
   def arguments # :nodoc:
c99b38
@@ -60,25 +64,36 @@ def execute
c99b38
     end
c99b38
 
c99b38
     if File.exist? gemspec
c99b38
-      Dir.chdir(File.dirname(gemspec)) do
c99b38
-        spec = Gem::Specification.load File.basename(gemspec)
c99b38
-
c99b38
-        if spec
c99b38
-          Gem::Package.build(
c99b38
-            spec,
c99b38
-            options[:force],
c99b38
-            options[:strict],
c99b38
-            options[:output]
c99b38
-          )
c99b38
-        else
c99b38
-          alert_error "Error loading gemspec. Aborting."
c99b38
-          terminate_interaction 1
c99b38
+      spec = Gem::Specification.load(gemspec)
c99b38
+
c99b38
+      if options[:build_path]
c99b38
+        Dir.chdir(File.dirname(gemspec)) do
c99b38
+          spec = Gem::Specification.load File.basename(gemspec)
c99b38
+          build_package(spec)
c99b38
         end
c99b38
+      else
c99b38
+        build_package(spec)
c99b38
       end
c99b38
+
c99b38
     else
c99b38
       alert_error "Gemspec file not found: #{gemspec}"
c99b38
       terminate_interaction 1
c99b38
     end
c99b38
   end
c99b38
 
c99b38
+  private
c99b38
+
c99b38
+  def build_package(spec)
c99b38
+    if spec
c99b38
+      Gem::Package.build(
c99b38
+        spec,
c99b38
+        options[:force],
c99b38
+        options[:strict],
c99b38
+        options[:output]
c99b38
+      )
c99b38
+    else
c99b38
+      alert_error "Error loading gemspec. Aborting."
c99b38
+      terminate_interaction 1
c99b38
+    end
c99b38
+  end
c99b38
 end
c99b38
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
c99b38
index ac82a408c7..02d1b98e8f 100644
c99b38
--- a/test/rubygems/test_gem_commands_build_command.rb
c99b38
+++ b/test/rubygems/test_gem_commands_build_command.rb
c99b38
@@ -207,6 +207,7 @@ def test_execute_outside_dir
c99b38
       gs.write @gem.to_ruby
c99b38
     end
c99b38
 
c99b38
+    @cmd.options[:build_path] = gemspec_dir
c99b38
     @cmd.options[:args] = [gemspec_file]
c99b38
 
c99b38
     use_ui @ui do