summaryrefslogtreecommitdiff
path: root/site_scons/site_tools/mongo_benchmark.py
blob: b2a1750e3d2eeac0c2c23d06d796437287887ce7 (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
"""Pseudo-builders for building and registering benchmarks.
"""
from SCons.Script import Action

def exists(env):
    return True

_benchmarks = []
def register_benchmark(env, test):
    _benchmarks.append(test.path)
    env.Alias('$BENCHMARK_ALIAS', test)

def benchmark_list_builder_action(env, target, source):
    ofile = open(str(target[0]), 'wb')
    try:
        for s in _benchmarks:
            print '\t' + str(s)
            ofile.write('%s\n' % s)
    finally:
        ofile.close()

def build_benchmark(env, target, source, **kwargs):

    bmEnv = env.Clone()
    bmEnv.InjectThirdPartyIncludePaths(libraries=['benchmark'])

    if bmEnv.TargetOSIs('windows'):
        bmEnv.Append(LIBS=["ShLwApi.lib"])

    libdeps = kwargs.get('LIBDEPS', [])
    libdeps.append('$BUILD_DIR/mongo/unittest/benchmark_main')

    kwargs['LIBDEPS'] = libdeps
    kwargs['INSTALL_ALIAS'] = ['benchmarks']

    result = bmEnv.Program(target, source, **kwargs)
    bmEnv.RegisterBenchmark(result[0])
    hygienic = bmEnv.GetOption('install-mode') == 'hygienic'
    if not hygienic:
        bmEnv.Install("#/build/benchmark/", result[0])
    return result

def generate(env):
    env.Command('$BENCHMARK_LIST', env.Value(_benchmarks),
            Action(benchmark_list_builder_action, "Generating $TARGET"))
    env.AddMethod(register_benchmark, 'RegisterBenchmark')
    env.AddMethod(build_benchmark, 'Benchmark')
    env.Alias('$BENCHMARK_ALIAS', '$BENCHMARK_LIST')