Exemplo n.º 1
0
def filter_relations(base: Deb822Dict, field: str,
                     cb: RelationsCallback) -> List[str]:
    """Update a relations field."""
    try:
        old_contents = base[field]
    except KeyError:
        return []

    oldrelations = parse_relations(old_contents)
    newrelations = []

    changed = []
    for i, (ws1, oldrelation, ws2) in enumerate(oldrelations):
        relation, dropped = cb(oldrelation)
        changed.extend([d.name for d in dropped])
        if relation == oldrelation or relation:
            newrelations.append((ws1, relation, ws2))
        elif i == 0 and len(oldrelations) > 1:
            # If the first item is removed, then copy the spacing to the next
            # item
            oldrelations[1] = (ws1, oldrelations[1][1], ws2)

    if changed:
        if _relations_empty(newrelations):
            del base[field]
        else:
            base[field] = format_relations(newrelations)
        return changed
    return []
Exemplo n.º 2
0
async def _package_provides(package: str,
                            release: str) -> Optional[List[PkgRelation]]:
    from .udd import connect_udd_mirror

    async with await connect_udd_mirror() as conn:
        provides = await conn.fetchval(
            "select provides from packages where package = $1 and release = $2",
            package, release)
    if provides is not None:
        return [r[1] for r in parse_relations(provides)]
    return None
Exemplo n.º 3
0
async def _package_build_essential(package: str, release: str) -> bool:
    from .udd import connect_udd_mirror

    async with await connect_udd_mirror() as conn:
        depends = await conn.fetchval(
            "select depends from packages where package = $1 and release = $2",
            'build-essential', release)

    build_essential = set()
    for ws1, rel, ws2 in parse_relations(depends):
        build_essential.update([r.name for r in rel])
    return package in build_essential
Exemplo n.º 4
0
def apply_hint_dep_any(binary, hint):
    m = re.match(
        "(.*) could have its dependency on (.*) annotated with :any",
        hint["description"],
    )
    if not m or m.group(1) != binary["Package"]:
        raise ValueError("unable to parse hint description: %r" % hint["description"])
    dep = m.group(2)
    if "Depends" not in binary:
        return
    changed = False
    relations = parse_relations(binary["Depends"])
    for entry in relations:
        (head_whitespace, relation, tail_whitespace) = entry
        if not isinstance(relation, str):  # formatting
            for r in relation:
                if r.name == dep and r.archqual != "any":
                    r.archqual = "any"
                    changed = True
    if not changed:
        return
    binary["Depends"] = format_relations(relations)
    return "Add :any qualifier for %s dependency." % dep
Exemplo n.º 5
0
        for offset, relation in iter_relations(updater.source.get(field, ''),
                                               'debhelper'):
            if (field == 'Build-Depends'
                    and set([r.name for r in relation]) == set(['debhelper'])):
                # In the simple case, we'd just replace the debhelper
                # dependency with a debhelper-compat one, so remember the
                # location.
                insert_position = offset - len(to_delete)
            if is_relation_implied(
                    relation, 'debhelper (>= %d)' % debhelper_compat_version):
                to_delete.append(offset)

        if to_delete:
            # TODO(jelmer): Move this into a helper function in
            # lintian_brush.control.
            relations = parse_relations(updater.source[field])
            for i in reversed(to_delete):
                if i == 0 and len(relations) > 1:
                    # If the first item is removed, then copy the spacing to
                    # the next item
                    relations[1] = (relations[0][0], relations[1][1],
                                    relations[0][2])
                del relations[i]

            updater.source[field] = format_relations(relations)
            changed_fields.append(field)

    updater.source["Build-Depends"] = ensure_exact_version(
        updater.source.get("Build-Depends", ""),
        "debhelper-compat",
        "%d" % debhelper_compat_version,
def has_misc_depends(relations):
    for entry in parse_relations(relations):
        (head_whitespace, relation, tail_whitespace) = entry
        if any(r.name == '${misc:Depends}' for r in relation):
            return True
    return False

uses_debhelper = False
misc_depends_added = []


def has_misc_depends(relations):
    for entry in parse_relations(relations):
        (head_whitespace, relation, tail_whitespace) = entry
        if any(r.name == '${misc:Depends}' for r in relation):
            return True
    return False


with control as updater:
    for entry in parse_relations(updater.source.get("Build-Depends", '')):
        (head_whitespace, relation, tail_whitespace) = entry
        if any(r.name in ('debhelper', 'debhelper-compat') for r in relation):
            uses_debhelper = True
            break

    if uses_debhelper:
        for binary in updater.binaries:
            if (has_misc_depends(binary.get('Depends', '')) or
                    has_misc_depends(binary.get('Pre-Depends', ''))):
                continue
            else:
                issue = LintianIssue(
                    updater.source, 'debhelper-but-no-misc-depends',
                    info=binary['Package'])
                if issue.should_fix():
if not need:
    sys.exit(0)

changed = []

with control as updater:
    for deps, issues, kind, name in need:
        parsed = PkgRelation.parse(deps)
        is_implied = False

        if is_relation_implied(parsed, 'debhelper'):
            is_implied = True

        for field in ['Build-Depends', 'Build-Depends-Indep',
                      'Build-Depends-Arch']:
            for unused1, existing, unused2 in parse_relations(
                    updater.source.get(field, '')):
                if is_relation_implied(parsed, existing):
                    is_implied = True

        if not is_implied:
            build_deps = updater.source.get('Build-Depends', '')
            updater.source['Build-Depends'] = add_dependency(build_deps, deps)
            for issue in issues:
                issue.report_fixed()
            changed.append((deps, issue, kind, name))

if len(changed) == 1:
    (dep, issue, kind, name) = changed[0]
    report_result('Add missing build dependency on %s for %s %s.' % (dep, kind, name))
else:
    report_result(