summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorDaniel Moody <daniel.moody@mongodb.com>2020-12-16 06:21:08 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-12-16 07:27:36 +0000
commit6425c5740002ffd27f2682023b7ff36fba7af1ac (patch)
treec2a62bb6c0b321df3c49149cc77806ba99e2a310 /site_scons
parent0efb63b64441f935b5d06f4180d0969434327551 (diff)
downloadmongo-6425c5740002ffd27f2682023b7ff36fba7af1ac.tar.gz
SERVER-30815 Added linter to check for unnecessary PUBLIC libdeps, and added schema versioning.
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/libdeps_next.py84
1 files changed, 62 insertions, 22 deletions
diff --git a/site_scons/libdeps_next.py b/site_scons/libdeps_next.py
index 1df8f33b4d4..33b8ec502c2 100644
--- a/site_scons/libdeps_next.py
+++ b/site_scons/libdeps_next.py
@@ -882,14 +882,41 @@ def _get_node_with_ixes(env, node, node_builder_type):
_get_node_with_ixes.node_type_ixes = dict()
+def add_node_from(env, node):
+ from buildscripts.libdeps.libdeps_graph_enums import NodeProps
+
+ env.GetLibdepsGraph().add_nodes_from([(
+ str(node.abspath),
+ {
+ NodeProps.bin_type.name: node.builder.get_name(env),
+ NodeProps.shim.name: getattr(node.attributes, "is_shim", False)
+ })])
+
+def add_edge_from(env, depender_node, dependent_node, visibility, direct):
+ from buildscripts.libdeps.libdeps_graph_enums import EdgeProps
+
+ env.GetLibdepsGraph().add_edges_from([(
+ dependent_node,
+ depender_node,
+ {
+ EdgeProps.direct.name: direct,
+ EdgeProps.visibility.name: int(visibility)
+ })])
def add_libdeps_node(env, target, libdeps):
+
if str(target).endswith(env["SHLIBSUFFIX"]):
- t_str = _get_node_with_ixes(env, str(target.abspath), target.get_builder().get_name(env)).abspath
- env.GetLibdepsGraph().add_node(t_str)
+ node = _get_node_with_ixes(env, str(target.abspath), target.get_builder().get_name(env))
+ add_node_from(env, node)
+
for libdep in libdeps:
if str(libdep.target_node).endswith(env["SHLIBSUFFIX"]):
- env.GetLibdepsGraph().add_edge(str(libdep.target_node.abspath), t_str, visibility=libdep.dependency_type)
+ add_edge_from(
+ env,
+ str(node.abspath),
+ str(libdep.target_node.abspath),
+ visibility=libdep.dependency_type,
+ direct=True)
def get_libdeps_nodes(env, target, builder, debug=False, visibility_map=None):
@@ -1093,29 +1120,36 @@ def expand_libdeps_with_flags(source, target, env, for_signature):
def generate_libdeps_graph(env):
if env.get('SYMBOLDEPSSUFFIX', None):
import glob
- from buildscripts.libdeps.graph_analyzer import EdgeProps
find_symbols = env.Dir("$BUILD_DIR").path + "/libdeps/find_symbols"
+
+ env.GetLibdepsGraph().graph['invocation'] = " ".join([env['ESCAPE'](str(sys.executable))] + [env['ESCAPE'](arg) for arg in sys.argv])
+ env.GetLibdepsGraph().graph['git_hash'] = env['MONGO_GIT_HASH']
+ env.GetLibdepsGraph().graph['graph_schema_version'] = env['LIBDEPS_GRAPH_SCHEMA_VERSION']
+ env.GetLibdepsGraph().graph['build_dir'] = env.Dir('$BUILD_DIR').path
+
symbol_deps = []
for target, source in env.get('LIBDEPS_SYMBOL_DEP_FILES', []):
+
direct_libdeps = []
for direct_libdep in _get_sorted_direct_libdeps(source):
- env.GetLibdepsGraph().add_edges_from([(
- str(direct_libdep.target_node.abspath),
+ add_node_from(env, direct_libdep.target_node)
+ add_edge_from(
+ env,
str(source.abspath),
- {
- EdgeProps.direct.name: 1,
- EdgeProps.visibility.name: int(direct_libdep.dependency_type)
- })])
+ str(direct_libdep.target_node.abspath),
+ visibility=int(direct_libdep.dependency_type),
+ direct=True)
direct_libdeps.append(direct_libdep.target_node.abspath)
+
for libdep in _get_libdeps(source):
if libdep.abspath not in direct_libdeps:
- env.GetLibdepsGraph().add_edges_from([(
- str(libdep.abspath),
+ add_node_from(env, libdep)
+ add_edge_from(
+ env,
str(source.abspath),
- {
- EdgeProps.direct.name: 0,
- EdgeProps.visibility.name: int(deptype.Public)
- })])
+ str(libdep.abspath),
+ visibility=int(deptype.Public),
+ direct=False)
ld_path = ":".join([os.path.dirname(str(libdep)) for libdep in _get_libdeps(source)])
symbol_deps.append(env.Command(
@@ -1134,13 +1168,15 @@ def generate_libdeps_graph(env):
f.write(hashlib.sha256(json_str).hexdigest())
graph_hash = env.Command(target="$BUILD_DIR/libdeps/graph_hash.sha256",
- source=symbol_deps + [
- env.File("#SConstruct")] +
- glob.glob("**/SConscript", recursive=True) +
- [os.path.abspath(__file__)],
+ source=symbol_deps,
action=SCons.Action.FunctionAction(
write_graph_hash,
{"cmdstr": None}))
+ env.Depends(graph_hash, [
+ env.File("#SConstruct")] +
+ glob.glob("**/SConscript", recursive=True) +
+ [os.path.abspath(__file__),
+ env.File('$BUILD_DIR/mongo/util/version_constants.h')])
graph_node = env.Command(
target=env.get('LIBDEPS_GRAPH_FILE', None),
@@ -1208,6 +1244,7 @@ def generate_graph(env, target, source):
import fileinput
import networkx
import json
+ from buildscripts.libdeps.libdeps_graph_enums import EdgeProps, NodeProps
for symbol_deps_file in source:
with open(str(symbol_deps_file)) as f:
@@ -1221,11 +1258,13 @@ def generate_graph(env, target, source):
symbols[lib].append(symbol)
for lib in symbols:
+
env.GetLibdepsGraph().add_edges_from([(
os.path.abspath(lib).strip(),
os.path.abspath(str(symbol_deps_file)[:-len(env['SYMBOLDEPSSUFFIX'])]),
- {"symbols": " ".join(symbols[lib]) })])
-
+ {EdgeProps.symbols.name: " ".join(symbols[lib]) })])
+ node = env.File(str(symbol_deps_file)[:-len(env['SYMBOLDEPSSUFFIX'])])
+ add_node_from(env, node)
libdeps_graph_file = f"{env.Dir('$BUILD_DIR').path}/libdeps/libdeps.graphml"
networkx.write_graphml(env.GetLibdepsGraph(), libdeps_graph_file, named_key_ids=True)
@@ -1327,6 +1366,7 @@ def setup_environment(env, emitting_shared=False, debug='off', linting='on', san
env['LIBDEPS_SYMBOL_DEP_FILES'] = symbol_deps
env['LIBDEPS_GRAPH_FILE'] = env.File("${BUILD_DIR}/libdeps/libdeps.graphml")
+ env['LIBDEPS_GRAPH_SCHEMA_VERSION'] = 1
env["SYMBOLDEPSSUFFIX"] = '.symbol_deps'
# Now we will setup an emitter, and an additional action for several