def looks_like_implicit_value(v):
    """Returns true if 'v' is either implicit value, or
    the part before the first '-' symbol is implicit value."""
    if feature.is_implicit_value(v):
        return 1
    else:
        split = v.split("-")
        if feature.is_implicit_value(split[0]):
            return 1

    return 0
Beispiel #2
0
def create_from_string(s, allow_condition=False, allow_missing_value=False):
    assert isinstance(s, basestring)
    assert isinstance(allow_condition, bool)
    assert isinstance(allow_missing_value, bool)
    condition = []
    import types
    if not isinstance(s, types.StringType):
        print type(s)
    if __re_has_condition.search(s):

        if not allow_condition:
            raise BaseException(
                "Conditional property is not allowed in this context")

        m = __re_separate_condition_and_property.match(s)
        condition = m.group(1)
        s = m.group(2)

    # FIXME: break dependency cycle
    from b2.manager import get_manager

    feature_name = get_grist(s)
    if not feature_name:
        if feature.is_implicit_value(s):
            f = feature.implied_feature(s)
            value = s
        else:
            raise get_manager().errors()(
                "Invalid property '%s' -- unknown feature" % s)
    else:
        if feature.valid(feature_name):
            f = feature.get(feature_name)
            value = get_value(s)
        else:
            # In case feature name is not known, it is wrong to do a hard error.
            # Feature sets change depending on the toolset. So e.g.
            # <toolset-X:version> is an unknown feature when using toolset Y.
            #
            # Ideally we would like to ignore this value, but most of
            # Boost.Build code expects that we return a valid Property. For this
            # reason we use a sentinel <not-applicable-in-this-context> feature.
            #
            # The underlying cause for this problem is that python port Property
            # is more strict than its Jam counterpart and must always reference
            # a valid feature.
            f = feature.get(__not_applicable_feature)
            value = s

        if not value and not allow_missing_value:
            get_manager().errors()(
                "Invalid property '%s' -- no value specified" % s)

    if condition:
        condition = [create_from_string(x) for x in condition.split(',')]

    return Property(f, value, condition)
Beispiel #3
0
def variant(name, parents_or_properties, explicit_properties=[]):
    """ Declares a new variant.
        First determines explicit properties for this variant, by
        refining parents' explicit properties with the passed explicit
        properties. The result is remembered and will be used if
        this variant is used as parent.
        
        Second, determines the full property set for this variant by
        adding to the explicit properties default values for all properties 
        which neither present nor are symmetric.
        
        Lastly, makes appropriate value of 'variant' property expand
        to the full property set.
        name:                   Name of the variant
        parents_or_properties:  Specifies parent variants, if 
                                'explicit_properties' are given,
                                and explicit_properties otherwise.
        explicit_properties:    Explicit properties.
    """
    parents = []
    if not explicit_properties:
        if get_grist(parents_or_properties[0]):
            explicit_properties = parents_or_properties

        else:
            parents = parents_or_properties

    else:
        parents = parents_or_properties

    # The problem is that we have to check for conflicts
    # between base variants.
    if len(parents) > 1:
        raise BaseException("Multiple base variants are not yet supported")

    inherited = []
    # Add explicitly specified properties for parents
    for p in parents:
        # TODO: the check may be stricter
        if not feature.is_implicit_value(p):
            raise BaseException("Invalid base varaint '%s'" % p)

        inherited += __variant_explicit_properties[p]

    property.validate(explicit_properties)
    explicit_properties = property.refine(inherited, explicit_properties)

    # Record explicitly specified properties for this variant
    # We do this after inheriting parents' properties, so that
    # they affect other variants, derived from this one.
    __variant_explicit_properties[name] = explicit_properties

    feature.extend('variant', [name])
    feature.compose(replace_grist(name, '<variant>'), explicit_properties)
