コード例 #1
0
def analyze(write_postscript=False):
    root = path(ROOTDIRNAME)
    headers = list(root.walkfiles('*.h'))
    sources = headers + list(root.walkfiles('*.cpp'))
    file2inc = get_file2inc(sources)

    moduleUser2provider = {}
    dirUser2provider = {}
    fileUser2provider = {}
    unknownIncludes = {}
    dirclusters = {}
    fill_dep_infos(file2inc, fileUser2provider, dirUser2provider,
                   moduleUser2provider, unknownIncludes, dirclusters)

    # write module dep graph
    out = []
    illegalModuleDeps = []
    for user, providers in sorted(moduleUser2provider.items()):
        for provider in sorted(providers):
            if user != provider:
                out.append('    "' + user + '" -> "' + provider + '"')
                msg = check_dep_error(ALLOWED_MODULE_DEPS, user, provider)
                if msg:
                    illegalModuleDeps.append(msg)
    write_dot_file('%s.dot' % MODULE_DEPS_OUT, out)
    if write_postscript:
        run_dot(MODULE_DEPS_OUT, "ps")
    run_dot(MODULE_DEPS_OUT, "png")

    # write dir dep graph
    out = []
    for cluster, subdirs in sorted(dirclusters.items()):
        out.append(get_cluster_str(len(out), sorted(subdirs), cluster))
    for user, providers in sorted(dirUser2provider.items()):
        for provider in sorted(providers):
            if user != provider:
                out.append('    "' + user + '" -> "' + provider + '"')
    write_dot_file('%s.dot' % DIR_DEPS_OUT, out)
    if write_postscript:
        run_dot(DIR_DEPS_OUT, "ps")

    # write file dep graph
    out = []
    for user, providers in sorted(file2inc.items()):
        for provider in sorted(providers):
            if user != provider:
                out.append('    "' + user + '" -> "' + provider + '"')
    write_dot_file('%s.dot' % FILE_DEPS_OUT, out)
    # os.system('dot -Tps %s.dot > %s.ps' % (MODULE_DEPS_OUT, MODULE_DEPS_OUT))

    # write raw dep info
    #out = []
    #for f, file2inc
    result = '\n'.join(illegalModuleDeps)
    if result:
        print result
    else:
        print "no dependency analyzer errors found"
    return result
コード例 #2
0
ファイル: dep_analyzer.py プロジェクト: Beliaar/fifengine
def analyze(write_postscript=False):
	root = path(ROOTDIRNAME)
	headers = list(root.walkfiles('*.h'))
	sources = headers + list(root.walkfiles('*.cpp'))
	file2inc = get_file2inc(sources)
	
	moduleUser2provider = {}
	dirUser2provider = {}
	fileUser2provider = {}	
	unknownIncludes = {}
	dirclusters = {}
	fill_dep_infos(file2inc, fileUser2provider, dirUser2provider, moduleUser2provider, unknownIncludes, dirclusters)
	
	# write module dep graph
	out = []
	illegalModuleDeps = []
	for user, providers in sorted(moduleUser2provider.items()):
		for provider in sorted(providers):
			if user != provider:
				out.append('    "' + user + '" -> "' + provider + '"')
				msg = check_dep_error(ALLOWED_MODULE_DEPS, user, provider)
				if msg:
					illegalModuleDeps.append(msg)
	write_dot_file('%s.dot' % MODULE_DEPS_OUT, out)
	if write_postscript:
		run_dot(MODULE_DEPS_OUT, "ps")
	run_dot(MODULE_DEPS_OUT,"png")
	
	# write dir dep graph
	out = []
	for cluster, subdirs in sorted(dirclusters.items()):
		out.append(get_cluster_str(len(out), sorted(subdirs), cluster))
	for user, providers in sorted(dirUser2provider.items()):
		for provider in sorted(providers):
			if user != provider:
				out.append('    "' + user + '" -> "' + provider + '"')
	write_dot_file('%s.dot' % DIR_DEPS_OUT, out)
	if write_postscript:
		run_dot(DIR_DEPS_OUT, "ps")
	
	# write file dep graph
	out = []
	for user, providers in sorted(file2inc.items()):
		for provider in sorted(providers):
			if user != provider:
				out.append('    "' + user + '" -> "' + provider + '"')
	write_dot_file('%s.dot' % FILE_DEPS_OUT, out)
	# os.system('dot -Tps %s.dot > %s.ps' % (MODULE_DEPS_OUT, MODULE_DEPS_OUT))
	
	# write raw dep info
	#out = []
	#for f, file2inc
	result = '\n'.join(illegalModuleDeps)
	if result:
		print result
	else:
		print "no dependency analyzer errors found"
	return result
