fix dependency parsing with ldc2 - close #110
This commit is contained in:
parent
2385874f4a
commit
1e157c79ec
@ -1,3 +1,7 @@
|
||||
configure do
|
||||
check_d_compiler "gdc"
|
||||
end
|
||||
|
||||
build do
|
||||
Environment.new(echo: :command) do |env|
|
||||
env.Program("hello-d.exe", glob("*.d"))
|
||||
|
9
build_tests/d/build-ldc2.rb
Normal file
9
build_tests/d/build-ldc2.rb
Normal file
@ -0,0 +1,9 @@
|
||||
configure do
|
||||
check_d_compiler "ldc2"
|
||||
end
|
||||
|
||||
build do
|
||||
Environment.new(echo: :command) do |env|
|
||||
env.Program("hello-d.exe", glob("*.d"))
|
||||
end
|
||||
end
|
@ -9,7 +9,7 @@ module Rscons
|
||||
def finalize_command_with_depfile
|
||||
deps = @sources
|
||||
if File.exists?(@vars["_DEPFILE"])
|
||||
deps += Util.parse_makefile_deps(@vars["_DEPFILE"])
|
||||
deps += Util.parse_dependency_file(@vars["_DEPFILE"])
|
||||
end
|
||||
@cache.register_build(@target, @command, deps.uniq, @env)
|
||||
true
|
||||
|
@ -479,6 +479,7 @@ module Rscons
|
||||
"DC" => dc,
|
||||
"DCCMD" => env["DCCMD"].map {|e| if e == "-o"; "-of"; else; e; end},
|
||||
"LDCMD" => env["LDCMD"].map {|e| if e == "-o"; "-of"; else; e; end},
|
||||
"DDEPGEN" => ["-deps=${_DEPFILE}"],
|
||||
}
|
||||
end
|
||||
_, _, status = log_and_test_command(command)
|
||||
|
@ -160,7 +160,7 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Parse dependencies from a Makefile.
|
||||
# Parse dependencies from a Makefile or ldc2 dependency file.
|
||||
#
|
||||
# This method is used internally by Rscons builders.
|
||||
#
|
||||
@ -169,7 +169,7 @@ module Rscons
|
||||
#
|
||||
# @return [Array<String>]
|
||||
# Paths of dependency files.
|
||||
def parse_makefile_deps(mf_fname)
|
||||
def parse_dependency_file(mf_fname)
|
||||
deps = []
|
||||
buildup = ''
|
||||
File.read(mf_fname).each_line do |line|
|
||||
@ -177,7 +177,11 @@ module Rscons
|
||||
buildup += ' ' + $1
|
||||
else
|
||||
buildup += ' ' + line
|
||||
if buildup =~ /^.*: (.*)$/
|
||||
if buildup =~ /^[^:]+\(\S+\)\s*:.*?:[^:]+\((\S+)\)/
|
||||
# ldc2-style dependency line
|
||||
deps << $1
|
||||
elsif buildup =~ /^.*: (.*)$/
|
||||
# Makefile-style dependency line
|
||||
mf_deps = $1
|
||||
deps += mf_deps.split(' ').map(&:strip)
|
||||
end
|
||||
|
@ -589,7 +589,7 @@ EOF
|
||||
end
|
||||
|
||||
unless ENV["omit_gdc_tests"]
|
||||
it "supports building D sources" do
|
||||
it "supports building D sources with gdc" do
|
||||
test_dir("d")
|
||||
result = run_rscons
|
||||
expect(result.stderr).to eq ""
|
||||
@ -600,6 +600,39 @@ EOF
|
||||
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
|
||||
end
|
||||
|
||||
it "supports building D sources with ldc2" do
|
||||
test_dir("d")
|
||||
result = run_rscons(rsconscript: "build-ldc2.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
slines = lines(result.stdout)
|
||||
verify_lines(slines, [%r{ldc2 -c -of build/e.1/main.o -deps=build/e.1/main.mf main.d}])
|
||||
verify_lines(slines, [%r{ldc2 -c -of build/e.1/mod.o -deps=build/e.1/mod.mf mod.d}])
|
||||
verify_lines(slines, [%r{ldc2 -of hello-d.exe build/e.1/main.o build/e.1/mod.o}])
|
||||
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
|
||||
end
|
||||
|
||||
it "rebuilds D modules with ldc2 when deep dependencies change" do
|
||||
test_dir("d")
|
||||
result = run_rscons(rsconscript: "build-ldc2.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
slines = lines(result.stdout)
|
||||
verify_lines(slines, [%r{ldc2 -c -of build/e.1/main.o -deps=build/e.1/main.mf main.d}])
|
||||
verify_lines(slines, [%r{ldc2 -c -of build/e.1/mod.o -deps=build/e.1/mod.mf mod.d}])
|
||||
verify_lines(slines, [%r{ldc2 -of hello-d.exe build/e.1/main.o build/e.1/mod.o}])
|
||||
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
|
||||
contents = File.read("mod.d", mode: "rb").sub("42", "33")
|
||||
File.open("mod.d", "wb") do |fh|
|
||||
fh.write(contents)
|
||||
end
|
||||
result = run_rscons(rsconscript: "build-ldc2.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
slines = lines(result.stdout)
|
||||
verify_lines(slines, [%r{ldc2 -c -of build/e.1/main.o -deps=build/e.1/main.mf main.d}])
|
||||
verify_lines(slines, [%r{ldc2 -c -of build/e.1/mod.o -deps=build/e.1/mod.mf mod.d}])
|
||||
verify_lines(slines, [%r{ldc2 -of hello-d.exe build/e.1/main.o build/e.1/mod.o}])
|
||||
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 33!"
|
||||
end
|
||||
|
||||
it "links with the D linker when object files were built from D sources" do
|
||||
test_dir("d")
|
||||
result = run_rscons(rsconscript: "link_objects.rb")
|
||||
|
@ -197,12 +197,12 @@ EOF
|
||||
end
|
||||
end
|
||||
|
||||
describe ".parse_makefile_deps" do
|
||||
describe ".parse_dependency_file" do
|
||||
it 'handles dependencies on one line' do
|
||||
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
||||
module.o: source.cc
|
||||
EOS
|
||||
expect(Util.parse_makefile_deps('makefile')).to eq ['source.cc']
|
||||
expect(Util.parse_dependency_file('makefile')).to eq ['source.cc']
|
||||
end
|
||||
|
||||
it 'handles dependencies split across many lines' do
|
||||
@ -211,9 +211,22 @@ module.o: module.c \\
|
||||
module.h \\
|
||||
other.h
|
||||
EOS
|
||||
expect(Util.parse_makefile_deps('makefile')).to eq [
|
||||
expect(Util.parse_dependency_file('makefile')).to eq [
|
||||
'module.c', 'module.h', 'other.h']
|
||||
end
|
||||
|
||||
it "parses ldc2-style dependency lines" do
|
||||
expect(File).to receive(:read).with("deps.out").and_return(<<EOS)
|
||||
std.traits (/usr/lib/ldc/x86_64-linux-gnu/include/d/std/traits.d) : private : std.meta (/usr/lib/ldc/x86_64-linux-gnu/include/d/std/meta.d):staticIndexOf
|
||||
std.conv (/usr/lib/ldc/x86_64-linux-gnu/include/d/std/conv.d) : private : std.array (/usr/lib/ldc/x86_64-linux-gnu/include/d/std/array.d):array
|
||||
std.stdio (/usr/lib/ldc/x86_64-linux-gnu/include/d/std/stdio.d) : private static : core.sys.posix.sys.socket (/usr/lib/ldc/x86_64-linux-gnu/include/d/core/sys/posix/sys/socket.d) -> sock
|
||||
EOS
|
||||
expect(Util.parse_dependency_file("deps.out")).to eq [
|
||||
"/usr/lib/ldc/x86_64-linux-gnu/include/d/std/meta.d",
|
||||
"/usr/lib/ldc/x86_64-linux-gnu/include/d/std/array.d",
|
||||
"/usr/lib/ldc/x86_64-linux-gnu/include/d/core/sys/posix/sys/socket.d",
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user