Place object files next to source files for source files in build directory - close #171

This commit is contained in:
Josh Holtrop 2023-09-10 10:00:41 -04:00
parent 3867133e89
commit 6a8647a933
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,13 @@
env("e", echo: :command) do |env|
source_file = "#{env.build_root}/src/foo.c"
FileUtils.mkdir_p(File.dirname(source_file))
File.open(source_file, "w") do |fh|
fh.puts(<<-EOF)
int main()
{
return 29;
}
EOF
end
env.Program("foo.exe", source_file)
end

View File

@ -277,7 +277,15 @@ module Rscons
if extra_path = builder_class.extra_path if extra_path = builder_class.extra_path
extra_path = "/#{extra_path}" extra_path = "/#{extra_path}"
end end
"#{@build_root}/o#{extra_path}/#{Util.make_relative_path("#{source_fname}#{suffix}")}".gsub("\\", "/") source_fname = source_fname.gsub("\\", "/")
if extra_path.nil? && source_fname.start_with?("#{@build_root}/")
# If the source file is in the environment's build directory and no
# builder "extra path" is present, then just place the output file
# next to the source file.
"#{source_fname}#{suffix}"
else
"#{@build_root}/o#{extra_path}/#{Util.make_relative_path("#{source_fname}#{suffix}")}"
end
end end
# Build all build targets specified in the Environment. # Build all build targets specified in the Environment.

View File

@ -990,6 +990,14 @@ EOF
verify_lines(slines, [%r{\babs.exe\b}]) verify_lines(slines, [%r{\babs.exe\b}])
end end
it "creates object files next to the source file for source files in the build root" do
test_dir "simple"
result = run_rscons(args: %w[-f build_root_source_path.rb])
expect(result.stderr).to eq ""
expect(File.exist?("build/e/o/build/e/src/foo.c.o")).to be_falsey
expect(File.exist?("build/e/src/foo.c.o")).to be_truthy
end
it "creates shared libraries" do it "creates shared libraries" do
test_dir("shared_library") test_dir("shared_library")