Skip to content

Commit cc68e42

Browse files
dmoody256Evergreen Agent
authored andcommitted
SERVER-49761 Added libdeps rule for leaf node no dependencies
1 parent 8cd9ddc commit cc68e42

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

site_scons/libdeps.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,19 @@ def _raise_libdep_lint_exception(self, message):
179179
else:
180180
raise LibdepLinterError(message)
181181

182-
def _check_for_lint_tags(self, lint_tag, env=None):
182+
def _check_for_lint_tags(self, lint_tag, env=None, inclusive_tag=False):
183183
"""
184184
Used to get the lint tag from the environment,
185185
and if printing instead of raising exceptions,
186186
will ignore the tags.
187187
"""
188188

189-
# ignore LIBDEP_TAGS if printing was selected
190-
if self.__class__.print_linter_errors:
189+
# If print mode is on, we want to make sure to bypass checking
190+
# exclusive tags so we can make sure the exceptions are not excluded
191+
# and are printed. If it's an inclusive tag, we want to ignore this
192+
# early return completely, because we want to make sure the node
193+
# gets included for checking, and the exception gets printed.
194+
if not inclusive_tag and self.__class__.print_linter_errors:
191195
return False
192196

193197
target_env = env if env else self.env
@@ -202,6 +206,29 @@ def _get_deps_dependents(self, env=None):
202206
deps_dependents += target_env.get(Constants.ProgdepsDependents, [])
203207
return deps_dependents
204208

209+
@linter_rule
210+
def linter_rule_leaf_node_no_deps(self, libdep):
211+
"""
212+
LIBDEP RULE:
213+
Nodes marked explicitly as a leaf node should not have any dependencies,
214+
unless those dependencies are explicitly marked as allowed as leaf node
215+
dependencies.
216+
"""
217+
if not self._check_for_lint_tags('lint-leaf-node-no-deps', inclusive_tag=True):
218+
return
219+
220+
# Ignore dependencies that explicitly exempt themselves.
221+
if self._check_for_lint_tags('lint-leaf-node-allowed-dep', libdep.target_node.env):
222+
return
223+
224+
target_type = self.target[0].builder.get_name(self.env)
225+
lib = os.path.basename(str(libdep))
226+
self._raise_libdep_lint_exception(
227+
textwrap.dedent(f"""\
228+
{target_type} '{self.target[0]}' has dependency '{lib}' and is marked explicitly as a leaf node,
229+
and '{lib}' does not exempt itself as an exception to the rule."""
230+
))
231+
205232
@linter_rule
206233
def linter_rule_no_dups(self, libdep):
207234
"""

src/mongo/util/SConscript

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ env.Library(
7171
source=[
7272
'boost_assert_shim.cpp'
7373
],
74-
# NOTE: This library *must not* depend on any mongodb code
75-
LIBDEPS=[],
74+
LIBDEPS_TAGS=[
75+
# NOTE: This library *must not* depend on any mongodb code
76+
'lint-leaf-node-no-deps',
77+
],
7678
)
7779

7880
env.SConscript(

src/third_party/SConscript

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,13 @@ gperftoolsEnv.Library(
543543
"shim_allocator.cpp",
544544
],
545545
DISABLE_ALLOCATOR_SHIM_INJECTION=True,
546+
LIBDEPS_TAGS=[
547+
# The shim allocator must be linked to every node, including what would
548+
# be considered a leaf node to ensure the system allocator
549+
# is not linked in before tcmalloc. This tag allows nodes tagged as
550+
# leaf nodes to still get the correct allocator.
551+
'lint-leaf-node-allowed-dep'
552+
],
546553
)
547554

548555

0 commit comments

Comments
 (0)