Boost logo

Boost-Commit :

From: jurko.gospodnetic_at_[hidden]
Date: 2008-08-31 17:22:59


Author: jurko
Date: 2008-08-31 17:22:58 EDT (Sun, 31 Aug 2008)
New Revision: 48499
URL: http://svn.boost.org/trac/boost/changeset/48499

Log:
Cleaned up the Boost Build util/utility.jam module a bit. Reordered the rule definitions alphabetically. Added better testing for the ungrist rule. Added better documentation comments.
Text files modified:
   trunk/tools/build/v2/util/utility.jam | 203 +++++++++++++++++++++++++--------------
   1 files changed, 128 insertions(+), 75 deletions(-)

Modified: trunk/tools/build/v2/util/utility.jam
==============================================================================
--- trunk/tools/build/v2/util/utility.jam (original)
+++ trunk/tools/build/v2/util/utility.jam 2008-08-31 17:22:58 EDT (Sun, 31 Aug 2008)
@@ -1,66 +1,77 @@
-# Copyright 2001, 2002 Dave Abrahams
-# Copyright 2002, 2003, 2004, 2005 Vladimir Prus
-# Distributed under the Boost Software License, Version 1.0.
-# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+# Copyright 2001, 2002 Dave Abrahams
+# Copyright 2002, 2003, 2004, 2005 Vladimir Prus
+# Copyright 2008 Jurko Gospodnetic
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 
 import "class" : is-instance ;
 import errors ;
 
-rule ungrist ( names * )
+
+# For all elements of 'list' which do not already have 'suffix', add 'suffix'.
+#
+rule apply-default-suffix ( suffix : list * )
 {
     local result ;
- for local name in $(names)
+ for local i in $(list)
     {
- local stripped = [ MATCH ^<(.*)>$ : $(name) ] ;
- if ! $(stripped)
+ if $(i:S) = $(suffix)
         {
- errors.error "in ungrist" $(names) : $(name) is not of the form <.*> ;
+ result += $(i) ;
+ }
+ else
+ {
+ result += $(i)$(suffix) ;
         }
- result += $(stripped) ;
     }
     return $(result) ;
 }
 
+
+# If 'name' contains a dot, returns the part before the last dot. If 'name'
+# contains no dot, returns it unmodified.
+#
+rule basename ( name )
+{
+ if $(name:S)
+ {
+ name = $(name:B) ;
+ }
+ return $(name) ;
+}
+
+
 # Return the file of the caller of the rule that called caller-file.
+#
 rule caller-file ( )
 {
     local bt = [ BACKTRACE ] ;
     return $(bt[9]) ;
 }
 
-# Returns the textual representation of argument. If it is a class
-# instance, class its 'str' method. Otherwise, returns the argument.
-rule str ( value )
-{
- if [ is-instance $(value) ]
- {
- return [ $(value).str ] ;
- }
- else
- {
- return $(value) ;
- }
-}
 
-# Tests if 'a' is equal to 'b'. If 'a' is a class instance,
-# calls its 'equal' method. Uses ordinary jam's comparison otherwise.
+# Tests if 'a' is equal to 'b'. If 'a' is a class instance, calls its 'equal'
+# method. Uses ordinary jam's comparison otherwise.
+#
 rule equal ( a b )
 {
- if [ is-instance $(a) ]
+ if [ is-instance $(a) ]
     {
         return [ $(a).equal $(b) ] ;
     }
     else
     {
- if $(a) = $(b)
+ if $(a) = $(b)
         {
             return true ;
         }
     }
 }
 
-# Tests if 'a' is less than 'b'. If 'a' is a class instance,
-# calls its 'less' method. Uses ordinary jam's comparison otherwise.
+
+# Tests if 'a' is less than 'b'. If 'a' is a class instance, calls its 'less'
+# method. Uses ordinary jam's comparison otherwise.
+#
 rule less ( a b )
 {
     if [ is-instance $(a) ]
@@ -76,66 +87,57 @@
     }
 }
 
