Skip to content

Commit

Permalink
use env var to set site path confs
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Jul 28, 2023
1 parent 3d0bbd4 commit 33dfd19
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
9 changes: 0 additions & 9 deletions lib/rake/always_file_task.rb

This file was deleted.

31 changes: 6 additions & 25 deletions lib/rake/extensiontask.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "rbconfig"

require "mkmf"
require 'rake/baseextensiontask'
require 'rake/always_file_task'
require "rubygems/package_task"

# Define a series of tasks to aid in the compilation of C extensions for
Expand Down Expand Up @@ -80,7 +79,7 @@ def cross_config_options(for_platform=nil)
end.flatten
end

def make_makefile_cmd(root_path, tmp_path, extconf, siteconf_path, cross_platform) # :nodoc:
def make_makefile_cmd(root_path, tmp_path, extconf, cross_platform) # :nodoc:
# include current directory
include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)

Expand All @@ -90,7 +89,7 @@ def make_makefile_cmd(root_path, tmp_path, extconf, siteconf_path, cross_platfor
rel_extconf = abs_extconf.relative_path_from(abs_tmp_path).to_s

# base command
cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}", rel_extconf]
cmd = [Gem.ruby, "-I#{include_dirs}", rel_extconf]

# add all the options
cmd += @config_options
Expand Down Expand Up @@ -124,10 +123,6 @@ def define_staging_file_tasks(files, lib_path, stage_path, platf, ruby_ver)
end
end

def always_file(*args, &block)
AlwaysFileTask.define_task(*args, &block)
end

def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
# platform usage
platf = for_platform || platform
Expand All @@ -145,7 +140,6 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
tmp_path = "#{@tmp_dir}/#{platf}/#{@name}/#{ruby_ver}"
stage_path = "#{@tmp_dir}/#{platf}/stage"

siteconf_path = "#{tmp_path}/.rake-compiler-siteconf.rb"
tmp_binary_path = "#{tmp_path}/#{binary_path}"
tmp_binary_dir_path = File.dirname(tmp_binary_path)
stage_binary_path = "#{stage_path}/#{lib_binary_path}"
Expand All @@ -163,20 +157,6 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
directory lib_path
directory stage_binary_dir_path

directory File.dirname(siteconf_path)
# Set paths for "make install" destinations
always_file siteconf_path => File.dirname(siteconf_path) do
File.open(siteconf_path, "w") do |siteconf|
siteconf.puts "require 'rbconfig'"
siteconf.puts "require 'mkmf'"
siteconf.puts "dest_path = mkintpath(#{File.expand_path(lib_path).dump})"
%w[sitearchdir sitelibdir].each do |dir|
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
end
end
end

# copy binary from temporary location to final lib
# tmp/extension_name/extension_name.{so,bundle} => lib/
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_path, tmp_binary_path, "#{tmp_path}/Makefile"] do
Expand Down Expand Up @@ -212,16 +192,17 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)

# makefile depends of tmp_dir and config_script
# tmp/extension_name/Makefile
file "#{tmp_path}/Makefile" => [tmp_path, extconf, siteconf_path] do |t|
file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t|
if t.prerequisites.include?("#{tmp_path}/fake.rb")
cross_platform = platf
else
cross_platform = nil
end

command = make_makefile_cmd(Dir.pwd, tmp_path, extconf, siteconf_path, cross_platform)
command = make_makefile_cmd(Dir.pwd, tmp_path, extconf, cross_platform)

chdir tmp_path do
ENV['sitearchdir'] = ENV['sitelibdir'] = mkintpath(File.expand_path(lib_path).dump)
sh(*command)
end
end
Expand Down
18 changes: 4 additions & 14 deletions spec/lib/rake/extensiontask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@
it "should depend on 'compile:{platform}'" do
Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
end

it "should always rebuild the siteconf" do
task = Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/.rake-compiler-siteconf.rb"]
task.is_a? Rake::AlwaysFileTask
end
end

context 'compile:extension_one' do
Expand Down Expand Up @@ -294,7 +289,6 @@
around :each do |test|
@tmp_path = "injectedtmp"
@extconf = "injectedextconf.rb"
@siteconf_path = "#{@tmp_path}/.injected-siteconf.rb"

Dir.mktmpdir do |root_path|
@root_path = root_path
Expand All @@ -318,13 +312,12 @@
end

it "runs the extconf with proper arguments when not cross-compiling" do
command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, @siteconf_path, nil)
command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, nil)

expected_includes = [".", "/injected/include1", "/injected/include2"].join(File::PATH_SEPARATOR)
expected = [
Gem.ruby,
"-I#{expected_includes}",
"-r.injected-siteconf.rb",
"../#{@extconf}",
"--with-a", # config_options
"--", "--with-b", # extra_options
Expand All @@ -334,13 +327,12 @@
end

it "runs the extconf with proper arguments when cross-compiling" do
command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, @siteconf_path, "universal-known")
command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, "universal-known")

expected_includes = [".", "/injected/include1", "/injected/include2"].join(File::PATH_SEPARATOR)
expected = [
Gem.ruby,
"-I#{expected_includes}",
"-r.injected-siteconf.rb",
"../#{@extconf}",
"--with-a", # config_options
"--with-c", "--with-d", # cross_config_options
Expand All @@ -353,13 +345,12 @@
it "handles spaces in arguments correctly" do
@ext.extra_options << "--with-spaces='a b'"

command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, @siteconf_path, nil)
command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, nil)

expected_includes = [".", "/injected/include1", "/injected/include2"].join(File::PATH_SEPARATOR)
expected = [
Gem.ruby,
"-I#{expected_includes}",
"-r.injected-siteconf.rb",
"../#{@extconf}",
"--with-a", # config_options
"--", "--with-b", "--with-spaces='a b'", # extra_options
Expand All @@ -371,13 +362,12 @@
it "handles 'nil' in the command array gracefully" do
@ext.config_options << nil # imagine this is ENV['NONEXISTENT_VALUE']

command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, @siteconf_path, nil)
command = @ext.make_makefile_cmd(@root_path, @tmp_path, @extconf, nil)

expected_includes = [".", "/injected/include1", "/injected/include2"].join(File::PATH_SEPARATOR)
expected = [
Gem.ruby,
"-I#{expected_includes}",
"-r.injected-siteconf.rb",
"../#{@extconf}",
"--with-a", # config_options
"--", "--with-b", # extra_options
Expand Down

0 comments on commit 33dfd19

Please sign in to comment.