예제 #1
0
def register(type, suffixes=[], base_type=None):
    """ Registers a target type, possibly derived from a 'base-type'.
        If 'suffixes' are provided, they list all the suffixes that mean a file is of 'type'.
        Also, the first element gives the suffix to be used when constructing and object of
        'type'.
        type: a string
        suffixes: None or a sequence of strings
        base_type: None or a string
    """
    # Type names cannot contain hyphens, because when used as
    # feature-values they will be interpreted as composite features
    # which need to be decomposed.
    if __re_hyphen.search(type):
        raise BaseException('type name "%s" contains a hyphen' % type)

    # it's possible for a type to be registered with a
    # base type that hasn't been registered yet. in the
    # check for base_type below and the following calls to setdefault()
    # the key `type` will be added to __types. When the base type
    # actually gets registered, it would fail after the simple check
    # of "type in __types"; thus the check for "'base' in __types[type]"
    if type in __types and 'base' in __types[type]:
        raise BaseException('Type "%s" is already registered.' % type)

    entry = __types.setdefault(type, {})
    entry['base'] = base_type
    entry.setdefault('derived', [])
    entry.setdefault('scanner', None)

    if base_type:
        __types.setdefault(base_type, {}).setdefault('derived',
                                                     []).append(type)

    if len(suffixes) > 0:
        # Generated targets of 'type' will use the first of 'suffixes'
        # (this may be overridden)
        set_generated_target_suffix(type, [], suffixes[0])

        # Specify mapping from suffixes to type
        register_suffixes(suffixes, type)

    feature.extend('target-type', [type])
    feature.extend('main-target-type', [type])
    feature.extend('base-target-type', [type])

    if base_type:
        feature.compose('<target-type>' + type,
                        [replace_grist(base_type, '<base-target-type>')])
        feature.compose('<base-target-type>' + type,
                        ['<base-target-type>' + base_type])

    import b2.build.generators as generators
    # Adding a new derived type affects generator selection so we need to
    # make the generator selection module update any of its cached
    # information related to a new derived type being defined.
    generators.update_cached_information_with_a_new_type(type)

    # FIXME: resolving recursive dependency.
    from b2.manager import get_manager
    get_manager().projects().project_rules().add_rule_for_type(type)
예제 #2
0
파일: type.py 프로젝트: boostorg/build
def register(type, suffixes=[], base_type=None):
    """ Registers a target type, possibly derived from a 'base-type'.
        If 'suffixes' are provided, they list all the suffixes that mean a file is of 'type'.
        Also, the first element gives the suffix to be used when constructing and object of
        'type'.
        type: a string
        suffixes: None or a sequence of strings
        base_type: None or a string
    """
    # Type names cannot contain hyphens, because when used as
    # feature-values they will be interpreted as composite features
    # which need to be decomposed.
    if __re_hyphen.search(type):
        raise BaseException('type name "%s" contains a hyphen' % type)

    # it's possible for a type to be registered with a
    # base type that hasn't been registered yet. in the
    # check for base_type below and the following calls to setdefault()
    # the key `type` will be added to __types. When the base type
    # actually gets registered, it would fail after the simple check
    # of "type in __types"; thus the check for "'base' in __types[type]"
    if type in __types and "base" in __types[type]:
        raise BaseException('Type "%s" is already registered.' % type)

    entry = __types.setdefault(type, {})
    entry["base"] = base_type
    entry.setdefault("derived", [])
    entry.setdefault("scanner", None)

    if base_type:
        __types.setdefault(base_type, {}).setdefault("derived", []).append(type)

    if len(suffixes) > 0:
        # Generated targets of 'type' will use the first of 'suffixes'
        # (this may be overriden)
        set_generated_target_suffix(type, [], suffixes[0])

        # Specify mapping from suffixes to type
        register_suffixes(suffixes, type)

    feature.extend("target-type", [type])
    feature.extend("main-target-type", [type])
    feature.extend("base-target-type", [type])

    if base_type:
        feature.compose("<target-type>" + type, [replace_grist(base_type, "<base-target-type>")])
        feature.compose("<base-target-type>" + type, ["<base-target-type>" + base_type])

    import b2.build.generators as generators

    # Adding a new derived type affects generator selection so we need to
    # make the generator selection module update any of its cached
    # information related to a new derived type being defined.
    generators.update_cached_information_with_a_new_type(type)

    # FIXME: resolving recursive dependency.
    from b2.manager import get_manager

    get_manager().projects().project_rules().add_rule_for_type(type)
