fix PROGSUFFIX handling - close #29

This commit is contained in:
Josh Holtrop 2017-05-29 11:40:01 -04:00
parent d31b4725d2
commit 1880e6650e
6 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1,4 @@
Rscons::Environment.new do |env|
env["MYSUFFIX"] = ".out"
env.Program("simple${MYSUFFIX}", Dir["*.c"])
end

View File

@ -0,0 +1,3 @@
Rscons::Environment.new do |env|
env.Program("simple", Dir["*.c"], "PROGSUFFIX" => ".xyz")
end

View File

@ -36,6 +36,8 @@ module Rscons
# The user-supplied target name. # The user-supplied target name.
# @option options [Array<String>] :sources # @option options [Array<String>] :sources
# The user-supplied source file name(s). # The user-supplied source file name(s).
# @option options [Hash,VarSet] :vars
# Extra construction variables.
# #
# @return [BuildTarget] # @return [BuildTarget]
def create_build_target(options) def create_build_target(options)

View File

@ -39,9 +39,10 @@ module Rscons
# #
# @return [BuildTarget] # @return [BuildTarget]
def create_build_target(options) def create_build_target(options)
env, target, vars = options.values_at(:env, :target, :vars)
my_options = options.dup my_options = options.dup
unless my_options[:target] =~ /\./ unless env.expand_varref(target, vars) =~ /\./
my_options[:target] += options[:env].expand_varref("${PROGSUFFIX}") my_options[:target] += env.expand_varref("${PROGSUFFIX}", vars)
end end
super(my_options) super(my_options)
end end

View File

@ -409,7 +409,7 @@ module Rscons
end end
sources = Array(sources) sources = Array(sources)
builder = @builders[method.to_s] builder = @builders[method.to_s]
build_target = builder.create_build_target(env: self, target: target, sources: sources) build_target = builder.create_build_target(env: self, target: target, sources: sources, vars: vars)
add_target(build_target.to_s, builder, sources, vars || {}, rest) add_target(build_target.to_s, builder, sources, vars || {}, rest)
build_target build_target
else else

View File

@ -632,7 +632,7 @@ EOF
] ]
end end
it "allows overriding progsuffix" do it "allows overriding PROGSUFFIX" do
test_dir("simple") test_dir("simple")
result = run_test(rsconsfile: "progsuffix.rb") result = run_test(rsconsfile: "progsuffix.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
@ -642,6 +642,26 @@ EOF
] ]
end end
it "does not use PROGSUFFIX when the Program target name expands to a value already containing an extension" do
test_dir("simple")
result = run_test(rsconsfile: "progsuffix2.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
"CC simple.o",
"LD simple.out",
]
end
it "allows overriding PROGSUFFIX from extra vars passed in to the builder" do
test_dir("simple")
result = run_test(rsconsfile: "progsuffix3.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [
"CC simple.o",
"LD simple.xyz",
]
end
context "backward compatibility" do context "backward compatibility" do
it "allows a builder to call Environment#run_builder in a non-threaded manner" do it "allows a builder to call Environment#run_builder in a non-threaded manner" do
test_dir("simple") test_dir("simple")