provide Environment construction option to use stored configuration settings - close #78
This commit is contained in:
parent
fa5aa51daa
commit
eaac473f44
15
build_tests/configure/check_cfg_use.rb
Normal file
15
build_tests/configure/check_cfg_use.rb
Normal file
@ -0,0 +1,15 @@
|
||||
configure do
|
||||
check_cfg package: "mypackage", use: "myp"
|
||||
end
|
||||
|
||||
build do
|
||||
Environment.new(echo: :command) do |env|
|
||||
env.Copy("myconfigtest1.c", "simple.c")
|
||||
env.Program("myconfigtest1.exe", "myconfigtest1.c")
|
||||
end
|
||||
|
||||
Environment.new(echo: :command, use: "myp") do |env|
|
||||
env.Copy("myconfigtest2.c", "simple.c")
|
||||
env.Program("myconfigtest2.exe", "myconfigtest2.c")
|
||||
end
|
||||
end
|
15
build_tests/configure/check_lib_use.rb
Normal file
15
build_tests/configure/check_lib_use.rb
Normal file
@ -0,0 +1,15 @@
|
||||
configure do
|
||||
check_lib "m", use: :m
|
||||
end
|
||||
|
||||
build do
|
||||
Environment.new(echo: :command) do |env|
|
||||
env.Copy("test1.c", "simple.c")
|
||||
env.Program("test2.exe", "test1.c")
|
||||
end
|
||||
|
||||
Environment.new(echo: :command, use: %w[m]) do |env|
|
||||
env.Copy("test2.c", "simple.c")
|
||||
env.Program("test2.exe", "test2.c")
|
||||
end
|
||||
end
|
@ -3,8 +3,14 @@ module Rscons
|
||||
class BasicEnvironment
|
||||
|
||||
# Create a BasicEnvironment object.
|
||||
def initialize
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
# @param options [Hash]
|
||||
# Construction options.
|
||||
def initialize(options = {})
|
||||
@varset = VarSet.new(Rscons.application.default_varset)
|
||||
load_configuration_data!(options)
|
||||
end
|
||||
|
||||
# Get a construction variable's value.
|
||||
@ -185,15 +191,24 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Load construction variables saved from the configure operation.
|
||||
def load_configuration_data!
|
||||
# Load all construction variables saved from the configure operation.
|
||||
def load_configuration_data!(options)
|
||||
if vars = Cache.instance.configuration_data["vars"]
|
||||
if default_vars = vars["_default_"]
|
||||
apply_configuration_data!(default_vars)
|
||||
end
|
||||
if options[:use]
|
||||
Array(options[:use]).each do |use|
|
||||
if use_vars = vars[use]
|
||||
apply_configuration_data!(use_vars)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Load a specific set of construction variables saved from the configure
|
||||
# operation.
|
||||
def apply_configuration_data!(vars)
|
||||
if merge_vars = vars["merge"]
|
||||
append(merge_vars)
|
||||
|
@ -360,7 +360,12 @@ module Rscons
|
||||
# @return [Hash]
|
||||
# Configuration Hash for storing vars.
|
||||
def store_common(options)
|
||||
usename = options[:use] || "_default_"
|
||||
usename =
|
||||
if options[:use]
|
||||
options[:use].to_s
|
||||
else
|
||||
"_default_"
|
||||
end
|
||||
cache = Cache.instance
|
||||
cache.configuration_data["vars"] ||= {}
|
||||
cache.configuration_data["vars"][usename] ||= {}
|
||||
|
@ -64,7 +64,7 @@ module Rscons
|
||||
# If a block is given, the Environment object is yielded to the block and
|
||||
# when the block returns, the {#process} method is automatically called.
|
||||
def initialize(options = {})
|
||||
super()
|
||||
super(options)
|
||||
@id = self.class.get_id
|
||||
self.class.register(self)
|
||||
@threaded_commands = Set.new
|
||||
@ -83,7 +83,6 @@ module Rscons
|
||||
end
|
||||
@echo = options[:echo] || :short
|
||||
@build_root = "#{Cache.instance.configuration_data["build_dir"]}/e.#{@id}"
|
||||
load_configuration_data!
|
||||
|
||||
if block_given?
|
||||
yield self
|
||||
|
@ -1782,6 +1782,16 @@ EOF
|
||||
expect(result.stdout).to match /Checking for library 'm'... found/
|
||||
expect(result.stdout).to match /gcc.*-lm/
|
||||
end
|
||||
|
||||
it "does not link against the checked library by default if :use is specified" do
|
||||
test_dir "configure"
|
||||
result = run_rscons(rsconscript: "check_lib_use.rb", op: "build")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /Checking for library 'm'... found/
|
||||
expect(result.stdout).to_not match /gcc.*test1.*-lm/
|
||||
expect(result.stdout).to match /gcc.*test2.*-lm/
|
||||
end
|
||||
end
|
||||
|
||||
context "check_program" do
|
||||
@ -1832,6 +1842,20 @@ EOF
|
||||
expect(result.status).to_not eq 0
|
||||
expect(result.stdout).to match /Checking 'my-config'\.\.\. not found/
|
||||
end
|
||||
|
||||
it "does not use the flags found by default if :use is specified" do
|
||||
test_dir "configure"
|
||||
create_exe "pkg-config", "echo '-DMYPACKAGE'"
|
||||
result = run_rscons(rsconscript: "check_cfg_use.rb", op: "configure")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /Checking for package 'mypackage'\.\.\. found/
|
||||
result = run_rscons(rsconscript: "check_cfg_use.rb", op: "build")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to_not match /gcc.*-o.*myconfigtest1.*-DMYPACKAGE/
|
||||
expect(result.stdout).to match /gcc.*-o.*myconfigtest2.*-DMYPACKAGE/
|
||||
end
|
||||
end
|
||||
|
||||
context "when passed a program" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user