コード例 #3
0
def fill_dep_infos(file2inc, fileUser2provider, dirUser2provider,
                   moduleUser2provider, unknownIncludes, dirclusters):
    for f, incs in file2inc.items():
        #if f.find('engine.cpp') != -1:
        #	import pdb; pdb.set_trace()
        skip = False
        for user in SKIPPED_USERS:
            if f.find(user) != -1:
                skip = True
                break
        if skip:
            continue

        for i in incs:
            user = str(f.dirname()).replace(ROOTDIRNAME + _S, '')
            header = path(
                (f.dirname() / path(i)).abspath().split(ROOTDIRNAME + _S)[1])
            if not header.isfile():
                header = path(ROOTDIRNAME) + _S + path(i)
                if not header.isfile():
                    add_to_dictset(unknownIncludes, str(f), str(i))
                    continue
            provider = str(header.dirname()).replace(ROOTDIRNAME + _S, '')
            skip = False
            for skipped in SKIPPED_PROVIDERS:
                if header.find(skipped) != -1:
                    skip = True
                    break
            if skip:
                continue
            add_to_dictset(dirUser2provider, user, provider)
            usermodule = user.split(_S)[0]
            providermodule = provider.split(_S)[0]
            userfile = user.split(_S)[-1].split('.')[0]
            providerfile = provider.split(_S)[-1].split('.')[0]

            add_to_dictset(dirclusters, usermodule, user)
            add_to_dictset(dirclusters, providermodule, provider)
            add_to_dictset(moduleUser2provider, usermodule, providermodule)
            add_to_dictset(fileUser2provider, userfile, providerfile)
コード例 #4
0
ファイル: dep_analyzer.py プロジェクト: Beliaar/fifengine
def fill_dep_infos(file2inc, fileUser2provider, dirUser2provider, moduleUser2provider, unknownIncludes, dirclusters):
	for f, incs in file2inc.items():
		#if f.find('engine.cpp') != -1:
		#	import pdb; pdb.set_trace()
		skip = False
		for user in SKIPPED_USERS:
			if f.find(user) != -1:
				skip = True
				break
		if skip:
			continue
			
		for i in incs:
			user = str(f.dirname()).replace(ROOTDIRNAME + _S, '')
			header = path((f.dirname() / path(i)).abspath().split(ROOTDIRNAME + _S)[1])
			if not header.isfile():
				header = path(ROOTDIRNAME) + _S + path(i)
				if not header.isfile():
					add_to_dictset(unknownIncludes, str(f), str(i))
					continue
			provider = str(header.dirname()).replace(ROOTDIRNAME + _S, '')
			skip = False
			for skipped in SKIPPED_PROVIDERS:
				if header.find(skipped) != -1:
					skip = True
					break
			if skip:
				continue
			add_to_dictset(dirUser2provider, user, provider)
			usermodule = user.split(_S)[0]
			providermodule = provider.split(_S)[0]
			userfile = user.split(_S)[-1].split('.')[0]
			providerfile = provider.split(_S)[-1].split('.')[0]

			add_to_dictset(dirclusters, usermodule, user)
			add_to_dictset(dirclusters, providermodule, provider)
			add_to_dictset(moduleUser2provider, usermodule, providermodule)
			add_to_dictset(fileUser2provider, userfile, providerfile)