This file is indexed.

/usr/share/boost-build/src/build/property.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# Status: ported, except for tests.
# Base revision: 64070
#
# Copyright 2001, 2002, 2003 Dave Abrahams
# Copyright 2006 Rene Rivera
# Copyright 2002, 2003, 2004, 2005, 2006 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)

import re
import sys
from functools import total_ordering

from b2.util.utility import *
from b2.build import feature
from b2.util import sequence, qualify_jam_action, is_iterable_typed
import b2.util.set
from b2.manager import get_manager


__re_two_ampersands = re.compile ('&&')
__re_comma = re.compile (',')
__re_split_condition = re.compile ('(.*):(<.*)')
__re_split_conditional = re.compile (r'(.+):<(.+)')
__re_colon = re.compile (':')
__re_has_condition = re.compile (r':<')
__re_separate_condition_and_property = re.compile (r'(.*):(<.*)')

_not_applicable_feature='not-applicable-in-this-context'
feature.feature(_not_applicable_feature, [], ['free'])

__abbreviated_paths = False


class PropertyMeta(type):
    """
    This class exists to implement the isinstance() and issubclass()
    hooks for the Property class. Since we've introduce the concept of
    a LazyProperty, isinstance(p, Property) will fail when p is a LazyProperty.
    Implementing both __instancecheck__ and __subclasscheck__ will allow
    LazyProperty instances to pass the isinstance() and issubclass check for
    the Property class.

    Additionally, the __call__ method intercepts the call to the Property
    constructor to ensure that calling Property with the same arguments
    will always return the same Property instance.
    """
    _registry = {}
    current_id = 1

    def __call__(mcs, f, value, condition=None):
        """
        This intercepts the call to the Property() constructor.

        This exists so that the same arguments will always return the same Property
        instance. This allows us to give each instance a unique ID.
        """
        from b2.build.feature import Feature
        if not isinstance(f, Feature):
            f = feature.get(f)
        if condition is None:
            condition = []
        key = (f, value) + tuple(sorted(condition))
        if key not in mcs._registry:
            instance = super(PropertyMeta, mcs).__call__(f, value, condition)
            mcs._registry[key] = instance
        return mcs._registry[key]

    @staticmethod
    def check(obj):
        return (hasattr(obj, 'feature') and
                hasattr(obj, 'value') and
                hasattr(obj, 'condition'))

    def __instancecheck__(self, instance):
        return self.check(instance)

    def __subclasscheck__(self, subclass):
        return self.check(subclass)


@total_ordering
class Property(object):

    __slots__ = ('feature', 'value', 'condition', '_to_raw', '_hash', 'id')
    __metaclass__ = PropertyMeta

    def __init__(self, f, value, condition=None):
        assert(f.free or ':' not in value)
        if condition is None:
            condition = []

        self.feature = f
        self.value = value
        self.condition = condition
        self._hash = hash((self.feature, self.value) + tuple(sorted(self.condition)))
        self.id = PropertyMeta.current_id
        # increment the id counter.
        # this allows us to take a list of Property
        # instances and use their unique integer ID
        # to create a key for PropertySet caching. This is
        # much faster than string comparison.
        PropertyMeta.current_id += 1

        condition_str = ''
        if condition:
            condition_str = ",".join(str(p) for p in self.condition) + ':'

        self._to_raw = '{}<{}>{}'.format(condition_str, f.name, value)

    def to_raw(self):
        return self._to_raw

    def __str__(self):

        return self._to_raw

    def __hash__(self):
        return self._hash

    def __eq__(self, other):
        return self._hash == other._hash

    def __lt__(self, other):
        return (self.feature.name, self.value) < (other.feature.name, other.value)


@total_ordering
class LazyProperty(object):
    def __init__(self, feature_name, value, condition=None):
        if condition is None:
            condition = []

        self.__property = Property(
            feature.get(_not_applicable_feature), feature_name + value, condition=condition)
        self.__name = feature_name
        self.__value = value
        self.__condition = condition
        self.__feature = None

    def __getattr__(self, item):
        if self.__feature is None:
            try:
                self.__feature = feature.get(self.__name)
                self.__property = Property(self.__feature, self.__value, self.__condition)
            except KeyError:
                pass
        return getattr(self.__property, item)

    def __hash__(self):
        return hash(self.__property)

    def __str__(self):
        return self.__property._to_raw

    def __eq__(self, other):
        return self.__property == other

    def __lt__(self, other):
        return (self.feature.name, self.value) < (other.feature.name, other.value)


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

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

    feature_name = get_grist(s)
    if not feature_name:
        if feature.is_implicit_value(s):
            f = feature.implied_feature(s)
            value = s
            p = Property(f, value, condition=condition)
        else:
            raise get_manager().errors()("Invalid property '%s' -- unknown feature" % s)
    else:
        value = get_value(s)
        if not value and not allow_missing_value:
            get_manager().errors()("Invalid property '%s' -- no value specified" % s)

        if feature.valid(feature_name):
            p = Property(feature.get(feature_name), value, condition=condition)
        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.
            p = LazyProperty(feature_name, value, condition=condition)

    return p

