summaryrefslogtreecommitdiff
path: root/src/SConscript
blob: 0c3a05f8d81c5911db5a24cbeb55fc2b9d51300e (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
# -*- mode: python; -*-
#
# This is the principle SConscript file, invoked by the SConstruct.  Its job is
# to delegate to any and all per-module SConscript files.

from functools import partial

from site_scons.mongo import insort_wrapper

import SCons

Import('env')
Import('get_option')
Import('has_option')
Import('module_sconscripts')


def shim_hack(target, source, env, inject_target=None, exclusions=None):
    if exclusions is None:
        exclusions = set(inject_target)
    elif isinstance(exclusions, str):
        exclusions = {exclusions, inject_target}
    elif isinstance(exclusions, (list, set)):
        exclusions = set(exclusions)
        exclusions.add(inject_target)

    # If we allowed conftests to become dependent, any TryLink
    # that happened after we made the below modifications would
    # cause the configure steps to try to compile tcmalloc and any
    # of its dependencies. Oops!
    if any('conftest' in str(t) for t in target):
        return target, source

    # It is possible that 'env' isn't a unique
    # OverrideEnvironment, since if you didn't pass any kw args
    # into your builder call, you just reuse the env you were
    # called with. That could mean that we see the same
    # environment here multiple times. But that is really OK,
    # since the operation we are performing would be performed on
    # all of them anyway.
    libdeps_no_inherit = set(env.get('LIBDEPS_NO_INHERIT', []))
    exclusions.update(libdeps_no_inherit)

    if f"$BUILD_DIR/{inject_target}" not in exclusions:
        lds = env.get('LIBDEPS', [])
        shim_target = f"$BUILD_DIR/{inject_target}"
        if shim_target not in lds:
            insort_wrapper(lds, shim_target)
            env['LIBDEPS'] = lds

    return target, source


def hack_builder_emitters(env, hack_method):
    for builder_name in ('Program', 'SharedLibrary', 'LoadableModule', 'StaticLibrary'):
        builder = env['BUILDERS'][builder_name]
        base_emitter = builder.emitter
        builder.emitter = SCons.Builder.ListEmitter([hack_method, base_emitter])


if get_option("build-tools") == "next":
    # Add any "global" dependencies here. This is where we make every build node
    # depend on a list of other build nodes, such as an allocator or libunwind
    # or libstdx or similar.
    env.AppendUnique(
        LIBDEPS_GLOBAL=[
            '$BUILD_DIR/third_party/shim_allocator',
        ],
    )
else:
    hack_builder_emitters(
        env,
        partial(
            shim_hack,
            inject_target='third_party/shim_allocator',
            exclusions='gperftools/gperftools'))


# NOTE: We must do third_party first as it adds methods to the environment
# that we need in the mongo sconscript
env.SConscript('third_party/SConscript', exports=['env'])

# Inject common dependencies from third_party globally for all core mongo code
# and modules. Ideally, pcre wouldn't be here, but enough things require it
# now that it seems hopeless to remove it.
env.InjectThirdParty(libraries=[
    'abseil-cpp',
    'boost',
    'fmt',
    'pcre',
    'safeint',
    'variant',
])

# Run the core mongodb SConscript.
env.SConscript('mongo/SConscript', exports=['env'])

# Run SConscripts for any modules in play
env.SConscript(module_sconscripts, exports=['env'])