Beispiel #4
0
def create_from_string(s, allow_condition=False,allow_missing_value=False):
    assert isinstance(s, basestring)
    assert isinstance(allow_condition, bool)
    assert isinstance(allow_missing_value, bool)
    condition = []
    import types
    if not isinstance(s, types.StringType):
        print type(s)
    if __re_has_condition.search(s):

        if not allow_condition:
            raise BaseException("Conditional property is not allowed in this context")

        m = __re_separate_condition_and_property.match(s)
        condition = m.group(1)
        s = m.group(2)

    # FIXME: break dependency cycle
    from b2.manager import get_manager

    feature_name = get_grist(s)
    if not feature_name:
        if feature.is_implicit_value(s):
            f = feature.implied_feature(s)
            value = s
        else:
            raise get_manager().errors()("Invalid property '%s' -- unknown feature" % s)
    else:
        if feature.valid(feature_name):
            f = feature.get(feature_name)
            value = get_value(s)
        else:
            # In case feature name is not known, it is wrong to do a hard error.
            # Feature sets change depending on the toolset. So e.g.
            # <toolset-X:version> is an unknown feature when using toolset Y.
            #
            # Ideally we would like to ignore this value, but most of
            # Boost.Build code expects that we return a valid Property. For this
            # reason we use a sentinel <not-applicable-in-this-context> feature.
            #
            # The underlying cause for this problem is that python port Property
            # is more strict than its Jam counterpart and must always reference
            # a valid feature.
            f = feature.get(__not_applicable_feature)
            value = s

        if not value and not allow_missing_value:
            get_manager().errors()("Invalid property '%s' -- no value specified" % s)


    if condition:
        condition = [create_from_string(x) for x in condition.split(',')]

    return Property(f, value, condition)
Beispiel #5
0
def variant (name, parents_or_properties, explicit_properties = []):
    """ Declares a new variant.
        First determines explicit properties for this variant, by
        refining parents' explicit properties with the passed explicit
        properties. The result is remembered and will be used if
        this variant is used as parent.
        
        Second, determines the full property set for this variant by
        adding to the explicit properties default values for all properties 
        which neither present nor are symmetric.
        
        Lastly, makes appropriate value of 'variant' property expand
        to the full property set.
        name:                   Name of the variant
        parents_or_properties:  Specifies parent variants, if 
                                'explicit_properties' are given,
                                and explicit_properties otherwise.
        explicit_properties:    Explicit properties.
    """
    parents = []
    if not explicit_properties:
        if get_grist (parents_or_properties [0]):
            explicit_properties = parents_or_properties

        else:
            parents = parents_or_properties

    else:
        parents = parents_or_properties

    # The problem is that we have to check for conflicts
    # between base variants.
    if len (parents) > 1:
        raise BaseException ("Multiple base variants are not yet supported")
    
    inherited = []
    # Add explicitly specified properties for parents
    for p in parents:
        # TODO: the check may be stricter
        if not feature.is_implicit_value (p):
            raise BaseException ("Invalid base varaint '%s'" % p)
        
        inherited += __variant_explicit_properties [p]

    property.validate (explicit_properties)
    explicit_properties = property.refine (inherited, explicit_properties)
    
    # Record explicitly specified properties for this variant
    # We do this after inheriting parents' properties, so that
    # they affect other variants, derived from this one.
    __variant_explicit_properties [name] = explicit_properties
           
    feature.extend('variant', [name])
    feature.compose (replace_grist (name, '<variant>'), explicit_properties)
Beispiel #6
0
def variant(name, parents_or_properties, explicit_properties=[]):
    """ Declares a new variant.
        First determines explicit properties for this variant, by
        refining parents' explicit properties with the passed explicit
        properties. The result is remembered and will be used if
        this variant is used as parent.
        
        Second, determines the full property set for this variant by
        adding to the explicit properties default values for all properties 
        which neither present nor are symmetric.
        
        Lastly, makes appropriate value of 'variant' property expand
        to the full property set.
        name:                   Name of the variant
        parents_or_properties:  Specifies parent variants, if 
                                'explicit_properties' are given,
                                and explicit_properties otherwise.
        explicit_properties:    Explicit properties.
    """
    parents = []
    if not explicit_properties:
        explicit_properties = parents_or_properties
    else:
        parents = parents_or_properties

    inherited = property_set.empty()
    if parents:

        # If we allow multiple parents, we'd have to to check for conflicts
        # between base variants, and there was no demand for so to bother.
        if len(parents) > 1:
            raise BaseException("Multiple base variants are not yet supported")

        p = parents[0]
        # TODO: the check may be stricter
        if not feature.is_implicit_value(p):
            raise BaseException("Invalid base varaint '%s'" % p)

        inherited = __variant_explicit_properties[p]

    explicit_properties = property_set.create_with_validation(
        explicit_properties)
    explicit_properties = inherited.refine(explicit_properties)

    # Record explicitly specified properties for this variant
    # We do this after inheriting parents' properties, so that
    # they affect other variants, derived from this one.
    __variant_explicit_properties[name] = explicit_properties

    feature.extend('variant', [name])
    feature.compose("<variant>" + name, explicit_properties.all())