def create_from_strings(string_list, allow_condition=False):
    assert is_iterable_typed(string_list, basestring)
    return [create_from_string(s, allow_condition) for s in string_list]

def reset ():
    """ Clear the module state. This is mainly for testing purposes.
    """
    global __results

    # A cache of results from as_path
    __results = {}

reset ()


def set_abbreviated_paths(on=True):
    global __abbreviated_paths
    if on == 'off':
        on = False
    on = bool(on)
    __abbreviated_paths = on


def get_abbreviated_paths():
    return __abbreviated_paths or '--abbreviated-paths' in sys.argv


def path_order (x, y):
    """ Helper for as_path, below. Orders properties with the implicit ones
        first, and within the two sections in alphabetical order of feature
        name.
    """
    if x == y:
        return 0

    xg = get_grist (x)
    yg = get_grist (y)

    if yg and not xg:
        return -1

    elif xg and not yg:
        return 1

    else:
        if not xg:
            x = feature.expand_subfeatures([x])
            y = feature.expand_subfeatures([y])

        if x < y:
            return -1
        elif x > y:
            return 1
        else:
            return 0

def identify(string):
    return string

# Uses Property
def refine (properties, requirements):
    """ Refines 'properties' by overriding any non-free properties
        for which a different value is specified in 'requirements'.
        Conditional requirements are just added without modification.
        Returns the resulting list of properties.
    """
    assert is_iterable_typed(properties, Property)
    assert is_iterable_typed(requirements, Property)
    # The result has no duplicates, so we store it in a set
    result = set()

    # Records all requirements.
    required = {}

    # All the elements of requirements should be present in the result
    # Record them so that we can handle 'properties'.
    for r in requirements:
        # Don't consider conditional requirements.
        if not r.condition:
            required[r.feature] = r

    for p in properties:
        # Skip conditional properties
        if p.condition:
            result.add(p)
        # No processing for free properties
        elif p.feature.free:
            result.add(p)
        else:
            if p.feature in required:
                result.add(required[p.feature])
            else:
                result.add(p)

    return sequence.unique(list(result) + requirements)

def translate_paths (properties, path):
    """ Interpret all path properties in 'properties' as relative to 'path'
        The property values are assumed to be in system-specific form, and
        will be translated into normalized form.
        """
    assert is_iterable_typed(properties, Property)
    result = []

    for p in properties:

        if p.feature.path:
            values = __re_two_ampersands.split(p.value)

            new_value = "&&".join(os.path.normpath(os.path.join(path, v)) for v in values)

            if new_value != p.value:
                result.append(Property(p.feature, new_value, p.condition))
            else:
                result.append(p)

        else:
            result.append (p)

    return result

def translate_indirect(properties, context_module):
    """Assumes that all feature values that start with '@' are
    names of rules, used in 'context-module'. Such rules can be
    either local to the module or global. Qualified local rules
    with the name of the module."""
    assert is_iterable_typed(properties, Property)
    assert isinstance(context_module, basestring)
    result = []
    for p in properties:
        if p.value[0] == '@':
            q = qualify_jam_action(p.value[1:], context_module)
            get_manager().engine().register_bjam_action(q)
            result.append(Property(p.feature, '@' + q, p.condition))
        else:
            result.append(p)

    return result

def validate (properties):
    """ Exit with error if any of the properties is not valid.
        properties may be a single property or a sequence of properties.
    """
    if isinstance(properties, Property):
        properties = [properties]
    assert is_iterable_typed(properties, Property)
    for p in properties:
        __validate1(p)

def expand_subfeatures_in_conditions (properties):
    assert is_iterable_typed(properties, Property)
    result = []
    for p in properties:

        if not p.condition:
            result.append(p)
        else:
            expanded = []
            for c in p.condition:
                # It common that condition includes a toolset which
                # was never defined, or mentiones subfeatures which
                # were never defined. In that case, validation will
                # only produce an spirious error, so don't validate.
                expanded.extend(feature.expand_subfeatures ([c], True))

            # we need to keep LazyProperties lazy
            if isinstance(p, LazyProperty):
                value = p.value
                feature_name = get_grist(value)
                value = value.replace(feature_name, '')
                result.append(LazyProperty(feature_name, value, condition=expanded))
            else:
                result.append(Property(p.feature, p.value, expanded))

    return result

