add VarSet class to keep track of construction variables

This commit is contained in:
Josh Holtrop 2013-07-10 17:18:33 -04:00
parent bbdd6e930f
commit ff822155ea
3 changed files with 35 additions and 12 deletions

View File

@ -1,6 +1,7 @@
require "rscons/builder"
require "rscons/cache"
require "rscons/environment"
require "rscons/varset"
require "rscons/version"
require "rscons/monkey/module"

View File

@ -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
View 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