Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/cibuildgem/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ def run_rake_tasks!(*tasks)
rake_path = rake_specs.full_require_paths
prism_path = Gem.loaded_specs["prism"].full_require_paths
load_paths = (rake_compiler_path + rake_path + prism_path).join(File::PATH_SEPARATOR)
patch = File.expand_path("../extension_patch.rb", __FILE__)

system({ "RUBYLIB" => load_paths }, "bundle exec #{RbConfig.ruby} #{rake_executable} #{all_tasks} -R#{rakelibdir}", exception: true)
system(
{ "RUBYLIB" => load_paths },
"bundle exec #{RbConfig.ruby} #{rake_executable} #{all_tasks} -R#{rakelibdir} -r #{patch}",
exception: true,
)
end

def compilation_task
Expand Down
2 changes: 2 additions & 0 deletions lib/cibuildgem/compilation_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(create_packaging_task = false, gemspec = nil)
end

def setup
Rake::ExtensionTask.enable!

gemspec.extensions.each do |path|
binary_name = parse_extconf(path)
define_task(path, binary_name)
Expand Down
25 changes: 25 additions & 0 deletions lib/cibuildgem/extension_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require "rake/extensiontask"

module Cibuildgem
module ExtensionPatch
class << self
def prepended(mod)
class << mod
attr_accessor :enabled

def enable!
@enabled = true
end
end
end
end

def define
super if self.class.enabled
end
end
end

Rake::ExtensionTask.prepend(Cibuildgem::ExtensionPatch)
9 changes: 9 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "English"

module Cibuildgem
class CLITest < Minitest::Test
Expand Down Expand Up @@ -214,6 +215,14 @@ def test_cli_test_command_when_no_test_or_spec_rake_task_is_defined
end
end

def test_package_when_a_rakefile_defines_an_extension_task
Dir.chdir("test/fixtures/with_ext") do
CLI.start(["package"])
end

assert_predicate($CHILD_STATUS, :success?)
end

private

def raise_instead_of_exit(&block)
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/with_ext/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "rake/extensiontask"

gemspec = Gem::Specification.load("foo.gemspec")
Rake::ExtensionTask.new("foo", gemspec)

raise "No rake task should have been defined" if Rake::Task.task_defined?(:native)

exit(0)
14 changes: 14 additions & 0 deletions test/fixtures/with_ext/foo.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "edouard-dummy_gem"
spec.version = "0.0.1"
spec.authors = ["Edouard CHIN"]
spec.email = ["user@example.org"]
spec.summary = "A gem that do nothing"
spec.description = "Don't use it, really."
spec.license = "MIT"
spec.files = []
spec.require_paths = ["lib"]
spec.extensions = ["ext/hello_world/extconf.rb"]
end