summaryrefslogtreecommitdiff
path: root/src/mongo/tools/mongo_tidy_checks/SConscript
blob: eab97419218bc3f8e26e462158c0071997905d23 (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
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
Import('env')

from buildscripts.toolchains import DEFAULT_DATA_FILE, ToolchainConfig, ToolchainPlatform

toolchain_clang_tidy_dev_found = False
toolchain_found = False
base_toolchain_bin = None
try:
    toolchain_config = ToolchainConfig(DEFAULT_DATA_FILE, ToolchainPlatform('default'))
    toolchain_found = toolchain_config.base_path.exists()
    base_toolchain_bin = (toolchain_config.base_path / toolchain_config.aliases['stable'] / 'bin')
    base_revision_path = (base_toolchain_bin / 'clang-tidy').resolve().parent.parent

    tidy_include = base_revision_path / 'include'
    tidy_lib = base_revision_path / 'lib'

    toolchain_clang_tidy_dev_found = (tidy_include / 'clang-tidy' / 'ClangTidy.h').exists()

except FileNotFoundError:
    pass

if toolchain_found and not toolchain_clang_tidy_dev_found:
    # If there was a toolchain but its not setup right, issue a warning about this.
    print(
        "Could not find not find clang-tidy headers in toolchain, not building mongo custom checks module."
    )

if not toolchain_found or not toolchain_clang_tidy_dev_found:
    Return()

env = env.Clone()

# TODO SERVER-73731
# Instead of hardcoding these flags, we should load the flags used by the toolchain here
env['CXX'] = [f'{base_toolchain_bin}/g++']
env['SHCXX'] = [f'{base_toolchain_bin}/g++']
env['LINK'] = [f'{base_toolchain_bin}/g++']
env['SHLINK'] = [f'{base_toolchain_bin}/g++']
env['CPPPATH'] = [str(tidy_include)]
env['LIBPATH'] = []
env['CCFLAGS'] = [
    '-DGTEST_HAS_RTTI=0',
    '-D_GNU_SOURCE',
    '-D__STDC_CONSTANT_MACROS',
    '-D__STDC_FORMAT_MACROS',
    '-D__STDC_LIMIT_MACROS',
    '-fPIC',
    '-fvisibility-inlines-hidden',
    '-Werror=date-time',
    '-Wall',
    '-Wextra',
    '-Wno-unused-parameter',
    '-Wwrite-strings',
    '-Wcast-qual',
    '-Wno-missing-field-initializers',
    '-pedantic',
    '-Wno-long-long',
    '-Wimplicit-fallthrough',
    '-Wno-maybe-uninitialized',
    '-Wno-class-memaccess',
    '-Wno-redundant-move',
    '-Wno-noexcept-type',
    '-Wdelete-non-virtual-dtor',
    '-Wsuggest-override',
    '-Wno-comment',
    '-fdiagnostics-color',
    '-ffunction-sections',
    '-fdata-sections',
    '-fno-common',
    '-Woverloaded-virtual',
    '-fno-strict-aliasing',
    '-O3',
    '-g2',
    '-DNDEBUG',
    '-fPIC',
    '-fno-exceptions',
    '-fno-rtti',
    '-std=c++17',
]
env['LINKFLAGS'] = []
env['SHLINKFLAGS'] = [
    '-fPIC',
    '-fvisibility-inlines-hidden',
    '-Werror=date-time',
    '-Wall',
    '-Wextra',
    '-Wno-unused-parameter',
    '-Wwrite-strings',
    '-Wcast-qual',
    '-Wno-missing-field-initializers',
    '-pedantic',
    '-Wno-long-long',
    '-Wimplicit-fallthrough',
    '-Wno-maybe-uninitialized',
    '-Wno-class-memaccess',
    '-Wno-redundant-move',
    '-Wno-noexcept-type',
    '-Wdelete-non-virtual-dtor',
    '-Wsuggest-override',
    '-Wno-comment',
    '-fdiagnostics-color',
    '-ffunction-sections',
    '-fdata-sections',
    '-fno-common',
    '-Woverloaded-virtual',
    '-fno-strict-aliasing',
    '-O3',
    '-DNDEBUG',
    '-Wl,-z,nodelete',
    f'-Wl,-rpath-link,{tidy_lib}',
    '-Wl,-O3',
    '-Wl,--gc-sections',
    '-shared',
    r'-Wl,-rpath,"\$$ORIGIN/../lib"',
]
env['CXXFLAGS'] = []
env['CFLAGS'] = []
env['FORCEINCLUDES'] = []
env['LIBDEPS_TAG_EXPANSIONS'] = []

mongo_custom_check = env.SharedLibrary(
    target="mongo_tidy_checks",
    source=[
        "MongoHeaderBracketCheck.cpp",
        "MongoUninterruptibleLockGuardCheck.cpp",
        "MongoCctypeCheck.cpp",
        "MongoCxx20BannedIncludesCheck.cpp",
        "MongoStdOptionalCheck.cpp",
        "MongoVolatileCheck.cpp",
        "MongoStdAtomicCheck.cpp",
        "MongoTidyModule.cpp",
        "MongoTraceCheck.cpp",
        "MongoMutexCheck.cpp",
        "MongoAssertCheck.cpp",
        "MongoFCVConstantCheck.cpp",
        "MongoUnstructuredLogCheck.cpp",
    ],
    LIBDEPS_NO_INHERIT=[
        '$BUILD_DIR/third_party/shim_allocator',
    ],
    AIB_COMPONENT='mongo-tidy-checks',
)

env.AutoInstall(
    target='$PREFIX_LIBDIR',
    source=mongo_custom_check,
    AIB_ROLE='runtime',
    AIB_COMPONENT='mongo-tidy-checks',
)
mongo_tidy_module = env.GetAutoInstalledFiles(mongo_custom_check[0])[0]

# because compiledb is required for use with clang-tidy and potentially clang-tidy is
# loading the module, we add the module to the compiledb alias.
env.Alias("compiledb", mongo_tidy_module)

env.SConscript('tests/SConscript', exports=['env', 'mongo_tidy_module', 'base_toolchain_bin'])