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
|
class BasicEnvironment
|
||||||
|
|
||||||
# Create a BasicEnvironment object.
|
# Create a BasicEnvironment object.
|
||||||
def initialize
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
# @param options [Hash]
|
||||||
|
# Construction options.
|
||||||
|
def initialize(options = {})
|
||||||
@varset = VarSet.new(Rscons.application.default_varset)
|
@varset = VarSet.new(Rscons.application.default_varset)
|
||||||
|
load_configuration_data!(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a construction variable's value.
|
# Get a construction variable's value.
|
||||||
@ -185,15 +191,24 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load construction variables saved from the configure operation.
|
# Load all construction variables saved from the configure operation.
|
||||||
def load_configuration_data!
|
def load_configuration_data!(options)
|
||||||
if vars = Cache.instance.configuration_data["vars"]
|
if vars = Cache.instance.configuration_data["vars"]
|
||||||
if default_vars = vars["_default_"]
|
if default_vars = vars["_default_"]
|
||||||
apply_configuration_data!(default_vars)
|
apply_configuration_data!(default_vars)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Load a specific set of construction variables saved from the configure
|
||||||
|
# operation.
|
||||||
def apply_configuration_data!(vars)
|
def apply_configuration_data!(vars)
|
||||||
if merge_vars = vars["merge"]
|
if merge_vars = vars["merge"]
|
||||||
append(merge_vars)
|
append(merge_vars)
|
||||||
|
@ -360,7 +360,12 @@ module Rscons
|
|||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
# Configuration Hash for storing vars.
|
# Configuration Hash for storing vars.
|
||||||
def store_common(options)
|
def store_common(options)
|
||||||
usename = options[:use] || "_default_"
|
usename =
|
||||||
|
if options[:use]
|
||||||
|
options[:use].to_s
|
||||||
|
else
|
||||||
|
"_default_"
|
||||||
|
end
|
||||||
cache = Cache.instance
|
cache = Cache.instance
|
||||||
cache.configuration_data["vars"] ||= {}
|
cache.configuration_data["vars"] ||= {}
|
||||||
cache.configuration_data["vars"][usename] ||= {}
|
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
|
# If a block is given, the Environment object is yielded to the block and
|
||||||
# when the block returns, the {#process} method is automatically called.
|
# when the block returns, the {#process} method is automatically called.
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
super()
|
super(options)
|
||||||
@id = self.class.get_id
|
@id = self.class.get_id
|
||||||
self.class.register(self)
|
self.class.register(self)
|
||||||
@threaded_commands = Set.new
|
@threaded_commands = Set.new
|
||||||
@ -83,7 +83,6 @@ module Rscons
|
|||||||
end
|
end
|
||||||
@echo = options[:echo] || :short
|
@echo = options[:echo] || :short
|
||||||
@build_root = "#{Cache.instance.configuration_data["build_dir"]}/e.#{@id}"
|
@build_root = "#{Cache.instance.configuration_data["build_dir"]}/e.#{@id}"
|
||||||
load_configuration_data!
|
|
||||||
|
|
||||||
if block_given?
|
if block_given?
|
||||||
yield self
|
yield self
|
||||||
|
@ -1782,6 +1782,16 @@ EOF
|
|||||||
expect(result.stdout).to match /Checking for library 'm'... found/
|
expect(result.stdout).to match /Checking for library 'm'... found/
|
||||||
expect(result.stdout).to match /gcc.*-lm/
|
expect(result.stdout).to match /gcc.*-lm/
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "check_program" do
|
context "check_program" do
|
||||||
@ -1832,6 +1842,20 @@ EOF
|
|||||||
expect(result.status).to_not eq 0
|
expect(result.status).to_not eq 0
|
||||||
expect(result.stdout).to match /Checking 'my-config'\.\.\. not found/
|
expect(result.stdout).to match /Checking 'my-config'\.\.\. not found/
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "when passed a program" do
|
context "when passed a program" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user