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/cache"
|
||||
require "rscons/environment"
|
||||
require "rscons/varset"
|
||||
require "rscons/version"
|
||||
|
||||
require "rscons/monkey/module"
|
||||
|
@ -11,7 +11,7 @@ module Rscons
|
||||
# uppercase strings (such as "CC" or "LDFLAGS"), and rscons options,
|
||||
# which are lowercase symbols (such as :echo).
|
||||
def initialize(variables = {})
|
||||
@variables = variables
|
||||
@variables = VarSet.new(variables)
|
||||
@targets = {}
|
||||
@builders = {}
|
||||
@variables[:exclude_builders] ||= []
|
||||
@ -44,19 +44,12 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
def [](key, type = nil)
|
||||
val = @variables[key]
|
||||
if type == :array and val.is_a?(String)
|
||||
[val]
|
||||
elsif type == :string and val.is_a?(Array)
|
||||
val.first
|
||||
else
|
||||
val
|
||||
end
|
||||
def [](*args)
|
||||
@variables.send(:[], *args)
|
||||
end
|
||||
|
||||
def []=(key, val)
|
||||
@variables[key] = val
|
||||
def []=(*args)
|
||||
@variables.send(:[]=, *args)
|
||||
end
|
||||
|
||||
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