# FIXME: this should go
def split_conditional (property):
    """ If 'property' is conditional property, returns
        condition and the property, e.g
        <variant>debug,<toolset>gcc:<inlining>full will become
        <variant>debug,<toolset>gcc <inlining>full.
        Otherwise, returns empty string.
    """
    assert isinstance(property, basestring)
    m = __re_split_conditional.match (property)

    if m:
        return (m.group (1), '<' + m.group (2))

    return None


def select (features, properties):
    """ Selects properties which correspond to any of the given features.
    """
    assert is_iterable_typed(properties, basestring)
    result = []

    # add any missing angle brackets
    features = add_grist (features)

    return [p for p in properties if get_grist(p) in features]

def validate_property_sets (sets):
    if __debug__:
        from .property_set import PropertySet
        assert is_iterable_typed(sets, PropertySet)
    for s in sets:
        validate(s.all())

def evaluate_conditionals_in_context (properties, context):
    """ Removes all conditional properties which conditions are not met
        For those with met conditions, removes the condition. Properies
        in conditions are looked up in 'context'
    """
    if __debug__:
        from .property_set import PropertySet
        assert is_iterable_typed(properties, Property)
        assert isinstance(context, PropertySet)
    base = []
    conditional = []

    for p in properties:
        if p.condition:
            conditional.append (p)
        else:
            base.append (p)

    result = base[:]
    for p in conditional:

        # Evaluate condition
        # FIXME: probably inefficient
        if all(x in context for x in p.condition):
            result.append(Property(p.feature, p.value))

    return result


def change (properties, feature, value = None):
    """ Returns a modified version of properties with all values of the
        given feature replaced by the given value.
        If 'value' is None the feature will be removed.
    """
    assert is_iterable_typed(properties, basestring)
    assert isinstance(feature, basestring)
    assert isinstance(value, (basestring, type(None)))
    result = []

    feature = add_grist (feature)

    for p in properties:
        if get_grist (p) == feature:
            if value:
                result.append (replace_grist (value, feature))

        else:
            result.append (p)

    return result


################################################################
# Private functions

def __validate1 (property):
    """ Exit with error if property is not valid.
    """
    assert isinstance(property, Property)
    msg = None

    if not property.feature.free:
        feature.validate_value_string (property.feature, property.value)


###################################################################
# Still to port.
# Original lines are prefixed with "#   "
#
#
#   import utility : ungrist ;
#   import sequence : unique ;
#   import errors : error ;
#   import feature ;
#   import regex ;
#   import sequence ;
#   import set ;
#   import path ;
#   import assert ;
#
#


#   rule validate-property-sets ( property-sets * )
#   {
#       for local s in $(property-sets)
#       {
#           validate [ feature.split $(s) ] ;
#       }
#   }
#

def remove(attributes, properties):
    """Returns a property sets which include all the elements
    in 'properties' that do not have attributes listed in 'attributes'."""
    if isinstance(attributes, basestring):
        attributes = [attributes]
    assert is_iterable_typed(attributes, basestring)
    assert is_iterable_typed(properties, basestring)
    result = []
    for e in properties:
        attributes_new = feature.attributes(get_grist(e))
        has_common_features = 0
        for a in attributes_new:
            if a in attributes:
                has_common_features = 1
                break

        if not has_common_features:
            result += e

    return result


def take(attributes, properties):
    """Returns a property set which include all
    properties in 'properties' that have any of 'attributes'."""
    assert is_iterable_typed(attributes, basestring)
    assert is_iterable_typed(properties, basestring)
    result = []
    for e in properties:
        if b2.util.set.intersection(attributes, feature.attributes(get_grist(e))):
            result.append(e)
    return result

def translate_dependencies(properties, project_id, location):
    assert is_iterable_typed(properties, Property)
    assert isinstance(project_id, basestring)
    assert isinstance(location, basestring)
    result = []
    for p in properties:

        if not p.feature.dependency:
            result.append(p)
        else:
            v = p.value
            m = re.match("(.*)//(.*)", v)
            if m:
                rooted = m.group(1)
                if rooted[0] == '/':
                    # Either project id or absolute Linux path, do nothing.
                    pass
                else:
                    rooted = os.path.join(os.getcwd(), location, rooted)

                result.append(Property(p.feature, rooted + "//" + m.group(2), p.condition))

            elif os.path.isabs(v):
                result.append(p)
            else:
                result.append(Property(p.feature, project_id + "//" + v, p.condition))

    return result


