add VarSet class to keep track of construction variables
This commit is contained in:
parent
bbdd6e930f
commit
ff822155ea
@ -1,6 +1,7 @@
|
|||||||
require "rscons/builder"
|
require "rscons/builder"
|
||||||
require "rscons/cache"
|
require "rscons/cache"
|
||||||
require "rscons/environment"
|
require "rscons/environment"
|
||||||
|
require "rscons/varset"
|
||||||
require "rscons/version"
|
require "rscons/version"
|
||||||
|
|
||||||
require "rscons/monkey/module"
|
require "rscons/monkey/module"
|
||||||
|
@ -11,7 +11,7 @@ module Rscons
|
|||||||
# uppercase strings (such as "CC" or "LDFLAGS"), and rscons options,
|
# uppercase strings (such as "CC" or "LDFLAGS"), and rscons options,
|
||||||
# which are lowercase symbols (such as :echo).
|
# which are lowercase symbols (such as :echo).
|
||||||
def initialize(variables = {})
|
def initialize(variables = {})
|
||||||
@variables = variables
|
@variables = VarSet.new(variables)
|
||||||
@targets = {}
|
@targets = {}
|
||||||
@builders = {}
|
@builders = {}
|
||||||
@variables[:exclude_builders] ||= []
|
@variables[:exclude_builders] ||= []
|
||||||
@ -44,19 +44,12 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](key, type = nil)
|
def [](*args)
|
||||||
val = @variables[key]
|
@variables.send(:[], *args)
|
||||||
if type == :array and val.is_a?(String)
|
|
||||||
[val]
|
|
||||||
elsif type == :string and val.is_a?(Array)
|
|
||||||
val.first
|
|
||||||
else
|
|
||||||
val
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def []=(key, val)
|
def []=(*args)
|
||||||
@variables[key] = val
|
@variables.send(:[]=, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process
|
def process
|
||||||
|
29
lib/rscons/varset.rb
Normal file
29
lib/rscons/varset.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
module Rscons
|
||||||
|
class VarSet
|
||||||
|
attr_reader :vars
|
||||||
|
|
||||||
|
def initialize(vars = {})
|
||||||
|
@vars = vars
|
||||||
|
end
|
||||||
|
|
||||||
|
def [](key, type = nil)
|
||||||
|
val = @vars[key]
|
||||||
|
if type == :array and val.is_a?(String)
|
||||||
|
[val]
|
||||||
|
elsif type == :string and val.is_a?(Array)
|
||||||
|
val.first
|
||||||
|
else
|
||||||
|
val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def []=(key, val)
|
||||||
|
@vars[key] = val
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge(other)
|
||||||
|
other = other.vars if other.is_a?(VarSet)
|
||||||
|
VarSet.new(@vars.merge(other))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user