Skip to content

Instantly share code, notes, and snippets.

@techtonik
Last active September 4, 2015 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techtonik/8f53e9866beed570ead4 to your computer and use it in GitHub Desktop.
Save techtonik/8f53e9866beed570ead4 to your computer and use it in GitHub Desktop.
SCons - Dump Build Graph
{
"nodes": [
"wesnothd",
"wesnothd.exe",
"ban.o",
"ban.cpp",
"forum_user_handler.o",
"forum_user_handler.cpp",
"game.o",
"game.cpp",
"input_stream.o",
"input_stream.cpp",
"metrics.o",
"metrics.cpp",
"player.o",
"player.cpp",
"player_network.o",
"player_network.cpp",
"proxy.o",
"proxy.cpp",
"room.o",
"room.cpp",
"room_manager.o",
"room_manager.cpp",
"sample_user_handler.o",
"sample_user_handler.cpp",
"simple_wml.o",
"simple_wml.cpp",
"user_handler.o",
"user_handler.cpp",
"server.o",
"server.cpp",
"libwesnoth_core.a",
"color_range.o",
"color_range.cpp",
"config.o",
"config.cpp",
"hash.o",
"hash.cpp",
"log.o",
"log.cpp",
"map.o",
"map.cpp",
"map_location.o",
"map_location.cpp",
"md5.o",
"md5.cpp",
"mt_rng.o",
"mt_rng.cpp",
"seed_rng.o",
"seed_rng.cpp",
"network.o",
"network.cpp",
"terrain_type_data.o",
"terrain_type_data.cpp",
"thread.o",
"thread.cpp",
"tstring.o",
"tstring.cpp",
"util.o",
"util.cpp",
"version.o",
"version.cpp",
"binary_or_text.o",
"binary_or_text.cpp",
"parser.o",
"parser.cpp",
"preprocessor.o",
"preprocessor.cpp",
"schema_validator.o",
"schema_validator.cpp",
"string_utils.o",
"string_utils.cpp",
"tokenizer.o",
"tokenizer.cpp",
"unicode.o",
"unicode.cpp",
"validator.o",
"validator.cpp",
"tag.o",
"tag.cpp",
"network_worker.o",
"network_worker.cpp",
"game_config.o",
"game_config.cpp",
"filesystem_common.o",
"filesystem_common.cpp",
"filesystem_boost.o",
"filesystem_boost.cpp",
"gettext_boost.o",
"gettext_boost.cpp",
"libwesnothd.a",
"loadscreen_empty.o",
"loadscreen_empty.cpp",
"dummy_video.o",
"dummy_video.cpp",
"wesnothd.o",
"wesnothd.rc"
],
"edges": [
["wesnothd", "wesnothd.exe"],
["wesnothd.exe", "ban.o"],
["wesnothd.exe", "forum_user_handler.o"],
["wesnothd.exe", "game.o"],
["wesnothd.exe", "input_stream.o"],
["wesnothd.exe", "metrics.o"],
["wesnothd.exe", "player.o"],
["wesnothd.exe", "player_network.o"],
["wesnothd.exe", "proxy.o"],
["wesnothd.exe", "room.o"],
["wesnothd.exe", "room_manager.o"],
["wesnothd.exe", "sample_user_handler.o"],
["wesnothd.exe", "simple_wml.o"],
["wesnothd.exe", "user_handler.o"],
["wesnothd.exe", "server.o"],
["wesnothd.exe", "libwesnoth_core.a"],
["wesnothd.exe", "libwesnothd.a"],
["wesnothd.exe", "wesnothd.o"],
["ban.o", "ban.cpp"],
["forum_user_handler.o", "forum_user_handler.cpp"],
["game.o", "game.cpp"],
["input_stream.o", "input_stream.cpp"],
["metrics.o", "metrics.cpp"],
["player.o", "player.cpp"],
["player_network.o", "player_network.cpp"],
["proxy.o", "proxy.cpp"],
["room.o", "room.cpp"],
["room_manager.o", "room_manager.cpp"],
["sample_user_handler.o", "sample_user_handler.cpp"],
["simple_wml.o", "simple_wml.cpp"],
["user_handler.o", "user_handler.cpp"],
["server.o", "server.cpp"],
["libwesnoth_core.a", "color_range.o"],
["libwesnoth_core.a", "config.o"],
["libwesnoth_core.a", "hash.o"],
["libwesnoth_core.a", "log.o"],
["libwesnoth_core.a", "map.o"],
["libwesnoth_core.a", "map_location.o"],
["libwesnoth_core.a", "md5.o"],
["libwesnoth_core.a", "mt_rng.o"],
["libwesnoth_core.a", "seed_rng.o"],
["libwesnoth_core.a", "network.o"],
["libwesnoth_core.a", "terrain_type_data.o"],
["libwesnoth_core.a", "thread.o"],
["libwesnoth_core.a", "tstring.o"],
["libwesnoth_core.a", "util.o"],
["libwesnoth_core.a", "version.o"],
["libwesnoth_core.a", "binary_or_text.o"],
["libwesnoth_core.a", "parser.o"],
["libwesnoth_core.a", "preprocessor.o"],
["libwesnoth_core.a", "schema_validator.o"],
["libwesnoth_core.a", "string_utils.o"],
["libwesnoth_core.a", "tokenizer.o"],
["libwesnoth_core.a", "unicode.o"],
["libwesnoth_core.a", "validator.o"],
["libwesnoth_core.a", "tag.o"],
["libwesnoth_core.a", "network_worker.o"],
["libwesnoth_core.a", "game_config.o"],
["libwesnoth_core.a", "filesystem_common.o"],
["libwesnoth_core.a", "filesystem_boost.o"],
["libwesnoth_core.a", "gettext_boost.o"],
["color_range.o", "color_range.cpp"],
["config.o", "config.cpp"],
["hash.o", "hash.cpp"],
["log.o", "log.cpp"],
["map.o", "map.cpp"],
["map_location.o", "map_location.cpp"],
["md5.o", "md5.cpp"],
["mt_rng.o", "mt_rng.cpp"],
["seed_rng.o", "seed_rng.cpp"],
["network.o", "network.cpp"],
["terrain_type_data.o", "terrain_type_data.cpp"],
["thread.o", "thread.cpp"],
["tstring.o", "tstring.cpp"],
["util.o", "util.cpp"],
["version.o", "version.cpp"],
["binary_or_text.o", "binary_or_text.cpp"],
["parser.o", "parser.cpp"],
["preprocessor.o", "preprocessor.cpp"],
["schema_validator.o", "schema_validator.cpp"],
["string_utils.o", "string_utils.cpp"],
["tokenizer.o", "tokenizer.cpp"],
["unicode.o", "unicode.cpp"],
["validator.o", "validator.cpp"],
["tag.o", "tag.cpp"],
["network_worker.o", "network_worker.cpp"],
["game_config.o", "game_config.cpp"],
["filesystem_common.o", "filesystem_common.cpp"],
["filesystem_boost.o", "filesystem_boost.cpp"],
["gettext_boost.o", "gettext_boost.cpp"],
["libwesnothd.a", "loadscreen_empty.o"],
["libwesnothd.a", "dummy_video.o"],
["loadscreen_empty.o", "loadscreen_empty.cpp"],
["dummy_video.o", "dummy_video.cpp"],
["wesnothd.o", "wesnothd.rc"]
]
}
#
# Dump graph of build nodes
#
import sys
from collections import OrderedDict
from SCons.Node import arg2nodes_lookups
def nodename(node):
nodename = node.name
#return '<' + str(node.__class__.__name__) + '> ' + nodename
return nodename
def dump_graph(start, printto=sys.stdout):
graph = OrderedDict()
graph['nodes'] = []
graph['edges'] = []
# use node.sources to avoid triggerring scanners in node.children()
queue = [(start, 0)] # node, indentation
visited = []
while len(queue):
node, indent = queue.pop()
printto.write((' ' * indent) + ' ' + nodename(node) + '\n')
graph['nodes'].append(nodename(node))
#print dumpattr(node)
#print node.children()
for child in reversed(node.sources):
queue.append((child, indent+1))
for child in node.sources:
graph['edges'].append([nodename(node), nodename(child)])
with open('treelog.json', 'wb') as jg:
jg.write("""\
{
"nodes": [
""")
for n in graph['nodes'][:-1]:
jg.write("""\
"%s",
""" % n)
jg.write("""\
"%s"
],
"edges": [
""" % graph['nodes'][-1])
if not graph['edges']:
# [ ] this doesn't look normal
fail
for l in graph['edges'][:-1]:
print l
jg.write("""\
["%s", "%s"],
""" % tuple(l))
jg.write("""\
["%s", "%s"]
]
}
""" % tuple(graph['edges'][-1]))
treelog = open('treelog.txt', 'wb')
for t in BUILD_TARGETS:
if type(t) != str:
node = t
else:
for lookup in arg2nodes_lookups:
node = lookup(t)
if node == None:
print("Error finding Node object for target '%s'" % t)
dump_graph(node, printto=treelog)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment