add :check_libpath option to check_lib configuration method - #107

This commit is contained in:
Josh Holtrop 2019-07-29 21:00:52 -04:00
parent 6e590b62a6
commit 51a9dd365f
5 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,5 @@
build do
Environment.new(echo: :command) do |env|
env.Library("usr2/libfrobulous.a", "two.c")
end
end

View File

@ -0,0 +1,10 @@
configure do
check_lib "m", check_libpath: ["./usr1"]
check_lib "frobulous", check_libpath: ["./usr2"]
end
build do
Environment.new(echo: :command) do |env|
env.Program("simple.exe", "simple.c")
end
end

View File

@ -0,0 +1,4 @@
int two(void)
{
return 42;
}

View File

@ -235,6 +235,7 @@ module Rscons
# Check for a library. # Check for a library.
def check_lib(lib, options = {}) def check_lib(lib, options = {})
check_libpath = [nil] + (options[:check_libpath] || [])
Ansi.write($stdout, "Checking for library '", :cyan, lib, :reset, "'... ") Ansi.write($stdout, "Checking for library '", :cyan, lib, :reset, "'... ")
File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| File.open("#{@work_dir}/cfgtest.c", "wb") do |fh|
fh.puts <<-EOF fh.puts <<-EOF
@ -249,8 +250,21 @@ module Rscons
"_SOURCES" => "#{@work_dir}/cfgtest.c", "_SOURCES" => "#{@work_dir}/cfgtest.c",
"_TARGET" => "#{@work_dir}/cfgtest.exe", "_TARGET" => "#{@work_dir}/cfgtest.exe",
} }
command = BasicEnvironment.new.build_command("${LDCMD}", vars) status = 1
_, _, status = log_and_test_command(command) check_libpath.each do |libpath|
env = BasicEnvironment.new
if libpath
env["LIBPATH"] += Array(libpath)
end
command = env.build_command("${LDCMD}", vars)
_, _, status = log_and_test_command(command)
if status == 0
if libpath
store_append({"LIBPATH" => Array(libpath)}, options)
end
break
end
end
if status == 0 if status == 0
store_append({"LIBS" => [lib]}, options) store_append({"LIBS" => [lib]}, options)
end end

View File

@ -1986,6 +1986,23 @@ EOF
expect(result.stdout).to match /Checking for library 'm'... found/ expect(result.stdout).to match /Checking for library 'm'... found/
expect(result.stdout).to_not match /-lm/ expect(result.stdout).to_not match /-lm/
end end
it "modifies LIBPATH based on check_libpath" do
test_dir "configure"
FileUtils.mkdir_p("usr1")
FileUtils.mkdir_p("usr2")
result = run_rscons(rsconscript: "check_lib_libpath1.rb")
expect(result.stderr).to eq ""
expect(result.status).to eq 0
result = run_rscons(rsconscript: "check_lib_libpath2.rb", op: "configure")
expect(result.stderr).to eq ""
expect(result.status).to eq 0
result = run_rscons(rsconscript: "check_lib_libpath2.rb")
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(result.stdout).to match %r{-L\./usr2}
expect(result.stdout).to_not match %r{-L\./usr1}
end
end end
context "check_program" do context "check_program" do