generate dependencies for D builds - close #49

This commit is contained in:
Josh Holtrop 2018-08-22 15:23:48 -04:00
parent dbbce9e476
commit 8cb02a7e34
6 changed files with 56 additions and 30 deletions

View File

@ -1,3 +1,3 @@
Rscons::Environment.new(echo: :command) do |env|
env.Program("hello-d.exe", Dir["*.d"])
env.Program("hello-d.exe", Dir["*.d"].sort)
end

View File

@ -1,6 +1,7 @@
import std.stdio;
import mod;
void main()
{
writeln("Hello from D!");
writeln("Hello from D, value is ", Klass.VAL, "!");
}

4
build_tests/d/mod.d Normal file
View File

@ -0,0 +1,4 @@
class Klass
{
enum VAL = 42;
};

View File

@ -30,7 +30,7 @@ module Rscons
'ASSUFFIX' => ['.S'],
'ASPPPATH' => '${CPPPATH}',
'ASPPFLAGS' => '${CPPFLAGS}',
'ASDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
'ASDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}', '-MT', 'TARGET'],
'ASCMD' => ['${AS}', '-c', '-o', '${_TARGET}', '${ASDEPGEN}', '${INCPREFIX}${ASPPPATH}', '${ASPPFLAGS}', '${ASFLAGS}', '${_SOURCES}'],
'CPPFLAGS' => ['${CPPDEFPREFIX}${CPPDEFINES}'],
@ -42,20 +42,21 @@ module Rscons
'CC' => 'gcc',
'CFLAGS' => [],
'CSUFFIX' => ['.c'],
'CCDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
'CCDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}', '-MT', 'TARGET'],
'CCCMD' => ['${CC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '${INCPREFIX}${CPPPATH}', '${CPPFLAGS}', '${CFLAGS}', '${CCFLAGS}', '${_SOURCES}'],
'CXX' => 'g++',
'CXXFLAGS' => [],
'CXXSUFFIX' => ['.cc', '.cpp', '.cxx', '.C'],
'CXXDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
'CXXDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}', '-MT', 'TARGET'],
'CXXCMD' =>['${CXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '${INCPREFIX}${CPPPATH}', '${CPPFLAGS}', '${CXXFLAGS}', '${CCFLAGS}', '${_SOURCES}'],
'DC' => 'gdc',
'DFLAGS' => [],
'DSUFFIX' => ['.d'],
'DDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}', '-MT', 'TARGET'],
'D_IMPORT_PATH' => [],
'DCCMD' => ['${DC}', '-c', '-o', '${_TARGET}', '${INCPREFIX}${D_IMPORT_PATH}', '${DFLAGS}', '${_SOURCES}'],
'DCCMD' => ['${DC}', '-c', '-o', '${_TARGET}', '${DDEPGEN}', '${INCPREFIX}${D_IMPORT_PATH}', '${DFLAGS}', '${_SOURCES}'],
}
end
@ -114,7 +115,7 @@ module Rscons
if options[:command_status]
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
if File.exists?(vars['_DEPFILE'])
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], 'TARGET')
FileUtils.rm_f(vars['_DEPFILE'])
end
cache.register_build(target, options[:tc].command, deps.uniq, env)

View File

@ -100,7 +100,7 @@ module Rscons
if options[:command_status]
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
if File.exists?(vars['_DEPFILE'])
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], 'TARGET')
FileUtils.rm_f(vars['_DEPFILE'])
end
cache.register_build(target, options[:tc].command, deps.uniq, env)

View File