-# For all elements of 'list' which do not already have 'suffix',
-# add 'suffix'.
-rule apply-default-suffix ( suffix : list * )
+
+# Returns the textual representation of argument. If it is a class instance,
+# class its 'str' method. Otherwise, returns the argument.
+#
+rule str ( value )
 {
- local result ;
- for local i in $(list)
+ if [ is-instance $(value) ]
     {
- if $(i:S) = $(suffix)
- {
- result += $(i) ;
- }
- else
- {
- result += $(i)$(suffix) ;
- }
+ return [ $(value).str ] ;
+ }
+ else
+ {
+ return $(value) ;
     }
- return $(result) ;
 }
 
-# If 'name' contains a dot, returns the part before the last dot.
-# If 'name' contains no dot, returns it unmodified.
-rule basename ( name )
-{
- if $(name:S)
+
+# Accepts a list of gristed values and returns them ungristed. Reports an error
+# in case any of the passed parameters is not gristed, i.e. surrounded in angle
+# brackets < and >.
+#
+rule ungrist ( names * )
+{
+ local result ;
+ for local name in $(names)
     {
- name = $(name:B) ;
+ local stripped = [ MATCH ^<(.*)>$ : $(name) ] ;
+ if ! $(stripped)
+ {
+ errors.error "in ungrist $(names) : $(name) is not of the form <.*>" ;
+ }
+ result += $(stripped) ;
     }
- return $(name) ;
+ return $(result) ;
 }
 
 
-
 rule __test__ ( )
 {
     import assert ;
     import "class" : new ;
- assert.result foo bar : ungrist <foo> <bar> ;
+ import errors : try catch ;
 
     assert.result 123 : str 123 ;
 
- class test-class__
+ class test-class__
     {
- rule __init__ ( )
- {
- }
-
- rule str ( )
- {
- return "str-test-class" ;
- }
-
- rule less ( a )
- {
- return "yes, of course!" ;
- }
-
- rule equal ( a )
- {
- return "not sure" ;
- }
+ rule __init__ ( ) { }
+ rule str ( ) { return "str-test-class" ; }
+ rule less ( a ) { return "yes, of course!" ; }
+ rule equal ( a ) { return "not sure" ; }
     }
 
     assert.result "str-test-class" : str [ new test-class__ ] ;
@@ -145,13 +147,64 @@
     assert.true equal 1 1 ;
     assert.false equal 1 2 ;
     assert.result "not sure" : equal [ new test-class__ ] 1 ;
-
- assert.result foo.lib foo.lib : apply-default-suffix .lib : foo.lib foo.lib ;
-
+
+ assert.result foo.lib foo.lib : apply-default-suffix .lib : foo.lib foo.lib
+ ;
+
     assert.result foo : basename foo ;
     assert.result foo : basename foo.so ;
     assert.result foo.so : basename foo.so.1 ;
-}
 
+ assert.result : ungrist ;
+ assert.result foo : ungrist <foo> ;
+ assert.result <foo> : ungrist <<foo>> ;
+ assert.result foo bar : ungrist <foo> <bar> ;
+
+ try ;
+ {
+ ungrist "" ;
+ }
+ catch "in ungrist : is not of the form <.*>" ;
+
+ try ;
+ {
+ ungrist <> ;
+ }
+ catch "in ungrist <> : <> is not of the form <.*>" ;
+
+ try ;
+ {
+ ungrist foo ;
+ }
+ catch "in ungrist foo : foo is not of the form <.*>" ;
+
+ try ;
+ {
+ ungrist <foo ;
+ }
+ catch "in ungrist <foo : <foo is not of the form <.*>" ;
 
+ try ;
+ {
+ ungrist foo> ;
+ }
+ catch "in ungrist foo> : foo> is not of the form <.*>" ;
+
+ try ;
+ {
+ ungrist foo bar ;
+ }
+ catch "in ungrist foo : foo is not of the form <.*>" ;
 
+ try ;
+ {
+ ungrist foo <bar> ;
+ }
+ catch "in ungrist foo : foo is not of the form <.*>" ;
+
+ try ;
+ {
+ ungrist <foo> bar ;
+ }
+ catch "in ungrist bar : bar is not of the form <.*>" ;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk