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
|
build do
|
||||||
Environment.new(echo: :command) do |env|
|
Environment.new(echo: :command) do |env|
|
||||||
env.Program("hello-d.exe", glob("*.d"))
|
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
|
def finalize_command_with_depfile
|
||||||
deps = @sources
|
deps = @sources
|
||||||
if File.exists?(@vars["_DEPFILE"])
|
if File.exists?(@vars["_DEPFILE"])
|
||||||
deps += Util.parse_makefile_deps(@vars["_DEPFILE"])
|
deps += Util.parse_dependency_file(@vars["_DEPFILE"])
|
||||||
end
|
end
|
||||||
@cache.register_build(@target, @command, deps.uniq, @env)
|
@cache.register_build(@target, @command, deps.uniq, @env)
|
||||||
true
|
true
|
||||||
|
@ -479,6 +479,7 @@ module Rscons
|
|||||||
"DC" => dc,
|
"DC" => dc,
|
||||||
"DCCMD" => env["DCCMD"].map {|e| if e == "-o"; "-of"; else; e; end},
|
"DCCMD" => env["DCCMD"].map {|e| if e == "-o"; "-of"; else; e; end},
|
||||||
"LDCMD" => env["LDCMD"].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
|
end
|
||||||
_, _, status = log_and_test_command(command)
|
_, _, status = log_and_test_command(command)
|
||||||
|
@ -160,7 +160,7 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse dependencies from a Makefile.
|
# Parse dependencies from a Makefile or ldc2 dependency file.
|
||||||
#
|
#
|
||||||
# This method is used internally by Rscons builders.
|
# This method is used internally by Rscons builders.
|
||||||
#
|
#
|
||||||
@ -169,7 +169,7 @@ module Rscons
|
|||||||
#
|
#
|
||||||
# @return [Array<String>]
|
# @return [Array<String>]
|
||||||
# Paths of dependency files.
|
# Paths of dependency files.
|
||||||
def parse_makefile_deps(mf_fname)
|
def parse_dependency_file(mf_fname)
|
||||||
deps = []
|
deps = []
|
||||||
buildup = ''
|
buildup = ''
|
||||||
File.read(mf_fname).each_line do |line|
|
File.read(mf_fname).each_line do |line|
|
||||||
@ -177,7 +177,11 @@ module Rscons
|
|||||||
buildup += ' ' + $1
|
buildup += ' ' + $1
|
||||||
else
|
else
|
||||||
buildup += ' ' + line
|
buildup += ' ' + line
|
||||||
if buildup =~ /^.*: (.*)$/
|
if buildup =~ /^[^:]+\(\S+\)\s*:.*?:[^:]+\((\S+)\)/
|
||||||
|
# ldc2-style dependency line
|
||||||
|
deps << $1
|
||||||
|
elsif buildup =~ /^.*: (.*)$/
|
||||||
|
# Makefile-style dependency line
|
||||||
mf_deps = $1
|
mf_deps = $1
|
||||||
deps += mf_deps.split(' ').map(&:strip)
|
deps += mf_deps.split(' ').map(&:strip)
|
||||||
end
|
end
|
||||||
|
@ -589,7 +589,7 @@ EOF
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless ENV["omit_gdc_tests"]
|
unless ENV["omit_gdc_tests"]
|
||||||
it "supports building D sources" do
|
it "supports building D sources with gdc" do
|
||||||
test_dir("d")
|
test_dir("d")
|
||||||
result = run_rscons
|
result = run_rscons
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
@ -600,6 +600,39 @@ EOF
|
|||||||
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
|
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
|
||||||
end
|
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
|
it "links with the D linker when object files were built from D sources" do
|
||||||
test_dir("d")
|
test_dir("d")
|
||||||
result = run_rscons(rsconscript: "link_objects.rb")
|
result = run_rscons(rsconscript: "link_objects.rb")
|
||||||
|
@ -197,12 +197,12 @@ EOF
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".parse_makefile_deps" do
|
describe ".parse_dependency_file" do
|
||||||
it 'handles dependencies on one line' do
|
it 'handles dependencies on one line' do
|
||||||
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
||||||
module.o: source.cc
|
module.o: source.cc
|
||||||
EOS
|
EOS
|
||||||
expect(Util.parse_makefile_deps('makefile')).to eq ['source.cc']
|
expect(Util.parse_dependency_file('makefile')).to eq ['source.cc']
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles dependencies split across many lines' do
|
it 'handles dependencies split across many lines' do
|
||||||
@ -211,9 +211,22 @@ module.o: module.c \\
|
|||||||
module.h \\
|
module.h \\
|
||||||
other.h
|
other.h
|
||||||
EOS
|
EOS
|
||||||
expect(Util.parse_makefile_deps('makefile')).to eq [
|
expect(Util.parse_dependency_file('makefile')).to eq [
|
||||||
'module.c', 'module.h', 'other.h']
|
'module.c', 'module.h', 'other.h']
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user