common/xbps-cycles.py: Add cache option

allows to modify deps and see if cycle is resolved
This commit is contained in:
Piotr Wójcik 2021-06-30 20:38:44 +02:00 committed by Piotr
parent 4fc5144f8e
commit 287624675c
2 changed files with 26 additions and 4 deletions

View file

@ -14,5 +14,9 @@ The standard behavior will be to spawn multiple processes, one per CPU, to
enumerate package dependencies. This is by far the most time-consuming part of
the execution. To override the degree of parallelism, use the `-j` option.
Dependencies can be cached on disk, one file per package, in directory
passed with `-c` option. On next execution with same option, dependencies are
read from file rather than computed.
Failures should be harmless but, at this early stage, unlikely to be pretty or
even helpful.

View file

@ -11,7 +11,7 @@ from argparse import ArgumentParser
import networkx as nx
def enum_depends(pkg, xbpsdir):
def enum_depends(pkg, xbpsdir, cachedir):
'''
Return a pair (pkg, [dependencies]), where [dependencies] is the list
of dependencies for the given package pkg. The argument xbpsdir should
@ -20,9 +20,19 @@ def enum_depends(pkg, xbpsdir):
<xbpsdir>/xbps-src show-build-deps <pkg>
unless <cachedir>/deps-<pkg> file exist, in that case it is read.
If the return code of this call nonzero, a message will be printed but
the package will treated as if it has no dependencies.
'''
if cachedir:
cachepath = os.path.join(cachedir, 'deps-' + pkg)
try:
with open(cachepath) as f:
return pkg, [l.strip() for l in f]
except FileNotFoundError:
pass
cmd = [os.path.join(xbpsdir, 'xbps-src'), 'show-build-deps', pkg]
try:
@ -32,6 +42,10 @@ def enum_depends(pkg, xbpsdir):
deps = [ ]
else:
deps = [d for d in deps.decode('utf-8').split('\n') if d]
if cachedir:
with open(cachepath, 'w') as f:
for d in deps:
print(d, file=f)
return pkg, deps
@ -83,6 +97,8 @@ if __name__ == '__main__':
parser = ArgumentParser(description='Cycle detector for xbps-src')
parser.add_argument('-j', '--jobs', default=None,
type=int, help='Number of parallel jobs')
parser.add_argument('-c', '--cachedir',
default=None, help='''Directory to use as cache for xbps-src show-build-deps. Directory must exist already.''')
parser.add_argument('-d', '--directory',
default=None, help='Path to void-packages repo')
@ -92,11 +108,13 @@ if __name__ == '__main__':
try: args.directory = os.environ['XBPS_DISTDIR']
except KeyError: args.directory = '.'
cachedir = args.cachedir
pool = multiprocessing.Pool(processes = args.jobs)
pattern = os.path.join(args.directory, 'srcpkgs', '*')
depmap = dict(pool.starmap(enum_depends,
((os.path.basename(g), args.directory)
((os.path.basename(g), args.directory, cachedir)
for g in glob.iglob(pattern))))
find_cycles(depmap, args.directory)