Beispiel #7
0
def variant(name, parents_or_properties, explicit_properties=[]):
    """ Declares a new variant.
        First determines explicit properties for this variant, by
        refining parents' explicit properties with the passed explicit
        properties. The result is remembered and will be used if
        this variant is used as parent.
        
        Second, determines the full property set for this variant by
        adding to the explicit properties default values for all properties 
        which neither present nor are symmetric.
        
        Lastly, makes appropriate value of 'variant' property expand
        to the full property set.
        name:                   Name of the variant
        parents_or_properties:  Specifies parent variants, if 
                                'explicit_properties' are given,
                                and explicit_properties otherwise.
        explicit_properties:    Explicit properties.
    """
    parents = []
    if not explicit_properties:
        explicit_properties = parents_or_properties
    else:
        parents = parents_or_properties

    inherited = property_set.empty()
    if parents:

        # If we allow multiple parents, we'd have to to check for conflicts
        # between base variants, and there was no demand for so to bother.
        if len(parents) > 1:
            raise BaseException("Multiple base variants are not yet supported")

        p = parents[0]
        # TODO: the check may be stricter
        if not feature.is_implicit_value(p):
            raise BaseException("Invalid base variant '%s'" % p)

        inherited = __variant_explicit_properties[p]

    explicit_properties = property_set.create_with_validation(
        explicit_properties)
    explicit_properties = inherited.refine(explicit_properties)

    # Record explicitly specified properties for this variant
    # We do this after inheriting parents' properties, so that
    # they affect other variants, derived from this one.
    __variant_explicit_properties[name] = explicit_properties

    feature.extend('variant', [name])
    feature.compose("<variant>" + name, explicit_properties.all())
Beispiel #8
0
def make (specification):
    """ Converts implicit values into full properties.
    """
    result = []
    for e in specification:
        if get_grist (e):
            result.append (e)

        elif feature.is_implicit_value (e):
            f = feature.implied_feature (e)
            result.append (f + e)

        else:
            raise InvalidProperty ("'%s' is not a valid for property specification" % e)

    return result
Beispiel #9
0
def create_from_string(s, allow_condition=False):

    condition = []
    import types
    if not isinstance(s, types.StringType):
        print type(s)
    if __re_has_condition.search(s):

        if not allow_condition:
            raise BaseException(
                "Conditional property is not allowed in this context")

        m = __re_separate_condition_and_property.match(s)
        condition = m.group(1)
        s = m.group(2)

    # FIXME: break dependency cycle
    from b2.manager import get_manager

    feature_name = get_grist(s)
    if not feature_name:
        if feature.is_implicit_value(s):
            f = feature.implied_feature(s)
            value = s
        else:
            raise get_manager().errors()(
                "Invalid property '%s' -- unknown feature" % s)
    else:
        f = feature.get(feature_name)

        value = get_value(s)
        if not value:
            get_manager().errors()(
                "Invalid property '%s' -- no value specified" % s)

    if condition:
        condition = [create_from_string(x) for x in condition.split(',')]

    return Property(f, value, condition)
Beispiel #10
0
def create_from_string(s, allow_condition=False, allow_missing_value=False):

    condition = []
    import types

    if not isinstance(s, types.StringType):
        print type(s)
    if __re_has_condition.search(s):

        if not allow_condition:
            raise BaseException("Conditional property is not allowed in this context")

        m = __re_separate_condition_and_property.match(s)
        condition = m.group(1)
        s = m.group(2)

    # FIXME: break dependency cycle
    from b2.manager import get_manager

    feature_name = get_grist(s)
    if not feature_name:
        if feature.is_implicit_value(s):
            f = feature.implied_feature(s)
            value = s
        else:
            raise get_manager().errors()("Invalid property '%s' -- unknown feature" % s)
    else:
        f = feature.get(feature_name)

        value = get_value(s)
        if not value and not allow_missing_value:
            get_manager().errors()("Invalid property '%s' -- no value specified" % s)

    if condition:
        condition = [create_from_string(x) for x in condition.split(",")]

    return Property(f, value, condition)