This file is indexed.

/usr/share/boost-build/src/build/type.py is in libboost1.65-tools-dev 1.65.1+dfsg-0ubuntu5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# Status: ported.
# Base revision: 45462.

#  Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
#  distribute this software is granted provided this copyright notice appears in
#  all copies. This software is provided "as is" without express or implied
#  warranty, and with no claim as to its suitability for any purpose.



import re
import os
import os.path
from b2.util.utility import replace_grist, os_name
from b2.exceptions import *
from b2.build import feature, property, scanner
from b2.util import bjam_signature, is_iterable_typed


__re_hyphen = re.compile ('-')

def __register_features ():
    """ Register features need by this module.
    """
    # The feature is optional so that it is never implicitly added.
    # It's used only for internal purposes, and in all cases we
    # want to explicitly use it.
    feature.feature ('target-type', [], ['composite', 'optional'])
    feature.feature ('main-target-type', [], ['optional', 'incidental'])
    feature.feature ('base-target-type', [], ['composite', 'optional', 'free'])

def reset ():
    """ Clear the module state. This is mainly for testing purposes.
        Note that this must be called _after_ resetting the module 'feature'.
    """
    global __prefixes_suffixes, __suffixes_to_types, __types, __rule_names_to_types, __target_suffixes_cache

    __register_features ()

    # Stores suffixes for generated targets.
    __prefixes_suffixes = [property.PropertyMap(), property.PropertyMap()]

    # Maps suffixes to types
    __suffixes_to_types = {}

    # A map with all the registered types, indexed by the type name
    # Each entry is a dictionary with following values:
    # 'base': the name of base type or None if type has no base
    # 'derived': a list of names of type which derive from this one
    # 'scanner': the scanner class registered for this type, if any
    __types = {}

    # Caches suffixes for targets with certain properties.
    __target_suffixes_cache = {}

reset ()

@bjam_signature((["type"], ["suffixes", "*"], ["base_type", "?"]))
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)

# FIXME: quick hack.
def type_from_rule_name(rule_name):
    assert isinstance(rule_name, basestring)
    return rule_name.upper().replace("-", "_")


def register_suffixes (suffixes, type):
    """ Specifies that targets with suffix from 'suffixes' have the type 'type'.
        If a different type is already specified for any of syffixes, issues an error.
    """
    assert is_iterable_typed(suffixes, basestring)
    assert isinstance(type, basestring)
    for s in suffixes:
        if s in __suffixes_to_types:
            old_type = __suffixes_to_types [s]
            if old_type != type:
                raise BaseException ('Attempting to specify type for suffix "%s"\nOld type: "%s", New type "%s"' % (s, old_type, type))
        else:
            __suffixes_to_types [s] = type

def registered (type):
    """ Returns true iff type has been registered.
    """
    assert isinstance(type, basestring)
    return type in __types

def validate (type):
    """ Issues an error if 'type' is unknown.
    """
    assert isinstance(type, basestring)
    if not registered (type):
        raise BaseException ("Unknown target type '%s'" % type)

def set_scanner (type, scanner):
    """ Sets a scanner class that will be used for this 'type'.
    """
    if __debug__:
        from .scanner import Scanner
        assert isinstance(type, basestring)
        assert issubclass(scanner, Scanner)
    validate (type)
    __types [type]['scanner'] = scanner

def get_scanner (type, prop_set):
    """ Returns a scanner instance appropriate to 'type' and 'property_set'.
    """
    if __debug__:
        from .property_set import PropertySet
        assert isinstance(type, basestring)
        assert isinstance(prop_set, PropertySet)
    if registered (type):
        scanner_type = __types [type]['scanner']
        if scanner_type:
            return scanner.get (scanner_type, prop_set.raw ())
            pass

    return None

def base(type):
    """Returns a base type for the given type or nothing in case the given type is
    not derived."""
    assert isinstance(type, basestring)
    return __types[type]['base']

def all_bases (type):
    """ Returns type and all of its bases, in the order of their distance from type.
    """
    assert isinstance(type, basestring)
    result = []
    while type:
        result.append (type)
        type = __types [type]['base']

    return result

def all_derived (type):
    """ Returns type and all classes that derive from it, in the order of their distance from type.
    """
    assert isinstance(type, basestring)
    result = [type]
    for d in __types [type]['derived']:
        result.extend (all_derived (d))

    return result

def is_derived (type, base):
    """ Returns true if 'type' is 'base' or has 'base' as its direct or indirect base.
    """
    assert isinstance(type, basestring)
    assert isinstance(base, basestring)
    # TODO: this isn't very efficient, especially for bases close to type
    if base in all_bases (type):
        return True
    else:
        return False

def is_subtype (type, base):
    """ Same as is_derived. Should be removed.
    """
    assert isinstance(type, basestring)
    assert isinstance(base, basestring)
    # TODO: remove this method
    return is_derived (type, base)

@bjam_signature((["type"], ["properties", "*"], ["suffix"]))
def set_generated_target_suffix (type, properties, suffix):
    """ Sets a target suffix that should be used when generating target
        of 'type' with the specified properties. Can be called with
        empty properties if no suffix for 'type' was specified yet.
        This does not automatically specify that files 'suffix' have
        'type' --- two different types can use the same suffix for
        generating, but only one type should be auto-detected for
        a file with that suffix. User should explicitly specify which
        one.

        The 'suffix' parameter can be empty string ("") to indicate that
        no suffix should be used.
    """
    assert isinstance(type, basestring)
    assert is_iterable_typed(properties, basestring)
    assert isinstance(suffix, basestring)
    set_generated_target_ps(1, type, properties, suffix)



