summaryrefslogtreecommitdiff
path: root/site_scons/mongo/generators.py
blob: b60c1fa3b00ea014fbc49ab95fa35ef408b884d6 (plain)
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
# -*- mode: python; -*-

import hashlib

# Default and alternative generator definitions go here.

# This is the tuple that will be returned by the buildInfo command and
# printed by the --version command-line option to mongod.
# Each tuple consists of:
#   key (string)
#   value (string)
#   should be included in buildInfo output (bool)
#   should be included in --version output (bool)
# The values will be passed through env.subst, so you can use any SCons variables you
# want to define them.
def default_buildinfo_environment_data():
    return (
        (
            'distmod',
            '$MONGO_DISTMOD',
            True,
            True,
        ),
        (
            'distarch',
            '$MONGO_DISTARCH',
            True,
            True,
        ),
        (
            'cc',
            '$CC_VERSION',
            True,
            False,
        ),
        (
            'ccflags',
            '$CCFLAGS',
            True,
            False,
        ),
        (
            'cxx',
            '$CXX_VERSION',
            True,
            False,
        ),
        (
            'cxxflags',
            '$CXXFLAGS',
            True,
            False,
        ),
        (
            'linkflags',
            '$LINKFLAGS',
            True,
            False,
        ),
        (
            'target_arch',
            '$TARGET_ARCH',
            True,
            True,
        ),
        (
            'target_os',
            '$TARGET_OS',
            True,
            False,
        ),
        (
            'cppdefines',
            '$CPPDEFINES',
            True,
            False,
        ),
    )


# If you want buildInfo and --version to be relatively empty, set
# MONGO_BUILDINFO_ENVIRONMENT_DATA = empty_buildinfo_environment_data()
def empty_buildinfo_environment_data():
    return ()


def default_variant_dir_generator(target, source, env, for_signature):

    if env.GetOption('cache') != None:
        return 'cached'

    # If an option should affect the variant directory, name it here.
    variant_options = [
        'opt',
        'dbg',
    ]

    # Hash the named options and their values, and take the first 8 characters of the hash as
    # the variant name
    hasher = hashlib.md5()
    for option in variant_options:
        hasher.update(option.encode('utf-8'))
        hasher.update(str(env.GetOption(option)).encode('utf-8'))
    variant_dir = str(hasher.hexdigest()[0:8])

    # If our option hash yields a well known hash, replace it with its name.
    known_variant_hashes = {
        '343e6678' : 'debug',
        '85fcf9b0' : 'opt',
        '981ce870' : 'debug',
        '9fface73' : 'optdebug',
        'c52b1cc3' : 'opt',
    }

    return known_variant_hashes.get(variant_dir, variant_dir)


def os_specific_variant_dir_generator(target, source, env, for_signature):
    return '-'.join([
        env['TARGET_OS'],
        default_variant_dir_generator(target, source, env, for_signature)])