Fix sub-dependency resolution and handling of pkgbase

This commit is contained in:
jld3103 2021-08-17 21:23:34 +02:00
parent 2b36325b92
commit 67bbf90b5c

View file

@ -55,11 +55,18 @@ class Package:
lines = result.stdout.decode('utf-8').split('\n') lines = result.stdout.decode('utf-8').split('\n')
names = [] names = []
depends = [] depends = []
multi_pkgs = False
for line_raw in lines: for line_raw in lines:
line = line_raw.lstrip() line = line_raw.lstrip()
if line.startswith('pkgname'): if line.startswith('pkgbase'):
self.name = line.split(' = ')[1] self.name = line.split(' = ')[1]
names.append(self.name) names.append(self.name)
multi_pkgs = True
if line.startswith('pkgname'):
names.append(line.split(' = ')[1])
if not multi_pkgs:
self.name = line.split(' = ')[1]
if line.startswith('pkgbase') or line.startswith('provides'): if line.startswith('pkgbase') or line.startswith('provides'):
names.append(line.split(' = ')[1]) names.append(line.split(' = ')[1])
if line.startswith('depends') or line.startswith('makedepends') or line.startswith('checkdepends') or line.startswith('optdepends'): if line.startswith('depends') or line.startswith('makedepends') or line.startswith('checkdepends') or line.startswith('optdepends'):
@ -191,30 +198,39 @@ def discover_packages(package_paths: list[str]) -> dict[str, Package]:
break break
if not found: if not found:
package.local_depends.remove(dep) package.local_depends.remove(dep)
"""
This figures out all dependencies and their sub-dependencies for the selection and adds those packages to the selection.
First the top-level packages get selected by searching the paths.
Then their dependencies and sub-dependencies and so on get added to the selection.
"""
selection = [] selection = []
deps = []
for package in packages.values(): for package in packages.values():
if 'all' in package_paths or package.path in package_paths: if 'all' in package_paths or package.path in package_paths:
selection.append(package) deps.append(package.name)
for dep in package.local_depends: while len(deps) > 0:
if dep in packages: for dep in deps.copy():
selection.append(packages[dep]) found = False
else: for p in packages.values():
found = False for name in p.names:
for p in packages.values(): if name == dep:
for name in p.names: selection.append(packages[p.name])
if dep == name: deps.remove(dep)
selection.append(p) # Add the sub-dependencies
found = True deps += p.local_depends
break found = True
if found: break
break if found:
if not found: break
logging.fatal(f'Could not find package for "{dep}"') if not found:
exit(1) logging.fatal(f'Failed to find dependency {dep}')
exit(1)
selection = list(set(selection)) selection = list(set(selection))
packages = {package.name: package for package in selection} packages = {package.name: package for package in selection}
logging.debug(f'Figured out selection: {list(map(lambda p: p.path, selection))}')
return packages return packages
@ -460,8 +476,6 @@ def cmd_build(verbose, paths):
logging.info('Everything built already') logging.info('Everything built already')
return return
logging.info('Building %s', ', '.join(map(lambda x: x.path, need_build))) logging.info('Building %s', ', '.join(map(lambda x: x.path, need_build)))
with open('.last_built', 'w') as file:
file.write('\n'.join(map(lambda x: x.path, need_build)))
for package in need_build: for package in need_build:
setup_chroot() setup_chroot()
@ -523,6 +537,7 @@ def cmd_check(verbose, paths):
'depends': False, 'depends': False,
'optdepends': False, 'optdepends': False,
'makedepends': False, 'makedepends': False,
'backup': False,
'install': False, 'install': False,
'options': False, 'options': False,
commit_key: is_git_package, commit_key: is_git_package,