Skip to content

Commit

Permalink
common/xbps-cycles.py: return nonzero on cycle detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocimier committed Jun 24, 2021
1 parent b3c34c8 commit 86fd1a1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions common/scripts/xbps-cycles.py
Expand Up @@ -28,7 +28,7 @@ def enum_depends(pkg, xbpsdir):
try:
deps = subprocess.check_output(cmd)
except subprocess.CalledProcessError as err:
print('xbps-src failed to find dependencies for package', pkg)
print('xbps-src failed to find dependencies for package', pkg)
deps = [ ]
else:
deps = [d for d in deps.decode('utf-8').split('\n') if d]
Expand All @@ -47,6 +47,7 @@ def find_cycles(depmap, xbpsdir):
subpackages.
'''
G = nx.DiGraph()
rv = 0

for i, deps in depmap.items():
path = os.path.join(xbpsdir, 'srcpkgs', i)
Expand All @@ -59,6 +60,7 @@ def find_cycles(depmap, xbpsdir):

for c in nx.strongly_connected_components(G):
if len(c) < 2: continue
rv = 1
pkgs = nx.to_dict_of_lists(G, c)

p = next(iter(pkgs.keys()))
Expand All @@ -77,6 +79,7 @@ def find_cycles(depmap, xbpsdir):

if cycles:
print('Cycle: ' + ' -> '.join(cycles) + '\n')
return rv


if __name__ == '__main__':
Expand All @@ -95,8 +98,9 @@ def find_cycles(depmap, xbpsdir):
pool = multiprocessing.Pool(processes = args.jobs)

pattern = os.path.join(args.directory, 'srcpkgs', '*')
depmap = dict(pool.starmap(enum_depends,
depmap = dict(pool.starmap(enum_depends,
((os.path.basename(g), args.directory)
for g in glob.iglob(pattern))))

find_cycles(depmap, args.directory)
rv = find_cycles(depmap, args.directory)
sys.exit(rv)

0 comments on commit 86fd1a1

Please sign in to comment.