pass the Environment to configure to ConfigureOp; begin modifying it in the tests

This commit is contained in:
Josh Holtrop 2018-11-07 20:46:07 -05:00
parent d656df5407
commit 30511a3443
2 changed files with 38 additions and 6 deletions

View File

@ -83,7 +83,7 @@ module Rscons
# @return [void] # @return [void]
def configure def configure
rv = 0 rv = 0
co = ConfigureOp.new("#{@build_dir}/configure") co = ConfigureOp.new("#{@build_dir}/configure", @default_environment)
begin begin
if ccc = @script.check_c_compiler if ccc = @script.check_c_compiler
co.check_c_compiler(ccc) co.check_c_compiler(ccc)

View File

@ -12,8 +12,11 @@ module Rscons
# #
# @param work_dir [String] # @param work_dir [String]
# Work directory for configure operation. # Work directory for configure operation.
def initialize(work_dir) # @param env [Environment]
# Environment aggregating the configuration options.
def initialize(work_dir, env)
@work_dir = work_dir @work_dir = work_dir
@env = env
FileUtils.mkdir_p(@work_dir) FileUtils.mkdir_p(@work_dir)
@log_fh = File.open("#{@work_dir}/config.log", "wb") @log_fh = File.open("#{@work_dir}/config.log", "wb")
end end
@ -117,14 +120,19 @@ module Rscons
case cc case cc
when "gcc" when "gcc"
command = %W[gcc -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] command = %W[gcc -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c]
merge = {"CC" => "gcc"}
when "clang" when "clang"
command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c]
merge = {"CC" => "clang"}
else else
$stderr.puts "Unknown C compiler (#{cc})" $stderr.puts "Unknown C compiler (#{cc})"
raise ConfigureFailure.new raise ConfigureFailure.new
end end
_, _, status = log_and_test_command(command) _, _, status = log_and_test_command(command)
status == 0 if status == 0
merge_vars(merge)
true
end
end end
# Test a C++ compiler. # Test a C++ compiler.
@ -148,14 +156,19 @@ module Rscons
case cc case cc
when "g++" when "g++"
command = %W[g++ -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.cxx] command = %W[g++ -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.cxx]
merge = {"CXX" => "g++"}
when "clang++" when "clang++"
command = %W[clang++ -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.cxx] command = %W[clang++ -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.cxx]
merge = {"CXX" => "clang++"}
else else
$stderr.puts "Unknown C++ compiler (#{cc})" $stderr.puts "Unknown C++ compiler (#{cc})"
raise ConfigureFailure.new raise ConfigureFailure.new
end end
_, _, status = log_and_test_command(command) _, _, status = log_and_test_command(command)
status == 0 if status == 0
merge_vars(merge)
true
end
end end
# Test a D compiler. # Test a D compiler.
@ -178,14 +191,23 @@ module Rscons
case dc case dc
when "gdc" when "gdc"
command = %W[gdc -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d] command = %W[gdc -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d]
merge = {"DC" => "gdc"}
when "ldc2" when "ldc2"
command = %W[ldc2 -of=#{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d] command = %W[ldc2 -of #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d]
merge = {
"DC" => "ldc2",
"DCCMD" => @env["DCCMD"].map {|e| if e == "-o"; "-of"; else; e; end},
"LDCMD" => @env["LDCMD"].map {|e| if e == "-o"; "-of"; else; e; end},
}
else else
$stderr.puts "Unknown D compiler (#{dc})" $stderr.puts "Unknown D compiler (#{dc})"
raise ConfigureFailure.new raise ConfigureFailure.new
end end
_, _, status = log_and_test_command(command) _, _, status = log_and_test_command(command)
status == 0 if status == 0
merge_vars(merge)
true
end
end end
# Execute a test command and log the result. # Execute a test command and log the result.
@ -202,5 +224,15 @@ module Rscons
end end
end end
# Merge construction variables into the configured Environment.
#
# @param vars [Hash]
# Hash containing the variables to merge.
def merge_vars(vars)
vars.each_pair do |key, value|
@env[key] = value
end
end
end end
end end