projects.py: Add cmd_exepath()

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-03-06 15:16:25 +00:00
commit 059977f47d

View file

@ -200,6 +200,17 @@ def cmd_ldlibpath(args_):
r = r + ':' + proj_dir(m) + '/lib'
print(r[1:])
def cmd_exepath(args_):
parser = argparse.ArgumentParser(description='exepath')
parser.add_argument('module', nargs='*', help='Modules')
args=parser.parse_args(args_)
deps = get_modules_from_project_txt(args.module, 'pkg.required', 'run',
scope = 2, add_self=True, names_only=True)
r = ''
for m in deps:
r = r + ':' + proj_dir(m) + '/bin'
print(r[1:])
def cmd_libname(args_):
parser = argparse.ArgumentParser(description='libname')
parser.add_argument('module', nargs='*', help='Modules')
@ -299,6 +310,75 @@ def cmd_summary(args_):
r.append(summary)
print(' '.join(r))
def contains(small, big):
for i in xrange(len(big)-len(small)+1):
for j in xrange(len(small)):
if big[i+j] != small[j]:
break
else:
return i, i+len(small)
return False
def read_dep_graph(modules, section, graph):
for m in modules:
if m in graph:
continue
deps = get_modules_from_project_txt([ m ], 'pkg.required', section,
scope = 1, add_self=False, names_only=True)
if not deps is None:
graph[m] = deps
for d in deps:
read_dep_graph([ d ], section, graph)
def flip_graph(graph):
r = {}
for m, deps in graph.iteritems():
for d in deps:
if not d in r:
r[d] = Set()
r[d].add(m)
return r
def check_circular_deps(module, section, graph, unvisited, temp, path):
if module in temp:
debug('found circular dependency at module', module)
return module
if not module in unvisited:
return None
temp.add(module)
if module in graph:
for m in graph[module]:
last = check_circular_deps(m, section, graph, unvisited, temp, path)
if last is not None:
path.insert(0, m)
return last
unvisited.remove(module)
temp.remove(module)
def cmd_check(args_):
parser = argparse.ArgumentParser(description='check')
parser.add_argument('module', nargs='*', help='Modules')
parser.add_argument('--flavour', '-f', nargs='?', default = 'build')
args=parser.parse_args(args_)
graph = {}
path = []
read_dep_graph(args.module, args.flavour, graph)
unvisited = graph.keys()
temp = Set()
while len(unvisited) is not 0:
m = unvisited[0]
debug('checking circular dependency of', m)
last = check_circular_deps(m, args.flavour, flip_graph(graph), unvisited, temp, path)
if last is not None:
debug('found circular dependency below', m, ', last is', last)
print('found circular dependency in flavour', args.flavour, ':', ' -> '.join(path))
exit(1)
print('no circular dependency found for flavour', args.flavour, ' in modules:',
' '.join(args.module))
exit(0)
# -------------------------------------------------------------------- here we go
global_args = []