Generating dependency matrix... Squaring dependency matrix... Squaring dependency matrix again... Squaring dependency matrix again... Squaring dependency matrix again... ban.cpp 4 base64.cpp 1 biome.cpp 27 camera.cpp 61 cavegen.cpp 45 chat.cpp 13 client.cpp 70 clientmap.cpp 62 clientobject.cpp 14 clientserver.cpp 9 clouds.cpp 21 collision.cpp 41 connection.cpp 24 content_abm.cpp 58 content_cao.cpp 52 content_cso.cpp 37 content_mapblock.cpp 26 content_mapnode.cpp 17 content_nodemeta.cpp 21 content_sao.cpp 59 convert_json.cpp 19 craftdef.cpp 20 debug.cpp 5 defaultsettings.cpp 18 dungeongen.cpp 45 emerge.cpp 78 environment.cpp 68 farmesh.cpp 55 filecache.cpp 9 filesys.cpp 4 game.cpp 85 genericobject.cpp 12 guiChatConsole.cpp 59 guiDeathScreen.cpp 56 guiEngine.cpp 43 guiFileSelectMenu.cpp 10 guiFormSpecMenu.cpp 27 guiKeyChangeMenu.cpp 60 guiMessageMenu.cpp 16 guiPasswordChange.cpp 56 guiPauseMenu.cpp 21 guiTextInputMenu.cpp 28 guiVolumeChange.cpp 57 hud.cpp 56 intlGUIEditBox.cpp 8 inventory.cpp 20 inventorymanager.cpp 53 itemdef.cpp 33 keycode.cpp 18 light.cpp 6 localplayer.cpp 43 log.cpp 6 main.cpp 69 map.cpp 66 mapblock.cpp 41 mapblock_mesh.cpp 48 mapgen.cpp 55 mapgen_indev.cpp 46 mapgen_math.cpp 60 mapgen_singlenode.cpp 58 mapgen_v6.cpp 65 mapgen_v7.cpp 67 mapnode.cpp 20 mapsector.cpp 53 mesh.cpp 8 mods.cpp 22 nameidmapping.cpp 9 nodedef.cpp 27 nodemetadata.cpp 19 nodetimer.cpp 10 noise.cpp 10 object_properties.cpp 9 particles.cpp 43 pathfinder.cpp 47 player.cpp 33 porting.cpp 12 quicktune.cpp 4 rollback.cpp 24 rollback_interface.cpp 40 script/common/c_content.cpp 67 script/common/c_converter.cpp 9 script/common/c_internal.cpp 7 script/common/c_types.cpp 11 script/cpp_api/s_base.cpp 24 script/cpp_api/s_entity.cpp 16 script/cpp_api/s_env.cpp 49 script/cpp_api/s_inventory.cpp 24 script/cpp_api/s_item.cpp 56 script/cpp_api/s_mainmenu.cpp 11 script/cpp_api/s_node.cpp 57 script/cpp_api/s_nodemeta.cpp 57 script/cpp_api/s_player.cpp 6 script/cpp_api/s_server.cpp 11 script/cpp_api/scriptapi.cpp 28 script/lua_api/l_base.cpp 24 script/lua_api/l_craft.cpp 58 script/lua_api/l_env.cpp 80 script/lua_api/l_inventory.cpp 57 script/lua_api/l_item.cpp 71 script/lua_api/l_mainmenu.cpp 75 script/lua_api/l_mapgen.cpp 67 script/lua_api/l_nodemeta.cpp 45 script/lua_api/l_nodetimer.cpp 40 script/lua_api/l_noise.cpp 23 script/lua_api/l_object.cpp 64 script/lua_api/l_particles.cpp 55 script/lua_api/l_rollback.cpp 57 script/lua_api/l_server.cpp 56 script/lua_api/l_util.cpp 29 script/lua_api/l_vmanip.cpp 56 script/lua_api/luaapi.cpp 56 serialization.cpp 9 server.cpp 93 serverlist.cpp 21 serverobject.cpp 18 sha1.cpp 1 shader.cpp 22 sky.cpp 10 socket.cpp 18 sound.cpp 6 sound_openal.cpp 15 staticobject.cpp 12 subgame.cpp 18 test.cpp 50 tile.cpp 24 tool.cpp 19 treegen.cpp 37 util/directiontables.cpp 3 util/numeric.cpp 7 util/pointedthing.cpp 9 util/serialize.cpp 8 util/string.cpp 11 util/timetaker.cpp 4 voxel.cpp 35 voxelalgorithms.cpp 17 #!/usr/bin/env python2 # -*- coding: utf-8 -*- # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # COPYING for more details. # 2013-08-11: made by kahrl import os import sys import re import getopt scriptpath = os.path.abspath(__file__) basepath = os.path.realpath(os.path.join(os.path.dirname(scriptpath), '../src')) os.chdir(basepath) def is_cpp(name): return name[-4:] == '.cpp' def is_h(name): return name[-2:] == '.h' def get_codefiles_set(): subpaths = ['', 'script/common', 'script/cpp_api', 'script/lua_api', 'util'] codefiles_set = set() for subpath in subpaths: for filename in os.listdir(os.path.join('.', subpath)): filepath = os.path.join(subpath, filename) if os.path.isfile(filepath): if is_cpp(filepath) or is_h(filepath): codefiles_set.add(filepath) return codefiles_set def get_included_file(includetext, curpath, codefiles_set): includepaths = [curpath, '', 'script'] for includepath in includepaths: filepath = os.path.normpath(os.path.join(includepath, includetext)) if filepath in codefiles_set: return filepath return None def get_includes(filepath, codefiles_set): includes_set = set() curpath = os.path.dirname(filepath) with open(filepath) as f: for line in f: match = re.match(r'^\s*#\s*include\s+"([^"]+)"\s*$', line) if match: included_file = get_included_file( match.group(1), curpath, codefiles_set) if included_file is not None: includes_set.add(included_file) else: #print(repr(line)) pass return sorted(includes_set) def make_depend_matrix(codefiles, codefiles_set): n = len(codefiles) mat = [[0 for j in range(0,n)] for i in range(0,n)] codefiles_index = dict() for i in range(0,n): codefiles_index[codefiles[i]] = i for i in range(0,n): filepath = codefiles[i] for include in get_includes(filepath, codefiles_set): j = codefiles_index[include] mat[i][j] = 1 mat[i][i] = 1 return mat def square_depend_matrix(mat): n = len(mat) mat2 = [[0 for j in range(0,n)] for i in range(0,n)] changed = False for i in range(0,n): for j in range(0,n): if mat[i][j] == 0: for k in range(0,n): if mat[i][k] != 0 and mat[k][j] != 0: mat2[i][j] = 1 changed = True break else: mat2[i][j] = 1 if changed: for i in range(0,n): mat[i] = mat2[i] return changed def print_depends(codefiles, mat, only_sources): n = len(codefiles) for i in range(0,n): if not only_sources or is_cpp(codefiles[i]): for j in range(0,n): if i != j and mat[i][j] != 0: print(codefiles[i] + '\t' + codefiles[j]) def print_depend_stats(codefiles, mat, only_sources): n = len(codefiles) for i in range(0,n): if not only_sources or is_cpp(codefiles[i]): # minus one because the diagonal of mat is ones, # but we don't want to count it print(codefiles[i] + '\t' + str(mat[i].count(1)-1)) codefiles_set = get_codefiles_set() codefiles = sorted(codefiles_set) sys.stderr.write('Generating dependency matrix...\n') mat = make_depend_matrix(codefiles, codefiles_set) sys.stderr.write('Squaring dependency matrix...\n') while square_depend_matrix(mat): sys.stderr.write('Squaring dependency matrix again...\n') print_depend_stats(codefiles, mat, True)