예제 #3
0
def register(type, suffixes=[], base_type=None):
    """ Registers a target type, possibly derived from a 'base-type'. 
        If 'suffixes' are provided, they list all the suffixes that mean a file is of 'type'.
        Also, the first element gives the suffix to be used when constructing and object of
        'type'.
        type: a string
        suffixes: None or a sequence of strings
        base_type: None or a string
    """
    # Type names cannot contain hyphens, because when used as
    # feature-values they will be interpreted as composite features
    # which need to be decomposed.
    if __re_hyphen.search(type):
        raise BaseException('type name "%s" contains a hyphen' % type)

    if __types.has_key(type):
        raise BaseException('Type "%s" is already registered.' % type)

    entry = {}
    entry["base"] = base_type
    entry["derived"] = []
    entry["scanner"] = None
    __types[type] = entry

    if base_type:
        __types[base_type]["derived"].append(type)

    if len(suffixes) > 0:
        # Generated targets of 'type' will use the first of 'suffixes'
        # (this may be overriden)
        set_generated_target_suffix(type, [], suffixes[0])

        # Specify mapping from suffixes to type
        register_suffixes(suffixes, type)

    feature.extend("target-type", [type])
    feature.extend("main-target-type", [type])
    feature.extend("base-target-type", [type])

    if base_type:
        feature.compose("<target-type>" + type, replace_grist(base_type, "<base-target-type>"))
        feature.compose("<base-target-type>" + type, "<base-target-type>" + base_type)

    import b2.build.generators as generators

    # Adding a new derived type affects generator selection so we need to
    # make the generator selection module update any of its cached
    # information related to a new derived type being defined.
    generators.update_cached_information_with_a_new_type(type)

    # FIXME: resolving recursive dependency.
    from b2.manager import get_manager

    get_manager().projects().project_rules().add_rule_for_type(type)
예제 #4
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)
예제 #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)
예제 #6
0
def register(type, suffixes=[], base_type=None):
    """ Registers a target type, possibly derived from a 'base-type'. 
        If 'suffixes' are provided, they list all the suffixes that mean a file is of 'type'.
        Also, the first element gives the suffix to be used when constructing and object of
        'type'.
        type: a string
        suffixes: None or a sequence of strings
        base_type: None or a string
    """
    # Type names cannot contain hyphens, because when used as
    # feature-values they will be interpreted as composite features
    # which need to be decomposed.
    if __re_hyphen.search(type):
        raise BaseException('type name "%s" contains a hyphen' % type)

    if __types.has_key(type):
        raise BaseException('Type "%s" is already registered.' % type)

    entry = {}
    entry['base'] = base_type
    entry['derived'] = []
    entry['scanner'] = None
    __types[type] = entry

    if base_type:
        __types[base_type]['derived'].append(type)

    if len(suffixes) > 0:
        # Generated targets of 'type' will use the first of 'suffixes'
        # (this may be overriden)
        set_generated_target_suffix(type, [], suffixes[0])

        # Specify mapping from suffixes to type
        register_suffixes(suffixes, type)

    feature.extend('target-type', [type])
    feature.extend('main-target-type', [type])
    feature.extend('base-target-type', [type])

    if base_type:
        feature.compose('<target-type>' + type,
                        replace_grist(base_type, '<base-target-type>'))
        feature.compose('<base-target-type>' + type,
                        '<base-target-type>' + base_type)

    import b2.build.generators as generators
    # Adding a new derived type affects generator selection so we need to
    # make the generator selection module update any of its cached
    # information related to a new derived type being defined.
    generators.update_cached_information_with_a_new_type(type)

    # FIXME: resolving recursive dependency.
    from b2.manager import get_manager
    get_manager().projects().project_rules().add_rule_for_type(type)
예제 #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 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())
예제 #8
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())