Skip to content
Snippets Groups Projects
Commit 00212947 authored by Ryan Gonzalez's avatar Ryan Gonzalez
Browse files

Avoid trying to download source versions that don't exist

This can happen when the "built with" versions are older than the
current ones in-repos, or the strip version suffix is incorrect or not
working. However, the fallbacks are rather slow, so it's ideal to try
and handle it more cleanly early on.
parent 5137f0d5
No related branches found
No related tags found
1 merge request!14Add several features used for the reference runtime
......@@ -31,6 +31,7 @@ Fetch source code for packages installed in the given sysroot.
"""
import argparse
import glob
import logging
import os
import re
......@@ -136,6 +137,40 @@ class SourceRequired:
return '{}={}'.format(self.source, self.source_version)
def gather_sources_index(in_chroot, sysroot):
index = set()
for sourcelist in glob.glob(os.path.join(
sysroot, 'var/lib/apt/lists/*_Sources.*')):
logger.info('Indexing available sources in %s', sourcelist)
rel_sourcelist = '/' + os.path.relpath(sourcelist, sysroot)
sources = subprocess.check_output(
in_chroot + ['/usr/lib/apt/apt-helper', 'cat-file', rel_sourcelist],
universal_newlines=True,
)
source = None
for line in sources.splitlines():
if not line:
assert source is None, 'Package {} without version'.format(
source)
continue
if line.startswith('Package:'):
source = line.split(':', 1)[1].strip()
elif line.startswith('Version:'):
version = line.split(':', 1)[1].strip()
assert source is not None, 'Version {} without package'.format(
version)
index.add(SourceRequired(source, version))
source = None
return index
def read_manifest(path):
# type: (str) -> typing.List[InstalledPackage]
......@@ -266,6 +301,8 @@ def main():
platform_built_using = os.path.join(
args.sysroot, 'usr', 'manifest.dpkg.built-using.platform')
sources_index = gather_sources_index(in_chroot, args.sysroot)
sdk_packages = read_manifest(manifest)
packages = sdk_packages[:]
sources_required = set()
......@@ -297,7 +334,6 @@ def main():
sources = set() # type: typing.Set[SourceRequired]
get_source = [] # type: typing.List[str]
included = set() # type: typing.Set[SourceRequired]
missing_sources = set() # type: typing.Set[SourceRequired]
for s in sources_required:
source = s.source
......@@ -314,6 +350,9 @@ def main():
sources.add(s)
get_source.append(s.get_source)
missing_sources = sources - sources_index
sources &= sources_index
attempts = install_source_packages(
in_chroot, list(sources), included, missing_sources)
logger.info('Downloaded %d source packages after %d attempt(s)',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment