From cc250ac504f594d409c67e0175fa8703ad262f19 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Thu, 22 Sep 2005 13:57:23 +0000 Subject: [PATCH] New 'configuration' class, for storing all auto-detected configuration of tools. Patch from Alexey Pakhunov. [SVN r31078] --- src/tools/common.jam | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/src/tools/common.jam b/src/tools/common.jam index 840aec3f2..7112be911 100644 --- a/src/tools/common.jam +++ b/src/tools/common.jam @@ -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