From 6a22b69b4825e72cb2aabab1b7546b4be4bb70d7 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 15 Jan 2003 01:11:27 +0000 Subject: [PATCH] Fix subfeature validation [SVN r16903] --- new/build-request.jam | 2 +- new/feature.jam | 78 ++++++++++++++++++++++++++++---------- new/gcc.jam | 6 +-- new/property.jam | 22 ++++++----- new/sequence.jam | 1 + v2/build/build-request.jam | 2 +- v2/build/feature.jam | 78 ++++++++++++++++++++++++++++---------- v2/build/property.jam | 22 ++++++----- v2/gcc.jam | 6 +-- v2/util/sequence.jam | 1 + 10 files changed, 152 insertions(+), 66 deletions(-) diff --git a/new/build-request.jam b/new/build-request.jam index c937fe5b8..337792f65 100644 --- a/new/build-request.jam +++ b/new/build-request.jam @@ -307,7 +307,7 @@ rule __test__ ( ) try ; build-request.from-command-line bjam gcc/debug runtime-link=dynamic/static : $(test-space) ; - catch "Invalid property 'static': 'static' is not a value of implicit feature." ; + catch \"static\" is not a value of an implicit feature ; r = [ build-request.from-command-line bjam -d2 --debug debug target diff --git a/new/feature.jam b/new/feature.jam index c4dd7689e..51058c178 100644 --- a/new/feature.jam +++ b/new/feature.jam @@ -136,10 +136,30 @@ rule values ( feature ) return $($(feature).values) ; } -# returns true iff 'value' is a value of an implicit feature -rule is-implicit-value ( value ) +# returns true iff 'value-string' is a value-string of an implicit feature +rule is-implicit-value ( value-string ) { - if $(value) in $(.all-implicit-values) + local v = [ regex.split $(value-string) - ] ; + local failed ; + if ! $(v[1]) in $(.all-implicit-values) + { + failed = true ; + } + else + { + local feature = $($(v[1]).implicit-feature) ; + + for local subvalue in $(v[2-]) + { + ECHO subvalue= \"$(subvalue)\" ; + if ! [ find-implied-subfeature $(feature) $(subvalue) : $(v[1]) ] + { + failed = true ; + } + } + } + + if ! $(failed) { return true ; } @@ -148,10 +168,13 @@ rule is-implicit-value ( value ) # return the implicit feature associated with the given implicit value. rule implied-feature ( implicit-value ) { - local feature = $($(implicit-value).implicit-feature) ; + local components = [ regex.split $(implicit-value) "-" ] ; + + local feature = $($(components[1]).implicit-feature) ; if ! $(feature) { error \"$(implicit-value)\" is not a value of an implicit feature ; + feature = "" ; } return $(feature) ; } @@ -220,16 +243,17 @@ local rule expand-subfeatures-aux ( validate-feature $(feature) ; } - local components = [ regex.split $(value) "-" ] ; if ! $(feature) { - feature = [ implied-feature $(components[1]) ] ; + feature = [ implied-feature $(value) ] ; } else if ! $(feature) in $(.all-features) { error unknown feature $(feature) ; } + local components = [ regex.split $(value) "-" ] ; + # get the top-level feature's value local value = $(components[1]:G=) ; @@ -305,26 +329,31 @@ local rule extend-feature ( feature : values * ) } # Checks that value-string is a valid value-string for the given feature. -local rule validate-value-string ( feature value-string ) +rule validate-value-string ( feature value-string ) { + feature = [ grist $(feature) ] ; + local values = $(value-string) ; - if $($(feature).subfeatures) + + if ! ( $(values) in $(feature).values ) { - values = [ regex.split $(value-string) - ] ; - } + if $($(feature).subfeatures) + { + values = [ regex.split $(value-string) - ] ; + } - if ! ( $(values[1]) in $($(feature).values) ) - { - return \"$(values[1])\" is not a known value of feature $(feature) ; - } + if ! ( $(values[1]) in $($(feature).values) ) + { + error \"$(values[1])\" is not a known value of feature $(feature) ; + } - if $(values[2]) - { - # this will validate any subfeature values in value-string - implied-subfeature $(feature) [ sequence.join $(values[2-]) - ] - : $(values[1]) ; + if $(values[2]) + { + # this will validate any subfeature values in value-string + implied-subfeature $(feature) [ sequence.join $(values[2-]) : - ] + : $(values[1]) ; + } } - } # Extends the given subfeature with the subvalues. If the optional @@ -876,6 +905,15 @@ local rule __test__ ( ) } catch unknown feature ; + validate-value-string gcc ; + validate-value-string gcc-3.0.1 ; + + try ; + { + validate-value-string digital_mars ; + } + catch \"digital_mars\" is not a known value of ; + try ; { feature foobar : : baz ; diff --git a/new/gcc.jam b/new/gcc.jam index d7c20c032..62aebebb9 100644 --- a/new/gcc.jam +++ b/new/gcc.jam @@ -31,9 +31,9 @@ rule init ( a1 * : a2 * : a3 * ) # NOTE: this should be collapsed in one line once # 'toolset.flags' supports specifying module name. - toolset.flags gcc.compile NAME gcc/$(version) : $(name) ; - toolset.flags gcc.link NAME gcc/$(version) : $(name) ; - toolset.flags gcc.link-dll NAME gcc/$(version) : $(name) ; + toolset.flags gcc.compile NAME gcc-$(version) : $(name) ; + toolset.flags gcc.link NAME gcc-$(version) : $(name) ; + toolset.flags gcc.link-dll NAME gcc-$(version) : $(name) ; # TODO: set path accordingly. } diff --git a/new/property.jam b/new/property.jam index 39322f6ee..75e8febdc 100644 --- a/new/property.jam +++ b/new/property.jam @@ -201,10 +201,9 @@ rule validate ( property : feature-space ? ) { msg = "unknown feature '$(feature)'" ; } - else if $(value) && ! $(value) in [ $(feature-space).values $(feature) ] - && ! free in [ $(feature-space).attributes $(feature) ] + else if $(value) && ! free in [ $(feature-space).attributes $(feature) ] { - msg = "value '"$(value:J=" ")"' is not valid for feature'"$(feature)' ; + $(feature-space).validate-value-string $(feature) $(value) ; } else if ! $(value) { @@ -213,10 +212,8 @@ rule validate ( property : feature-space ? ) } else { - if ! [ $(feature-space).is-implicit-value $(property) ] - { - msg = '$(property:J=" ")' "is not a value of implicit feature" ; - } + local feature = [ $(feature-space).implied-feature $(property) ] ; + $(feature-space).validate-value-string $(feature) $(property) ; } if $(msg) { @@ -389,6 +386,8 @@ local rule __test__ ( ) import assert ; feature toolset : gcc : implicit ; + subfeature toolset gcc : version : 2.95.2 2.95.3 2.95.4 + 3.0 3.0.1 3.0.2 : optional ; feature define : : free ; feature runtime-link : dynamic static : symmetric link-incompatible ; feature optimization : on off ; @@ -400,6 +399,11 @@ local rule __test__ ( ) } + validate gcc : $(test-space) ; + validate gcc-3.0.1 : $(test-space) ; + validate gcc : $(test-space) ; + validate gcc-3.0.1 : $(test-space) ; + assert.result gcc off FOO : refine gcc off : FOO @@ -447,7 +451,7 @@ local rule __test__ ( ) try ; validate default : $(test-space) ; - catch "Invalid property 'default': value 'default' is not valid for feature'rtti'." ; + catch \"default\" is not a known value of feature ; validate WHATEVER : $(test-space) ; @@ -457,7 +461,7 @@ local rule __test__ ( ) try ; validate value : $(test-space) ; - catch "Invalid property 'value': 'value' is not a value of implicit feature." ; + catch "value" is not a value of an implicit feature ; assert.result on diff --git a/new/sequence.jam b/new/sequence.jam index d47347fdd..50ab5c0aa 100644 --- a/new/sequence.jam +++ b/new/sequence.jam @@ -259,6 +259,7 @@ local rule __test__ ( ) assert.result foo-bar-baz : sequence.join foo bar baz : - ; assert.result substandard : sequence.join sub stan dard ; + assert.result 3.0.1 : sequence.join 3.0.1 : - ; assert.result 0 : sequence.length ; assert.result 3 : sequence.length a b c ; diff --git a/v2/build/build-request.jam b/v2/build/build-request.jam index c937fe5b8..337792f65 100644 --- a/v2/build/build-request.jam +++ b/v2/build/build-request.jam @@ -307,7 +307,7 @@ rule __test__ ( ) try ; build-request.from-command-line bjam gcc/debug runtime-link=dynamic/static : $(test-space) ; - catch "Invalid property 'static': 'static' is not a value of implicit feature." ; + catch \"static\" is not a value of an implicit feature ; r = [ build-request.from-command-line bjam -d2 --debug debug target diff --git a/v2/build/feature.jam b/v2/build/feature.jam index c4dd7689e..51058c178 100644 --- a/v2/build/feature.jam +++ b/v2/build/feature.jam @@ -136,10 +136,30 @@ rule values ( feature ) return $($(feature).values) ; } -# returns true iff 'value' is a value of an implicit feature -rule is-implicit-value ( value ) +# returns true iff 'value-string' is a value-string of an implicit feature +rule is-implicit-value ( value-string ) { - if $(value) in $(.all-implicit-values) + local v = [ regex.split $(value-string) - ] ; + local failed ; + if ! $(v[1]) in $(.all-implicit-values) + { + failed = true ; + } + else + { + local feature = $($(v[1]).implicit-feature) ; + + for local subvalue in $(v[2-]) + { + ECHO subvalue= \"$(subvalue)\" ; + if ! [ find-implied-subfeature $(feature) $(subvalue) : $(v[1]) ] + { + failed = true ; + } + } + } + + if ! $(failed) { return true ; } @@ -148,10 +168,13 @@ rule is-implicit-value ( value ) # return the implicit feature associated with the given implicit value. rule implied-feature ( implicit-value ) { - local feature = $($(implicit-value).implicit-feature) ; + local components = [ regex.split $(implicit-value) "-" ] ; + + local feature = $($(components[1]).implicit-feature) ; if ! $(feature) { error \"$(implicit-value)\" is not a value of an implicit feature ; + feature = "" ; } return $(feature) ; } @@ -220,16 +243,17 @@ local rule expand-subfeatures-aux ( validate-feature $(feature) ; } - local components = [ regex.split $(value) "-" ] ; if ! $(feature) { - feature = [ implied-feature $(components[1]) ] ; + feature = [ implied-feature $(value) ] ; } else if ! $(feature) in $(.all-features) { error unknown feature $(feature) ; } + local components = [ regex.split $(value) "-" ] ; + # get the top-level feature's value local value = $(components[1]:G=) ; @@ -305,26 +329,31 @@ local rule extend-feature ( feature : values * ) } # Checks that value-string is a valid value-string for the given feature. -local rule validate-value-string ( feature value-string ) +rule validate-value-string ( feature value-string ) { + feature = [ grist $(feature) ] ; + local values = $(value-string) ; - if $($(feature).subfeatures) + + if ! ( $(values) in $(feature).values ) { - values = [ regex.split $(value-string) - ] ; - } + if $($(feature).subfeatures) + { + values = [ regex.split $(value-string) - ] ; + } - if ! ( $(values[1]) in $($(feature).values) ) - { - return \"$(values[1])\" is not a known value of feature $(feature) ; - } + if ! ( $(values[1]) in $($(feature).values) ) + { + error \"$(values[1])\" is not a known value of feature $(feature) ; + } - if $(values[2]) - { - # this will validate any subfeature values in value-string - implied-subfeature $(feature) [ sequence.join $(values[2-]) - ] - : $(values[1]) ; + if $(values[2]) + { + # this will validate any subfeature values in value-string + implied-subfeature $(feature) [ sequence.join $(values[2-]) : - ] + : $(values[1]) ; + } } - } # Extends the given subfeature with the subvalues. If the optional @@ -876,6 +905,15 @@ local rule __test__ ( ) } catch unknown feature ; + validate-value-string gcc ; + validate-value-string gcc-3.0.1 ; + + try ; + { + validate-value-string digital_mars ; + } + catch \"digital_mars\" is not a known value of ; + try ; { feature foobar : : baz ; diff --git a/v2/build/property.jam b/v2/build/property.jam index 39322f6ee..75e8febdc 100644 --- a/v2/build/property.jam +++ b/v2/build/property.jam @@ -201,10 +201,9 @@ rule validate ( property : feature-space ? ) { msg = "unknown feature '$(feature)'" ; } - else if $(value) && ! $(value) in [ $(feature-space).values $(feature) ] - && ! free in [ $(feature-space).attributes $(feature) ] + else if $(value) && ! free in [ $(feature-space).attributes $(feature) ] { - msg = "value '"$(value:J=" ")"' is not valid for feature'"$(feature)' ; + $(feature-space).validate-value-string $(feature) $(value) ; } else if ! $(value) { @@ -213,10 +212,8 @@ rule validate ( property : feature-space ? ) } else { - if ! [ $(feature-space).is-implicit-value $(property) ] - { - msg = '$(property:J=" ")' "is not a value of implicit feature" ; - } + local feature = [ $(feature-space).implied-feature $(property) ] ; + $(feature-space).validate-value-string $(feature) $(property) ; } if $(msg) { @@ -389,6 +386,8 @@ local rule __test__ ( ) import assert ; feature toolset : gcc : implicit ; + subfeature toolset gcc : version : 2.95.2 2.95.3 2.95.4 + 3.0 3.0.1 3.0.2 : optional ; feature define : : free ; feature runtime-link : dynamic static : symmetric link-incompatible ; feature optimization : on off ; @@ -400,6 +399,11 @@ local rule __test__ ( ) } + validate gcc : $(test-space) ; + validate gcc-3.0.1 : $(test-space) ; + validate gcc : $(test-space) ; + validate gcc-3.0.1 : $(test-space) ; + assert.result gcc off FOO : refine gcc off : FOO @@ -447,7 +451,7 @@ local rule __test__ ( ) try ; validate default : $(test-space) ; - catch "Invalid property 'default': value 'default' is not valid for feature'rtti'." ; + catch \"default\" is not a known value of feature ; validate WHATEVER : $(test-space) ; @@ -457,7 +461,7 @@ local rule __test__ ( ) try ; validate value : $(test-space) ; - catch "Invalid property 'value': 'value' is not a value of implicit feature." ; + catch "value" is not a value of an implicit feature ; assert.result on diff --git a/v2/gcc.jam b/v2/gcc.jam index d7c20c032..62aebebb9 100644 --- a/v2/gcc.jam +++ b/v2/gcc.jam @@ -31,9 +31,9 @@ rule init ( a1 * : a2 * : a3 * ) # NOTE: this should be collapsed in one line once # 'toolset.flags' supports specifying module name. - toolset.flags gcc.compile NAME gcc/$(version) : $(name) ; - toolset.flags gcc.link NAME gcc/$(version) : $(name) ; - toolset.flags gcc.link-dll NAME gcc/$(version) : $(name) ; + toolset.flags gcc.compile NAME gcc-$(version) : $(name) ; + toolset.flags gcc.link NAME gcc-$(version) : $(name) ; + toolset.flags gcc.link-dll NAME gcc-$(version) : $(name) ; # TODO: set path accordingly. } diff --git a/v2/util/sequence.jam b/v2/util/sequence.jam index d47347fdd..50ab5c0aa 100644 --- a/v2/util/sequence.jam +++ b/v2/util/sequence.jam @@ -259,6 +259,7 @@ local rule __test__ ( ) assert.result foo-bar-baz : sequence.join foo bar baz : - ; assert.result substandard : sequence.join sub stan dard ; + assert.result 3.0.1 : sequence.join 3.0.1 : - ; assert.result 0 : sequence.length ; assert.result 3 : sequence.length a b c ;