mirror of
https://github.com/boostorg/build.git
synced 2026-02-12 12:02:24 +00:00
New 'configuration' class, for storing all auto-detected configuration of
tools. Patch from Alexey Pakhunov. [SVN r31078]
This commit is contained in:
@@ -18,6 +18,109 @@ import sequence ;
|
||||
import toolset ;
|
||||
|
||||
|
||||
# Configurations
|
||||
#
|
||||
# The following class helps to manage toolset configurations. Each configuration
|
||||
# has unique ID and one or more parameters. A typical example of unique ID is
|
||||
# a condition generated by 'common.check-init-parameters' rule. Other kinds of
|
||||
# ID can be used. Parameters may include any details about the configuration like
|
||||
# 'command', 'path', etc.
|
||||
#
|
||||
# A configuration may be in one of two states:
|
||||
#
|
||||
# - registered - a toolset configuration is registered (by autodetection code
|
||||
# for instance) but is not used. I.e. 'toolset.using' wasn't yet been called
|
||||
# for this configuration.
|
||||
# - used - once called 'toolset.using' marks the configuration as 'used'.
|
||||
#
|
||||
# The main difference between the states is that while a configuration is
|
||||
# 'registered' its options can be freely changed. This is useful in particular
|
||||
# for autodetection code - all detected configurations may be safely overwritten
|
||||
# by a user.
|
||||
|
||||
class configurations
|
||||
{
|
||||
import errors : error ;
|
||||
|
||||
rule __init__ ( )
|
||||
{
|
||||
}
|
||||
|
||||
# Registers a configuration.
|
||||
#
|
||||
# Returns 'true' if the configuration has been added and an empty value if
|
||||
# it already exists. Reports an error if the configuration is 'used'.
|
||||
rule register ( id )
|
||||
{
|
||||
if $(id) in $(self.used)
|
||||
{
|
||||
error "common: the configuration '$(id)' is in use" ;
|
||||
}
|
||||
|
||||
local retval ;
|
||||
|
||||
if ! $(id) in $(self.all)
|
||||
{
|
||||
self.all += $(id) ;
|
||||
|
||||
# indicate that a new configuration has been added
|
||||
retval = true ;
|
||||
}
|
||||
|
||||
return $(retval) ;
|
||||
}
|
||||
|
||||
# Mark a configuration as 'used'.
|
||||
#
|
||||
# Returns 'true' if the state of the configuration has been changed to
|
||||
# 'used' and an empty value if it the state wasn't changed. Reports an error
|
||||
# if the configuration isn't known.
|
||||
rule use ( id )
|
||||
{
|
||||
if ! $(id) in $(self.all)
|
||||
{
|
||||
error "common: the configuration '$(id)' is not known" ;
|
||||
}
|
||||
|
||||
local retval ;
|
||||
|
||||
if ! $(id) in $(self.used)
|
||||
{
|
||||
self.used += $(id) ;
|
||||
|
||||
# indicate that the configuration has been marked as 'used'
|
||||
retval = true ;
|
||||
}
|
||||
|
||||
return $(retval) ;
|
||||
}
|
||||
|
||||
# Return all registered configurations.
|
||||
rule all ( )
|
||||
{
|
||||
return $(self.all) ;
|
||||
}
|
||||
|
||||
# Return all used configurations.
|
||||
rule used ( )
|
||||
{
|
||||
return $(self.used) ;
|
||||
}
|
||||
|
||||
# Returns the value of a configuration parameter.
|
||||
rule get ( id : param )
|
||||
{
|
||||
return $(self.$(param).$(id)) ;
|
||||
}
|
||||
|
||||
# Sets the value of a configuration parameter.
|
||||
rule set ( id : param : value * )
|
||||
{
|
||||
self.$(param).$(id) = $(value) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# The rule checks toolset parameters. Each trailing parameter
|
||||
# should be a pair of parameter name and parameter value.
|
||||
# The rule will check that each parameter either has value in
|
||||
|
||||
Reference in New Issue
Block a user