Add more integration tests for SharedLibrary and backwards compatibility

This commit is contained in:
Josh Holtrop 2017-06-07 13:02:51 -04:00
parent aa192d7567
commit db2ec82a25
8 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,6 @@
Rscons::Environment.new do |env|
File.open("foo.xyz", "wb") do |fh|
fh.puts("hi")
end
env.SharedObject("foo.o", "foo.xyz")
end

View File

@ -0,0 +1,11 @@
Rscons::Environment.new do |env|
env["CPPPATH"] << "src/lib"
libmine = env.SharedLibrary("libmine", Dir["src/lib/*.cc"])
env.Program("test-shared.exe",
Dir["src/*.cc"],
"LIBPATH" => %w[.],
"LIBS" => %w[mine])
env.build_after("test-shared.exe", libmine.to_s)
env.Program("test-static.exe",
Dir["src/**/*.cc"])
end

View File

@ -0,0 +1,12 @@
Rscons::Environment.new do |env|
env["CPPPATH"] << "src/lib"
env["SHLD"] = "gcc"
libmine = env.SharedLibrary("libmine", Dir["src/lib/*.c"])
env.Program("test-shared.exe",
Dir["src/*.c"],
"LIBPATH" => %w[.],
"LIBS" => %w[mine])
env.build_after("test-shared.exe", libmine.to_s)
env.Program("test-static.exe",
Dir["src/**/*.c"])
end

View File

@ -0,0 +1,6 @@
#include <stdio.h>
void one(void)
{
printf("Hi from one()\n");
}

View File

@ -0,0 +1,6 @@
#include <stdio.h>
void two(void)
{
printf("Hi from two()\n");
}

View File

@ -0,0 +1,8 @@
#include "one.h"
#include "two.h"
int main(int argc, char * argv[])
{
one();
two();
}

View File

@ -0,0 +1,28 @@
class MyObject < Rscons::Builder
def produces?(target, source, env)
target.end_with?(".o") and source.end_with?(".xyz")
end
def run(target, sources, cache, env, vars)
cflags = env.expand_varref("${CFLAGS}", vars)
vars = vars.merge(
"CFLAGS" => cflags + %w[-x c],
"CSUFFIX" => ".xyz")
env.run_builder(env.builders["Object"], target, sources, cache, vars)
end
end
Rscons::Environment.new do |env|
env.add_builder(MyObject.new)
File.open("test.xyz", "w") do |fh|
fh.puts <<EOF
#include <stdio.h>
int main(int argc, char * argv[])
{
printf("XYZ!\\n");
return 0;
}
EOF
env.Program("test", "test.xyz")
end
end

View File

@ -687,6 +687,22 @@ EOF
expect(`./test-static.exe`).to match /Hi from one/
end
it "creates shared libraries using C++" do
test_dir("shared_library")
result = run_test(rsconsfile: "shared_library_cxx.rb")
expect(result.stderr).to eq ""
slines = lines(result.stdout)
expect(slines).to include("SHLD libmine.so")
result = run_test(rsconsfile: "shared_library_cxx.rb")
expect(result.stderr).to eq ""
expect(result.stdout).to eq ""
expect(`LD_LIBRARY_PATH=. ./test-shared.exe`).to match /Hi from one/
expect(`./test-static.exe`).to match /Hi from one/
end
context "backward compatibility" do
it "allows a builder to call Environment#run_builder in a non-threaded manner" do
test_dir("simple")
@ -725,6 +741,12 @@ EOF
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["MyCommand simple.o"]
end
it "supports the old 3-parameter signature to Builder#produces?" do
test_dir("simple")
result = run_test(rsconsfile: "bc_produces.rb")
expect(result.stderr).to eq ""
end
end
context "CFile builder" do
@ -1115,6 +1137,14 @@ EOF
end
end
context "SharedObject builder" do
it "raises an error when given a source file with an unknown suffix" do
test_dir("shared_library")
result = run_test(rsconsfile: "error_unknown_suffix.rb")
expect(result.stderr).to match /unknown input file type: "foo.xyz"/
end
end
context "Library builder" do
it "allows overriding ARCMD construction variable" do
test_dir("library")
@ -1124,6 +1154,17 @@ EOF
end
end
context "SharedLibrary builder" do
it "allows explicitly specifying SHLD construction variable value" do
test_dir("shared_library")
result = run_test(rsconsfile: "shared_library_set_shld.rb")
expect(result.stderr).to eq ""
slines = lines(result.stdout)
expect(slines).to include("SHLD libmine.so")
end
end
context "multi-threading" do
it "waits for subcommands in threads for builders that support threaded commands" do
test_dir("simple")