def _init_fw_from_dot_data(self, fw, dot_data, with_qt): def target_from_node(node): return node.name.replace("KF5", "") src_handle = gv.readstring(dot_data) targets = set() for node_handle in gvutils.get_node_list(src_handle): node = gvutils.Node(node_handle) if node.shape in TARGET_SHAPES and self._want(node): target = target_from_node(node) targets.add(target) fw.add_target(target) for edge_handle in gvutils.get_edge_list(src_handle): edge = gvutils.Edge(edge_handle) target = target_from_node(edge.tail) if target in targets and self._want(edge.head): dep_target = target_from_node(edge.head) fw.add_target_dependency(target, dep_target)
def preprocess(fname): graph_handle = gv.read(fname) txt = open(fname).read() targets = [] # Replace the generated node names with their label. CMake generates a graph # like this: # # "node0" [ label="KF5DNSSD" shape="polygon"]; # "node1" [ label="Qt5::Network" shape="ellipse"]; # "node0" -> "node1" # # And we turn it into this: # # "KF5DNSSD" [ label="KF5DNSSD" shape="polygon"]; # "Qt5::Network" [ label="Qt5::Network" shape="ellipse"]; # "KF5DNSSD" -> "Qt5::Network" # # Using real framework names as labels makes it possible to merge multiple # .dot files. for node_handle in gvutils.get_node_list(graph_handle): node = gvutils.Node(node_handle) label = node.label.replace("KF5::", "") if node.shape in TARGET_SHAPES: targets.append(label) txt = txt.replace('"' + node.name + '"', '"' + label + '"') # Sometimes cmake will generate an entry for the target alias, something # like this: # # "node9" [ label="KParts" shape="polygon"]; # ... # "node15" [ label="KF5::KParts" shape="ellipse"]; # ... # # After our node renaming, this ends up with a second "KParts" node # definition, which we need to get rid of. for target in targets: rx = r' *"' + target + '".*label="KF5::' + target + '".*shape="ellipse".*;' txt = re.sub(rx, '', txt) return txt