@ -125,7 +125,7 @@ EOF
result = run_test(rsconsfile: "command.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
'gcc -c -o build/simple.o -MMD -MF build/simple.mf simple.c',
'gcc -c -o build/simple.o -MMD -MF build/simple.mf -MT TARGET simple.c',
"gcc -o simple.exe build/simple.o",
]
end
@ -194,7 +194,7 @@ EOF
result = run_test(rsconsfile: "command.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
'gcc -c -o build/simple.o -MMD -MF build/simple.mf simple.c',
'gcc -c -o build/simple.o -MMD -MF build/simple.mf -MT TARGET simple.c',
"gcc -o simple.exe build/simple.o",
]
result = run_test(rsconsfile: "link_flag_change.rb")
@ -249,8 +249,8 @@ EOF
result = run_test(rsconsfile: "carat.rb")
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
%q{gcc -c -o build_root/one.o -MMD -MF build_root/one.mf -Isrc/one/ -Isrc/two/ build_root/one.c},
%q{gcc -c -o build_root/src/two/two.o -MMD -MF build_root/src/two/two.mf -Isrc/one/ -Isrc/two/ src/two/two.c},
%q{gcc -c -o build_root/one.o -MMD -MF build_root/one.mf -MT TARGET -Isrc/one/ -Isrc/two/ build_root/one.c},
%q{gcc -c -o build_root/src/two/two.o -MMD -MF build_root/src/two/two.mf -MT TARGET -Isrc/one/ -Isrc/two/ src/two/two.c},
%Q{gcc -o build_dir.exe build_root/src/two/two.o build_root/one.o},
]
end
@ -329,9 +329,9 @@ EOF
result = run_test
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
%q{gcc -c -o debug/program.o -MMD -MF debug/program.mf '-DSTRING="Debug Version"' -O2 src/program.c},
%q{gcc -c -o debug/program.o -MMD -MF debug/program.mf -MT TARGET '-DSTRING="Debug Version"' -O2 src/program.c},
%Q{gcc -o program-debug.exe debug/program.o},
%q{gcc -c -o release/program.o -MMD -MF release/program.mf '-DSTRING="Release Version"' -O2 src/program.c},
%q{gcc -c -o release/program.o -MMD -MF release/program.mf -MT TARGET '-DSTRING="Release Version"' -O2 src/program.c},
%Q{gcc -o program-release.exe release/program.o},
]
end
@ -341,7 +341,7 @@ EOF
result = run_test(rsconsfile: "clone_all.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
%q{gcc -c -o build/program.o -MMD -MF build/program.mf -DSTRING="Hello" -O2 src/program.c},
%q{gcc -c -o build/program.o -MMD -MF build/program.mf -MT TARGET -DSTRING="Hello" -O2 src/program.c},
%q{post build/program.o},
%Q{gcc -o program.exe build/program.o},
%q{post program.exe},
@ -364,8 +364,8 @@ EOF
result = run_test
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
'gcc -c -o one.o -MMD -MF one.mf -DONE one.c',
'gcc -c -o build/two.o -MMD -MF build/two.mf two.c',
'gcc -c -o one.o -MMD -MF one.mf -MT TARGET -DONE one.c',
'gcc -c -o build/two.o -MMD -MF build/two.mf -MT TARGET two.c',
"gcc -o two_sources.exe one.o build/two.o",
]
expect(File.exists?("two_sources.exe")).to be_truthy
@ -377,10 +377,10 @@ EOF
result = run_test
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
'gcc -c -o build/one.o -MMD -MF build/one.mf -Dmake_lib one.c',
'gcc -c -o build/two.o -MMD -MF build/two.mf -Dmake_lib two.c',
'gcc -c -o build/one.o -MMD -MF build/one.mf -MT TARGET -Dmake_lib one.c',
'gcc -c -o build/two.o -MMD -MF build/two.mf -MT TARGET -Dmake_lib two.c',
'ar rcs lib.a build/one.o build/two.o',
'gcc -c -o build/three.o -MMD -MF build/three.mf three.c',
'gcc -c -o build/three.o -MMD -MF build/three.mf -MT TARGET three.c',
"gcc -o library.exe lib.a build/three.o",
]
expect(File.exists?("library.exe")).to be_truthy
@ -392,8 +392,8 @@ EOF
result = run_test(rsconsfile: "build_hooks.rb")
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -Isrc/one/ -Isrc/two/ -O1 src/one/one.c',
'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -Isrc/one/ -Isrc/two/ -O2 src/two/two.c',
'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O1 src/one/one.c',
'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O2 src/two/two.c',
'gcc -o build_hook.exe build_one/one.o build_two/two.o',
]
expect(`./build_hook.exe`).to eq "Hello from two()\n"
@ -429,11 +429,31 @@ EOF
test_dir("d")
result = run_test
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
"gdc -c -o build/main.o main.d",
"gdc -o hello-d.exe build/main.o",
]
expect(`./hello-d.exe`.rstrip).to eq "Hello from D!"
slines = lines(result.stdout)
expect(slines).to include("gdc -c -o build/main.o -MMD -MF build/main.mf -MT TARGET main.d")
expect(slines).to include("gdc -c -o build/mod.o -MMD -MF build/mod.mf -MT TARGET mod.d")
expect(slines.last).to eq("gdc -o hello-d.exe build/main.o build/mod.o")
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
end
it "does dependency generation for D sources" do
test_dir("d")
result = run_test
expect(result.stderr).to eq ""
slines = lines(result.stdout)
expect(slines).to include("gdc -c -o build/main.o -MMD -MF build/main.mf -MT TARGET main.d")
expect(slines).to include("gdc -c -o build/mod.o -MMD -MF build/mod.mf -MT TARGET mod.d")
expect(slines.last).to eq("gdc -o hello-d.exe build/main.o build/mod.o")
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
fcontents = File.read("mod.d", mode: "rb").sub("42", "33")
File.open("mod.d", "wb") {|fh| fh.write(fcontents)}
result = run_test
expect(result.stderr).to eq ""
slines = lines(result.stdout)
expect(slines).to include("gdc -c -o build/main.o -MMD -MF build/main.mf -MT TARGET main.d")
expect(slines).to include("gdc -c -o build/mod.o -MMD -MF build/mod.mf -MT TARGET mod.d")
expect(slines.last).to eq("gdc -o hello-d.exe build/main.o build/mod.o")
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 33!"
end
it "creates shared libraries using D" do
@ -873,8 +893,8 @@ EOF
result = run_test(rsconsfile: "backward_compatible_build_hooks.rb")
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
'gcc -c -o one.o -MMD -MF one.mf -Isrc/one/ -Isrc/two/ -O1 src/two/two.c',
'gcc -c -o two.o -MMD -MF two.mf -Isrc/one/ -Isrc/two/ -O2 src/two/two.c'
'gcc -c -o one.o -MMD -MF one.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O1 src/two/two.c',
'gcc -c -o two.o -MMD -MF two.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O2 src/two/two.c'
]
expect(File.exists?('one.o')).to be_truthy
expect(File.exists?('two.o')).to be_truthy
@ -1258,7 +1278,7 @@ EOF
result = run_test(rsconsfile: "override_depfilesuffix.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
"gcc -c -o simple.o -MMD -MF simple.deppy simple.c",
"gcc -c -o simple.o -MMD -MF simple.deppy -MT TARGET simple.c",
]
end