class PropertyMap:
    """ Class which maintains a property set -> string mapping.
    """
    def __init__ (self):
        self.__properties = []
        self.__values = []

    def insert (self, properties, value):
        """ Associate value with properties.
        """
        assert is_iterable_typed(properties, basestring)
        assert isinstance(value, basestring)
        self.__properties.append(properties)
        self.__values.append(value)

    def find (self, properties):
        """ Return the value associated with properties
        or any subset of it. If more than one
        subset has value assigned to it, return the
        value for the longest subset, if it's unique.
        """
        assert is_iterable_typed(properties, basestring)
        return self.find_replace (properties)

    def find_replace(self, properties, value=None):
        assert is_iterable_typed(properties, basestring)
        assert isinstance(value, (basestring, type(None)))
        matches = []
        match_ranks = []

        for i in range(0, len(self.__properties)):
            p = self.__properties[i]

            if b2.util.set.contains (p, properties):
                matches.append (i)
                match_ranks.append(len(p))

        best = sequence.select_highest_ranked (matches, match_ranks)

        if not best:
            return None

        if len (best) > 1:
            raise NoBestMatchingAlternative ()

        best = best [0]

        original = self.__values[best]

        if value:
            self.__values[best] = value

        return original

#   local rule __test__ ( )
#   {
#       import errors : try catch ;
#       import feature ;
#       import feature : feature subfeature compose ;
#
#       # local rules must be explicitly re-imported
#       import property : path-order ;
#
#       feature.prepare-test property-test-temp ;
#
#       feature toolset : gcc : implicit symmetric ;
#       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 ;
#       feature variant : debug release : implicit composite symmetric ;
#       feature rtti : on off : link-incompatible ;
#
#       compose <variant>debug : <define>_DEBUG <optimization>off ;
#       compose <variant>release : <define>NDEBUG <optimization>on ;
#
#       import assert ;
#       import "class" : new ;
#
#       validate <toolset>gcc  <toolset>gcc-3.0.1 : $(test-space) ;
#
#       assert.result <toolset>gcc <rtti>off <define>FOO
#           : refine <toolset>gcc <rtti>off
#           : <define>FOO
#           : $(test-space)
#           ;
#
#       assert.result <toolset>gcc <optimization>on
#           : refine <toolset>gcc <optimization>off
#           : <optimization>on
#           : $(test-space)
#           ;
#
#       assert.result <toolset>gcc <rtti>off
#           : refine <toolset>gcc : <rtti>off : $(test-space)
#           ;
#
#       assert.result <toolset>gcc <rtti>off <rtti>off:<define>FOO
#           : refine <toolset>gcc : <rtti>off <rtti>off:<define>FOO
#           : $(test-space)
#           ;
#
#       assert.result <toolset>gcc:<define>foo <toolset>gcc:<define>bar
#           : refine <toolset>gcc:<define>foo : <toolset>gcc:<define>bar
#           : $(test-space)
#           ;
#
#       assert.result <define>MY_RELEASE
#           : evaluate-conditionals-in-context
#             <variant>release,<rtti>off:<define>MY_RELEASE
#             : <toolset>gcc <variant>release <rtti>off
#
#           ;
#
#       try ;
#           validate <feature>value : $(test-space) ;
#       catch "Invalid property '<feature>value': unknown feature 'feature'." ;
#
#       try ;
#           validate <rtti>default : $(test-space) ;
#       catch \"default\" is not a known value of feature <rtti> ;
#
#       validate <define>WHATEVER : $(test-space) ;
#
#       try ;
#           validate <rtti> : $(test-space) ;
#       catch "Invalid property '<rtti>': No value specified for feature 'rtti'." ;
#
#       try ;
#           validate value : $(test-space) ;
#       catch "value" is not a value of an implicit feature ;
#
#
#       assert.result <rtti>on
#           : remove free implicit : <toolset>gcc <define>foo <rtti>on : $(test-space) ;
#
#       assert.result <include>a
#           : select include : <include>a <toolset>gcc ;
#
#       assert.result <include>a
#           : select include bar : <include>a <toolset>gcc ;
#
#       assert.result <include>a <toolset>gcc
#           : select include <bar> <toolset> : <include>a <toolset>gcc ;
#
#       assert.result <toolset>kylix <include>a
#           : change <toolset>gcc <include>a : <toolset> kylix ;
#
#       # Test ordinary properties
#       assert.result
#         : split-conditional <toolset>gcc
#         ;
#
#       # Test properties with ":"
#       assert.result
#         : split-conditional <define>FOO=A::B
#         ;
#
#       # Test conditional feature
#       assert.result <toolset>gcc,<toolset-gcc:version>3.0 <define>FOO
#         : split-conditional <toolset>gcc,<toolset-gcc:version>3.0:<define>FOO
#         ;
#
#       feature.finish-test property-test-temp ;
#   }
#