def change_generated_target_suffix (type, properties, suffix):
    """ Change the suffix previously registered for this type/properties
        combination. If suffix is not yet specified, sets it.
    """
    assert isinstance(type, basestring)
    assert is_iterable_typed(properties, basestring)
    assert isinstance(suffix, basestring)
    change_generated_target_ps(1, type, properties, suffix)

def generated_target_suffix(type, properties):
    if __debug__:
        from .property_set import PropertySet
        assert isinstance(type, basestring)
        assert isinstance(properties, PropertySet)
    return generated_target_ps(1, type, properties)


@bjam_signature((["type"], ["properties", "*"], ["prefix"]))
def set_generated_target_prefix(type, properties, prefix):
    """
    Sets a file prefix to be used when generating a target of 'type' with the
    specified properties. Can be called with no properties if no prefix has
    already been specified for the 'type'. The 'prefix' parameter can be an empty
    string ("") to indicate that no prefix should be used.

    Note that this does not cause files with 'prefix' to be automatically
    recognized as being of 'type'. Two different types can use the same prefix for
    their generated files but only one type can be auto-detected for a file with
    that prefix. User should explicitly specify which one using the
    register-prefixes rule.

    Usage example: library names use the "lib" prefix on unix.
    """
    set_generated_target_ps(0, type, properties, prefix)

# Change the prefix previously registered for this type/properties combination.
# If prefix is not yet specified, sets it.
def change_generated_target_prefix(type, properties, prefix):
    assert isinstance(type, basestring)
    assert is_iterable_typed(properties, basestring)
    assert isinstance(prefix, basestring)
    change_generated_target_ps(0, type, properties, prefix)

def generated_target_prefix(type, properties):
    if __debug__:
        from .property_set import PropertySet
        assert isinstance(type, basestring)
        assert isinstance(properties, PropertySet)
    return generated_target_ps(0, type, properties)

def set_generated_target_ps(is_suffix, type, properties, val):
    assert isinstance(is_suffix, (int, bool))
    assert isinstance(type, basestring)
    assert is_iterable_typed(properties, basestring)
    assert isinstance(val, basestring)
    properties.append ('<target-type>' + type)
    __prefixes_suffixes[is_suffix].insert (properties, val)

def change_generated_target_ps(is_suffix, type, properties, val):
    assert isinstance(is_suffix, (int, bool))
    assert isinstance(type, basestring)
    assert is_iterable_typed(properties, basestring)
    assert isinstance(val, basestring)
    properties.append ('<target-type>' + type)
    prev = __prefixes_suffixes[is_suffix].find_replace(properties, val)
    if not prev:
        set_generated_target_ps(is_suffix, type, properties, val)

# Returns either prefix or suffix (as indicated by 'is_suffix') that should be used
# when generating a target of 'type' with the specified properties.
# If no prefix/suffix is specified for 'type', returns prefix/suffix for
# base type, if any.
def generated_target_ps_real(is_suffix, type, properties):
    assert isinstance(is_suffix, (int, bool))
    assert isinstance(type, basestring)
    assert is_iterable_typed(properties, basestring)
    result = ''
    found = False
    while type and not found:
        result = __prefixes_suffixes[is_suffix].find (['<target-type>' + type] + properties)

        # Note that if the string is empty (""), but not null, we consider
        # suffix found.  Setting prefix or suffix to empty string is fine.
        if result is not None:
            found = True

        type = __types [type]['base']

    if not result:
        result = ''
    return result

def generated_target_ps(is_suffix, type, prop_set):
    """ Returns suffix that should be used when generating target of 'type',
        with the specified properties. If not suffix were specified for
        'type', returns suffix for base type, if any.
    """
    if __debug__:
        from .property_set import PropertySet
        assert isinstance(is_suffix, (int, bool))
        assert isinstance(type, basestring)
        assert isinstance(prop_set, PropertySet)
    key = (is_suffix, type, prop_set)
    v = __target_suffixes_cache.get(key, None)

    if not v:
        v = generated_target_ps_real(is_suffix, type, prop_set.raw())
        __target_suffixes_cache [key] = v

    return v

def type(filename):
    """ Returns file type given it's name. If there are several dots in filename,
        tries each suffix. E.g. for name of "file.so.1.2" suffixes "2", "1", and
        "so"  will be tried.
    """
    assert isinstance(filename, basestring)
    while 1:
        filename, suffix = os.path.splitext (filename)
        if not suffix: return None
        suffix = suffix[1:]

        if suffix in __suffixes_to_types:
            return __suffixes_to_types[suffix]

# NOTE: moved from tools/types/register
def register_type (type, suffixes, base_type = None, os = []):
    """ Register the given type on the specified OSes, or on remaining OSes
        if os is not specified.  This rule is injected into each of the type
        modules for the sake of convenience.
    """
    assert isinstance(type, basestring)
    assert is_iterable_typed(suffixes, basestring)
    assert isinstance(base_type, basestring) or base_type is None
    assert is_iterable_typed(os, basestring)
    if registered (type):
        return

    if not os or os_name () in os:
        register (type, suffixes, base_type)