Skip to content

Commit f9b65bf

Browse files
committed
Add support for executing a script directly.
1 parent e32a0b5 commit f9b65bf

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/rubygems/ext.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ module Gem::Ext; end
1818
require_relative "ext/rake_builder"
1919
require_relative "ext/cmake_builder"
2020
require_relative "ext/cargo_builder"
21+
require_relative "ext/script_builder"

lib/rubygems/ext/builder.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def initialize(spec, build_args = spec.build_args)
138138

139139
def builder_for(extension) # :nodoc:
140140
case extension
141+
# File that ends with .rb
141142
when /extconf/ then
142143
Gem::Ext::ExtConfBuilder
143144
when /configure/ then
@@ -149,6 +150,8 @@ def builder_for(extension) # :nodoc:
149150
Gem::Ext::CmakeBuilder
150151
when /Cargo.toml/ then
151152
Gem::Ext::CargoBuilder.new
153+
when /\.rb/ then
154+
Gem::Ext::ScriptBuilder
152155
else
153156
build_error("No builder for extension '#{extension}'")
154157
end

lib/rubygems/ext/script_builder.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
#--
4+
# Copyright 2023 Samuel Williams.
5+
# All rights reserved.
6+
# See LICENSE.txt for permissions.
7+
#++
8+
9+
class Gem::Ext::ScriptBuilder < Gem::Ext::Builder
10+
def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=Dir.pwd)
11+
env = {
12+
"PREFIX_PATH" => dest_path,
13+
"LIBRARY_PATH" => lib_dir,
14+
"EXTENSION_PATH" => extension_dir,
15+
}
16+
17+
run([extension] + args, results, class_name, Dir.pwd, env)
18+
end
19+
end

0 commit comments

Comments
 (0)