0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-21 12:39:08 +01:00

SERVER-92768 add core binaries bazel conversion order. (#25216)

GitOrigin-RevId: 10829de36a7ecdc04aca668ae5f3884f0b4ee164
This commit is contained in:
Daniel Moody 2024-07-23 22:47:49 -05:00 committed by MongoDB Bot
parent 5981da81dd
commit 73380f5057
5 changed files with 102 additions and 19 deletions

View File

@ -236,7 +236,14 @@ def setup_args_parser():
"--bazel-order",
action="store_true",
default=False,
help="Find candidate nodes for merging by searching the graph for nodes with only one node which depends on them.",
help="Print an optimal order of target conversion for the bazel conversion.",
)
parser.add_argument(
"--bazel-order-core",
action="store_true",
default=False,
help="Print an optimal order of target conversion for the bazel conversion focused just on the core binaries.",
)
parser.add_argument(
@ -375,6 +382,9 @@ def main():
if args.bazel_order:
analysis.append(libdeps_analyzer.BazelOrder(libdeps_graph))
if args.bazel_order_core:
analysis.append(libdeps_analyzer.BazelOrderCore(libdeps_graph))
for analyzer_args in args.critical_edges:
analysis.append(
libdeps_analyzer.CriticalEdges(

View File

@ -713,6 +713,54 @@ class BazelOrder(Analyzer):
report[DependsReportTypes.BAZEL_ORDER.name] = self.run()
class BazelOrderCore(Analyzer):
"""Generate a topo sort order to covnert bazel targets."""
def __init__(self, dependency_graph):
"""Store graph and strip the nodes."""
super().__init__(dependency_graph)
@schema_check(schema_version=1)
def run(self):
"""Let networkx generate the list for us."""
order = []
mongod_graph = networkx.subgraph(
self._dependency_graph,
networkx.descendants(self._dependency_graph, "mongo/db/mongod") | {"mongo/db/mongod"},
)
mongos_graph = networkx.subgraph(
self._dependency_graph,
networkx.descendants(self._dependency_graph, "mongo/s/mongos") | {"mongo/s/mongos"},
)
mongo_graph = networkx.subgraph(
self._dependency_graph,
networkx.descendants(self._dependency_graph, "mongo/shell/mongo")
| {"mongo/shell/mongo"},
)
for node in networkx.lexicographical_topological_sort(
networkx.compose_all(
[
networkx.reverse_view(mongod_graph),
networkx.reverse_view(mongos_graph),
networkx.reverse_view(mongo_graph),
]
)
):
node_type = self._dependents_graph.nodes()[node].get(NodeProps.bin_type.name, "Unknown")
if node_type != "ThinTarget":
order.append({"type": node_type, "name": node})
return order
def report(self, report):
"""Add the symbol dependents list to the report."""
if DependsReportTypes.BAZEL_ORDER_CORE.name not in report:
report[DependsReportTypes.BAZEL_ORDER_CORE.name] = {}
report[DependsReportTypes.BAZEL_ORDER_CORE.name] = self.run()
class Efficiency(Analyzer):
"""Find efficiency of each public dependency originating from each node in a given set."""
@ -1049,6 +1097,29 @@ class GaJsonPrinter(GaPrinter):
return json.dumps(self.serialize(results))
def _bazel_order_print(results, report_name, title):
res = results[report_name]
builder_names = ("Bazel", "ThinTarget")
print(f"\n{title}:")
print(f"\tTotal targets: {len(res)}")
print(
f"\tTargets Converted: {len([node for node in res if node['type'].startswith(builder_names)])}"
)
print(
f"\tTargets left to convert: {len([node for node in res if not node['type'].startswith(builder_names)])}"
)
print("\tList of targets to convert (==== bars means independency groups):")
last_node = None
for num, node in enumerate(results[report_name]):
if last_node is None:
last_node = node["name"].lower()
if last_node != min(last_node, node["name"].lower()):
print("\t\t" + "=" * 60)
last_node = node["name"].lower()
target_type = "Bazel" if node["type"].startswith(builder_names) else "SCons"
print(f"\t\t{num}. {target_type}: {node['name']}")
class GaPrettyPrinter(GaPrinter):
"""Printer for pretty console output."""
@ -1160,26 +1231,15 @@ class GaPrettyPrinter(GaPrinter):
print(f"\t{node}")
if DependsReportTypes.BAZEL_ORDER.name in results:
res = results[DependsReportTypes.BAZEL_ORDER.name]
builder_names = ("Bazel", "ThinTarget")
print("\nBazel Target Conversion Order:")
print(f"\tTotal targets: {len(res)}")
print(
f"\tTargets Converted: {len([node for node in res if node['type'].startswith(builder_names)])}"
_bazel_order_print(
results, DependsReportTypes.BAZEL_ORDER.name, "Bazel Target Conversion Order"
)
print(
f"\tTargets left to convert: {len([node for node in res if not node['type'].startswith(builder_names)])}"
if DependsReportTypes.BAZEL_ORDER_CORE.name in results:
_bazel_order_print(
results,
DependsReportTypes.BAZEL_ORDER_CORE.name,
"Bazel Core Target Conversion Order",
)
print("\tList of targets to convert (==== bars means independency groups):")
last_node = None
for num, node in enumerate(results[DependsReportTypes.BAZEL_ORDER.name]):
if last_node is None:
last_node = node["name"].lower()
if last_node != min(last_node, node["name"].lower()):
print("\t\t" + "=" * 60)
last_node = node["name"].lower()
target_type = "Bazel" if node["type"].startswith(builder_names) else "SCons"
print(f"\t\t{num}. {target_type}: {node['name']}")
if LinterTypes.EFFICIENCY_LINT.name in results:
data = results[LinterTypes.EFFICIENCY_LINT.name]

View File

@ -73,6 +73,7 @@ class DependsReportTypes(Enum):
EFFICIENCY = auto()
BAZEL_CONV_CANDIDATES = auto()
BAZEL_ORDER = auto()
BAZEL_ORDER_CORE = auto()
class LinterTypes(Enum):

View File

@ -887,6 +887,17 @@ tasks:
content_type: text/plain
display_name: Bazel Target Conversions
- command: s3.put
params:
aws_key: ${aws_key}
aws_secret: ${aws_secret}
local_file: src/bazel_order_core.txt
remote_file: ${project}/${build_variant}/${revision}/artifacts/bazel_order_core.txt.${build_id}-${task_name}.${execution}
bucket: mciuploads
permissions: public-read
content_type: text/plain
display_name: Bazel Target Conversions Core Binaries
- command: s3.put
params:
aws_key: ${aws_key}

View File

@ -11,6 +11,7 @@ GRAPH_FILE=$(find build -name "libdeps.graphml")
python buildscripts/libdeps/analyzer_unittests.py
python buildscripts/libdeps/gacli.py --graph-file $GRAPH_FILE > results.txt
python buildscripts/libdeps/gacli.py --graph-file $GRAPH_FILE --lint= --bazel-order > bazel_order.txt
python buildscripts/libdeps/gacli.py --graph-file $GRAPH_FILE --lint= --bazel-order-core > bazel_order_core.txt
gzip $GRAPH_FILE
mv $GRAPH_FILE.gz .
targets_converted=$(grep "Targets Converted:" bazel_order.txt | cut -d":" -f 2)