src/modules/publish/dependencies.py
author Brock Pytlik <brock.pytlik@oracle.com>
Tue, 29 Mar 2011 15:08:42 -0700
changeset 2283 c368082b6a17
parent 2275 eed34df93728
child 2288 29c3afa79a1b
permissions -rw-r--r--
16499 pkgdepend resolve -mo includes manifest path in output stream 18019 pkgdepend resolves to double up group dependencies 18077 resolve traces back if two dependencies of different types are given 18082 it should be clear that -o is not parseable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1500
diff changeset
     1
#!/usr/bin/python
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     2
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     4
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     8
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    13
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    19
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    21
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    22
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    23
#
2191
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
    24
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    25
#
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    26
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
    27
import copy
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    28
import itertools
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    29
import os
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    30
import re
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
    31
import urllib
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    32
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    33
from collections import namedtuple
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    34
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    35
import pkg.actions as actions
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
    36
import pkg.client.api as api
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    37
import pkg.flavor.base as base
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    38
import pkg.flavor.elf as elf_dep
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    39
import pkg.flavor.hardlink as hardlink
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    40
import pkg.flavor.script as script
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
    41
import pkg.flavor.smf_manifest as smf_manifest
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    42
import pkg.fmri as fmri
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    43
import pkg.manifest as manifest
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    44
import pkg.portable as portable
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    45
import pkg.variant as variants
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    46
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    47
paths_prefix = "%s.path" % base.Dependency.DEPEND_DEBUG_PREFIX
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    48
files_prefix = "%s.file" % base.Dependency.DEPEND_DEBUG_PREFIX
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
    49
reason_prefix = "%s.reason" % base.Dependency.DEPEND_DEBUG_PREFIX
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    50
type_prefix = "%s.type" % base.Dependency.DEPEND_DEBUG_PREFIX
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    51
target_prefix = "%s.target" % base.Dependency.DEPEND_DEBUG_PREFIX
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    52
bypassed_prefix = "%s.bypassed" % base.Dependency.DEPEND_DEBUG_PREFIX
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    53
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    54
# A tag used to hold the product of the paths_prefix and files_prefix
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    55
# contents, used when bypassing dependency generation
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    56
fullpaths_prefix = "%s.fullpath" % base.Dependency.DEPEND_DEBUG_PREFIX
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    57
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    58
Entries = namedtuple("Entries", ["delivered", "installed"])
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    59
# This namedtuple is used to hold two items. The first, delivered, is used to
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    60
# hold items which are part of packages being delivered.  The second, installed,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    61
# is used to hold items which are part of packages installed on the system.
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    62
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    63
class DependencyError(Exception):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    64
        """The parent class for all dependency exceptions."""
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    65
        pass
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    66
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    67
class MultiplePackagesPathError(DependencyError):
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    68
        """This exception is used when a file dependency has paths which cause
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    69
        two or more packages to deliver files which fulfill the dependency under
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    70
        some combination of variants."""
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    71
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    72
        def __init__(self, res, source, vc):
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    73
                self.res = res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    74
                self.source = source
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    75
                self.vc = vc
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    76
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    77
        def __str__(self):
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
    78
                return _("The file dependency %(src)s has paths which resolve "
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    79
                    "to multiple packages under this combination of "
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    80
                    "variants:\n%(vars)s\nThe actions are as "
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
    81
                    "follows:\n%(acts)s") % {
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
    82
                        "src":self.source,
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    83
                        "acts":"\n".join(["\t%s" % a for a in self.res]),
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    84
                        "vars":"\n".join([
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    85
                            " ".join([
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    86
                                ("%s:%s" % (name, val)) for name, val in grp
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    87
                            ])
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    88
                            for grp in self.vc.sat_set])
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
    89
                    }
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    90
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    91
class AmbiguousPathError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    92
        """This exception is used when multiple packages deliver a path which
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    93
        is depended upon."""
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    94
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    95
        def __init__(self, pkgs, source):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    96
                self.pkgs = pkgs
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    97
                self.source = source
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    98
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    99
        def __str__(self):
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   100
                return _("The file dependency %(src)s depends on a path "
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   101
                    "delivered by multiple packages. Those packages "
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   102
                    "are:%(pkgs)s") % {
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   103
                        "src":self.source,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   104
                        "pkgs":" ".join([str(p) for p in self.pkgs])
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   105
                    }
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   106
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   107
class UnresolvedDependencyError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   108
        """This exception is used when no package delivers a file which is
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   109
        depended upon."""
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   110
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   111
        def __init__(self, pth, file_dep, pvars):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   112
                self.path = pth
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   113
                self.file_dep = file_dep
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   114
                self.pvars = pvars
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   115
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   116
        def __str__(self):
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   117
                return _("%(pth)s has unresolved dependency '%(dep)s' under "
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   118
                    "the following combinations of variants:\n%(combo)s") % \
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   119
                    {
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   120
                        "pth":self.path,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   121
                        "dep":self.file_dep,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   122
                        "combo":"\n".join([
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   123
                            " ".join([
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   124
                                ("%s:%s" % (name, val))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   125
                                for name, val in sorted(grp)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   126
                            ])
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   127
                            for grp in self.pvars.not_sat_set
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   128
                    ])}
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   129
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   130
class MissingPackageVariantError(DependencyError):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   131
        """This exception is used when an action is tagged with a variant or
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   132
        variant value which the package is not tagged with."""
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   133
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   134
        def __init__(self, act_vars, pkg_vars, pth):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   135
                self.act_vars = act_vars
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   136
                self.pkg_vars = pkg_vars
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   137
                self.path = pth
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   138
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   139
        def __str__(self):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   140
                return _("The action delivering %(path)s is tagged with a "
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   141
                    "variant type or value not tagged on the package. "
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   142
                    "Dependencies on this file may fail to be reported.\n"
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   143
                    "The action's variants are: %(act)s\nThe package's "
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   144
                    "variants are: %(pkg)s") % {
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   145
                        "path": self.path,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   146
                        "act": self.act_vars,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   147
                        "pkg": self.pkg_vars
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   148
                    }
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   149
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   150
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   151
def list_implicit_deps(file_path, proto_dirs, dyn_tok_conv, run_paths,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   152
    remove_internal_deps=True, convert=True, ignore_bypass=False):
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   153
        """Given the manifest provided in file_path, use the known dependency
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   154
        generators to produce a list of dependencies the files delivered by
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   155
        the manifest have.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   156
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   157
        'file_path' is the path to the manifest for the package.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   158
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   159
        'proto_dirs' is a list of paths to proto areas which hold the files that
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   160
        will be delivered by the package.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   161
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   162
        'dyn_tok_conv' is the dictionary which maps the dynamic tokens, like
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   163
        $PLATFORM, to the values they should be expanded to.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   164
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   165
        'run_paths' contains the run paths that are used to find modules.
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   166
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   167
        'convert' determines whether PublishingDependencies will be transformed
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   168
        to DependencyActions prior to being returned.  This is primarily an
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   169
        option to facilitate testing and debugging.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   170
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   171
        'ignore_bypass' determines whether to bypass generation of dependencies
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   172
        against certain files or directories.  This is primarily an option to
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   173
        facilitate testing and debugging.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   174
        """
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   175
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   176
        m, missing_manf_files = __make_manifest(file_path, proto_dirs)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   177
        pkg_vars = m.get_all_variants()
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   178
        deps, elist, missing, pkg_attrs = list_implicit_deps_for_manifest(m,
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   179
            proto_dirs, pkg_vars, dyn_tok_conv, run_paths,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   180
            ignore_bypass=ignore_bypass)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   181
        rid_errs = []
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   182
        if remove_internal_deps:
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   183
                deps, rid_errs = resolve_internal_deps(deps, m, proto_dirs,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   184
                    pkg_vars)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   185
        if convert:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   186
                deps = convert_to_standard_dep_actions(deps)
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   187
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   188
        return deps, missing_manf_files + elist + rid_errs, missing, pkg_attrs
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   189
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   190
def convert_to_standard_dep_actions(deps):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   191
        """Convert pkg.base.Dependency objects to
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   192
        pkg.actions.dependency.Dependency objects."""
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   193
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   194
        res = []
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   195
        for d in deps:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   196
                tmp = []
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   197
                for c in d.dep_vars.not_sat_set:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   198
                        attrs = d.attrs.copy()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   199
                        attrs.update(c)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   200
                        tmp.append(actions.depend.DependencyAction(**attrs))
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   201
                if not tmp:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   202
                        tmp.append(actions.depend.DependencyAction(**d.attrs))
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   203
                res.extend(tmp)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   204
        return res
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   205
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   206
def resolve_internal_deps(deps, mfst, proto_dirs, pkg_vars):
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   207
        """Given a list of dependencies, remove those which are satisfied by
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   208
        others delivered by the same package.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   209
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   210
        'deps' is a list of Dependency objects.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   211
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   212
        'mfst' is the Manifest of the package that delivered the dependencies
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   213
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   214
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   215
        'proto_dir' is the path to the proto area which holds the files that
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   216
        will be delivered by the package.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   217
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   218
        'pkg_vars' are the variants that this package was published against."""
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   219
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   220
        res = []
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   221
        errs = []
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   222
        delivered = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   223
        delivered_bn = {}
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   224
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   225
        files = Entries({}, {})
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   226
        links = Entries({}, {})
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   227
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   228
        # A fake pkg name is used because there is no requirement that a package
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   229
        # name itself to generate its dependencies.  Also, the name is entirely
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   230
        # a private construction which should not escape to the user.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   231
        add_fmri_path_mapping(files.delivered, links.delivered,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   232
            fmri.PkgFmri("INTERNAL@0-0", build_release="0"), mfst)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   233
        for a in mfst.gen_actions_by_type("file"):
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   234
                pvars = a.get_variant_template()
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   235
                if not pvars:
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   236
                        pvars = pkg_vars
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   237
                else:
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   238
                        if not pvars.issubset(pkg_vars):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   239
                                # This happens when an action in a package is
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   240
                                # tagged with a variant type or value which the
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   241
                                # package has not been tagged with.
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   242
                                errs.append(
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   243
                                    MissingPackageVariantError(pvars, pkg_vars,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   244
                                        a.attrs["path"]))
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   245
                        pvars.merge_unknown(pkg_vars)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   246
                pvc = variants.VariantCombinations(pvars, satisfied=True)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   247
                p = a.attrs["path"]
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   248
                bn = os.path.basename(p)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   249
                delivered_bn.setdefault(bn, copy.copy(pvc))
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   250
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   251
        for d in deps:
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   252
                etype, pvars = d.resolve_internal(
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   253
                    delivered_files=files.delivered,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   254
                    delivered_base_names=delivered_bn, links=links,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   255
                    resolve_links=resolve_links)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   256
                if etype is None:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   257
                        continue
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   258
                pvars.simplify(pkg_vars)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   259
                d.dep_vars = pvars
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   260
                res.append(d)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   261
        return res, errs
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   262
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   263
def no_such_file(action, **kwargs):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   264
        """Function to handle dispatch of files not found on the system."""
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   265
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   266
        return [], [base.MissingFile(action.attrs["path"])], {}
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   267
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   268
# Dictionary which maps codes from portable.get_file_type to the functions which
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   269
# find dependencies for those types of files.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   270
dispatch_dict = {
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   271
    portable.ELF: elf_dep.process_elf_dependencies,
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   272
    portable.EXEC: script.process_script_deps,
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   273
    portable.SMF_MANIFEST: smf_manifest.process_smf_manifest_deps,
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   274
    portable.UNFOUND: no_such_file
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   275
}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   276
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   277
def list_implicit_deps_for_manifest(mfst, proto_dirs, pkg_vars, dyn_tok_conv,
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   278
    run_paths, ignore_bypass=False):
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   279
        """For a manifest, produce the list of dependencies generated by the
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   280
        files it installs.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   281
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   282
        'mfst' is the Manifest of the package that delivered the dependencies
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   283
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   284
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   285
        'proto_dirs' are the paths to the proto areas which hold the files that
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   286
        will be delivered by the package.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   287
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   288
        'pkg_vars' are the variants that this package was published against.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   289
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   290
        'dyn_tok_conv' is the dictionary which maps the dynamic tokens, like
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   291
        $PLATFORM, to the values they should be expanded to.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   292
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   293
        'run_paths' contains the run paths used to find modules, this is
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   294
        overridden by any manifest or action attributes setting
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   295
        'pkg.depend.runpath' (portable.PD_RUN_PATH)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   296
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   297
        'ignore_bypass' set to True will prevent us from looking up any
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   298
        pkg.depend.bypass-generate attributes - this is primarily to aid
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   299
        debugging and testing.
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   300
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   301
        Returns a tuple of three lists.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   302
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   303
        'deps' is a list of dependencies found for the given Manifest.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   304
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   305
        'elist' is a list of errors encountered while finding dependencies.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   306
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   307
        'missing' is a dictionary mapping a file type that isn't recognized by
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   308
        portable.get_file_type to a file which produced that filetype.
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   309
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   310
        'pkg_attrs' is a dictionary containing metadata that was gathered
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   311
        during dependency analysis. Typically these would get turned into
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   312
        AttributeActions for that package. """
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   313
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   314
        deps = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   315
        elist = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   316
        missing = {}
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   317
        pkg_attrs = {}
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   318
        act_list = list(mfst.gen_actions_by_type("file"))
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   319
        file_types = portable.get_file_type(act_list)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   320
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   321
        if portable.PD_RUN_PATH in mfst:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   322
                # check for multiple values in a set attribute
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   323
                run_path_str = mfst[portable.PD_RUN_PATH]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   324
                es = __verify_run_path(run_path_str)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   325
                if es:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   326
                        return deps, elist + es, missing, pkg_attrs
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   327
                run_paths = run_path_str.split(":")
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   328
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   329
        mf_bypass = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   330
        if portable.PD_BYPASS_GENERATE in mfst:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   331
                mf_bypass = __makelist(mfst[portable.PD_BYPASS_GENERATE])
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   332
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   333
        for i, file_type in enumerate(file_types):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   334
                a = act_list[i]
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   335
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   336
                a_run_paths = run_paths
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   337
                if portable.PD_RUN_PATH in a.attrs:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   338
                        a_run_path_str = a.attrs[portable.PD_RUN_PATH]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   339
                        es = __verify_run_path(a_run_path_str)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   340
                        if es:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   341
                                return deps, elist + es, missing, pkg_attrs
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   342
                        a_run_paths = a_run_path_str.split(":")
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   343
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   344
                bypass = __makelist(
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   345
                    a.attrs.get(portable.PD_BYPASS_GENERATE, mf_bypass))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   346
                # If we're bypassing all depdendency generation, we can avoid
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   347
                # calling our dispatch_dict function altogether.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   348
                if (".*" in bypass or "^.*$" in bypass) and not ignore_bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   349
                        pkg_attrs[bypassed_prefix] = "%s:.*" % a.attrs["path"]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   350
                        continue
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   351
                try:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   352
                        func = dispatch_dict[file_type]
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   353
                except KeyError:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   354
                        if file_type not in missing:
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   355
                                missing[file_type] = \
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   356
                                    a.attrs[portable.PD_LOCAL_PATH]
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   357
                else:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   358
                        try:
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   359
                                ds, errs, attrs = func(action=a,
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   360
                                    pkg_vars=pkg_vars,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   361
                                    dyn_tok_conv=dyn_tok_conv,
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   362
                                    run_paths=a_run_paths)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   363
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   364
                                # prune out any dependencies on the files we've
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   365
                                # been asked to avoid creating dependencies on
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   366
                                if bypass and not ignore_bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   367
                                        ds = \
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   368
                                            __bypass_deps(ds, bypass, pkg_attrs)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   369
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   370
                                deps.extend(ds)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   371
                                elist.extend(errs)
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   372
                                __update_pkg_attrs(pkg_attrs, attrs)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   373
                        except base.DependencyAnalysisError, e:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   374
                                elist.append(e)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   375
        for a in mfst.gen_actions_by_type("hardlink"):
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   376
                deps.extend(hardlink.process_hardlink_deps(a, pkg_vars))
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   377
        return deps, elist, missing, pkg_attrs
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   378
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   379
def __update_pkg_attrs(pkg_attrs, new_attrs):
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   380
        """Update the pkg_attrs dictionary with the contents of new_attrs."""
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   381
        for key in new_attrs:
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   382
                pkg_attrs.setdefault(key, []).extend(new_attrs[key])
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   383
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   384
def __verify_run_path(run_path_str):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   385
        """Verify we've been passed a single item and ensure it contains
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   386
        at least one non-null string."""
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   387
        if not isinstance(run_path_str, str):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   388
                # require a colon separated string to potentially enforce
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   389
                # ordering in the future
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   390
                return [base.DependencyAnalysisError(
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   391
                    _("Manifest specified multiple values for %s rather "
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   392
                    "than a single colon-separated string.") %
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   393
                    portable.PD_RUN_PATH)]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   394
        if set(run_path_str.split(":")) == set([""]):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   395
                return [base.DependencyAnalysisError(
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   396
                    _("Manifest did not specify any entries for %s, expecting "
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   397
                    "a colon-separated string.") % portable.PD_RUN_PATH)]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   398
        return []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   399
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   400
def __makelist(value):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   401
        """Given a value, return it if that value is a list, or if it's a
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   402
        string, return a single-element list of just that string."""
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   403
        if isinstance(value, list):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   404
                return value
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   405
        elif isinstance(value, str):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   406
                if value:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   407
                        return [value]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   408
                else:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   409
                        return []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   410
        else:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   411
                raise ValueError("Value was not a string or a list")
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   412
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   413
def __bypass_deps(ds, bypass, pkg_attrs):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   414
        """Return a list of dependencies, excluding any of those that should be
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   415
        bypassed.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   416
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   417
        ds         the list of dependencies to operate on
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   418
        bypass     a list of paths on which we should not generate dependencies
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   419
        pkg_attrs  the set of package attributes for this manifest, produced as
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   420
                   a by-product of this dependency generation
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   421
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   422
        We support regular expressions as entries in the bypass list, matching
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   423
        one or more files.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   424
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   425
        If a bypass-list entry is provided that does not contain one of the
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   426
        following characters: ["/", "*", "?"], it is assumed to be a filename,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   427
        and expanded to the regular expression ".*/<entry>"
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   428
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   429
        All bypass-list entries are assumed to be regular expressions that are
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   430
        rooted at ^ and $.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   431
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   432
        The special match-all wildcard ".*" is dealt with separately,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   433
        by list_implicit_deps_for_manifest(..)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   434
        """
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   435
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   436
        new_ds = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   437
        for dep in ds:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   438
                full_paths = set(make_paths(dep))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   439
                bypassed_files = set()
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   440
                bypass_regexps = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   441
                try:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   442
                        for item in bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   443
                                # try to determine if this is a regexp,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   444
                                # rather than a filename
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   445
                                if "*" in item or "?" in item:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   446
                                        pass
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   447
                                # if it appears to be a filename, make it match
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   448
                                # all paths to that filename.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   449
                                elif "/" not in item:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   450
                                        item = ".*%s%s" % (os.path.sep, item)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   451
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   452
                                # always anchor our regular expressions,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   453
                                # otherwise, we get partial matches for files,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   454
                                # eg. bypassing "foo.c" would otherwise also
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   455
                                # bypass "foo.cc"
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   456
                                if item:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   457
                                        if not item.endswith("$"):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   458
                                                item = item + "$"
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   459
                                        if not item.startswith("^"):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   460
                                                item = "^" + item
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   461
                                        bypass_regexps.append(re.compile(item))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   462
                except re.error, e:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   463
                        raise base.InvalidDependBypassValue(item, e)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   464
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   465
                for path in full_paths:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   466
                        if path in bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   467
                                bypassed_files.add(path)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   468
                                continue
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   469
                        for regexp in bypass_regexps:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   470
                                if regexp.match(path):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   471
                                        bypassed_files.add(path)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   472
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   473
                if bypassed_files:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   474
                        # remove the old runpath and basename entries from
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   475
                        # the dependency if they were present
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   476
                        dep.attrs.pop(files_prefix, None)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   477
                        dep.attrs.pop(paths_prefix, None)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   478
                        dep.base_names = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   479
                        dep.run_paths = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   480
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   481
                        # determine our new list of paths
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   482
                        full_paths = full_paths - bypassed_files
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   483
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   484
                        dep.full_paths = sorted(list(full_paths))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   485
                        dep.attrs[fullpaths_prefix] = dep.full_paths
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   486
                        pkg_attrs[bypassed_prefix] = \
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   487
                            sorted(list(bypassed_files))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   488
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   489
                        # only include the dependency if it still contains data
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   490
                        if full_paths:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   491
                                new_ds.append(dep)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   492
                else:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   493
                        new_ds.append(dep)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   494
        return new_ds
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   495
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   496
def __make_manifest(fp, basedirs=None, load_data=True):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   497
        """Given the file path, 'fp', return a Manifest for that path."""
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   498
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   499
        m = manifest.Manifest()
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   500
        fh = open(fp, "rb")
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   501
        acts = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   502
        missing_files = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   503
        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   504
        for l in fh:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   505
                l = l.strip()
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   506
                if l.endswith("\\"):
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   507
                        accumulate += l[0:-1]
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   508
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   509
                elif accumulate:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   510
                        l = accumulate + l
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   511
                        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   512
                if not l or l[0] == '#':
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   513
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   514
                try:
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   515
                        a, local_path, used_bd = actions.internalizestr(l,
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   516
                            basedirs=basedirs,
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   517
                            load_data=load_data)
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   518
                        if local_path:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   519
                                assert portable.PD_LOCAL_PATH not in a.attrs
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   520
                                a.attrs[portable.PD_LOCAL_PATH] = local_path
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   521
                                a.attrs[portable.PD_PROTO_DIR] = used_bd
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   522
                                a.attrs[portable.PD_PROTO_DIR_LIST] = basedirs
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   523
                        acts.append(a)
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   524
                except actions.ActionDataError, e:
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   525
                        new_a, local_path, used_bd = actions.internalizestr(
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   526
                            l, basedirs=basedirs, load_data=False)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   527
                        if new_a.name == "license":
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   528
                                acts.append(new_a)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   529
                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   530
                                path = e.path
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   531
                                # If the path was not set, then parse the
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   532
                                # action, without trying to load the data and
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   533
                                # use the path defined in the action.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   534
                                if not path:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   535
                                        path = new_a.attrs["path"]
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   536
                                missing_files.append(base.MissingFile(path))
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   537
        fh.close()
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 1934
diff changeset
   538
        m.set_content(content=acts)
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   539
        return m, missing_files
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   540
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   541
def choose_name(fp, mfst):
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   542
        """Find the package name for this manifest. If it's defined in a set
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   543
        action in the manifest, use that. Otherwise use the basename of the
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   544
        path to the manifest as the name.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   545
        'fp' is the path to the file for the manifest.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   546
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   547
        'mfst' is the Manifest object."""
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   548
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   549
        if mfst is None:
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   550
                return urllib.unquote(os.path.basename(fp))
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1337
diff changeset
   551
        name = mfst.get("pkg.fmri", mfst.get("fmri", None))
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   552
        if name is not None:
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   553
                return name
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   554
        return urllib.unquote(os.path.basename(fp))
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   555
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   556
def helper(lst, file_dep, dep_vars, orig_dep_vars):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   557
        """Creates the depend actions from lst for the dependency and determines
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   558
        which variants have been accounted for.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   559
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   560
        'lst' is a list of fmri, variants pairs. The fmri a package which can
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   561
        satisfy the dependency. The variants are the variants under which it
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   562
        satisfies the dependency.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   563
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   564
        'file_dep' is the dependency that needs to be satisfied.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   565
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   566
        'dep_vars' is the variants under which 'file_dep' has not yet been
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   567
        satisfied.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   568
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   569
        'orig_dep_vars' is the original set of variants under which the
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   570
        dependency must be satisfied."""
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   571
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   572
        res = []
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   573
        vars = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   574
        errs = set()
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   575
        for pfmri, delivered_vars in lst:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   576
                # If the pfmri package isn't present under any of the variants
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   577
                # where the dependency is, skip it.
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   578
                if not orig_dep_vars.intersects(delivered_vars,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   579
                    only_not_sat=True):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   580
                        continue
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   581
                vc = orig_dep_vars.intersection(delivered_vars)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   582
                vc.mark_all_as_satisfied()
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   583
                for found_vars, found_fmri in vars:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   584
                        # Because we don't have the concept of one-of
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   585
                        # dependencies, depending on a file which is delivered
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   586
                        # in multiple packages under a set of variants
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   587
                        # prevents automatic resolution of dependencies.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   588
                        if found_fmri != pfmri and \
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   589
                            found_vars.intersects(delivered_vars):
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   590
                                errs.add(found_fmri)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   591
                                errs.add(pfmri)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   592
                # Find the variants under which pfmri is relevant.
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   593
                action_vars = vc
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   594
                # Mark the variants as satisfied so it's possible to know if
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   595
                # all variant combinations have been covered.
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   596
                dep_vars.mark_as_satisfied(delivered_vars)
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   597
                attrs = file_dep.attrs.copy()
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   598
                attrs.update({"fmri":pfmri.get_short_fmri()})
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   599
                # Add this package as satisfying the dependency.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   600
                res.append((actions.depend.DependencyAction(**attrs),
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   601
                    action_vars))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   602
                vars.append((action_vars, pfmri))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   603
        if errs:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   604
                # If any packages are in errs, then more than one file delivered
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   605
                # the same path under some configuration of variants. This
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   606
                # situation is unresolvable.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   607
                raise AmbiguousPathError(errs, file_dep)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   608
        return res, dep_vars
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   609
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   610
def make_paths(file_dep):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   611
        """Find all the possible paths which could satisfy the dependency
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   612
        'file_dep'."""
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   613
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   614
        if file_dep.attrs.get(fullpaths_prefix, []):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   615
                return file_dep.attrs[fullpaths_prefix]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   616
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   617
        rps = file_dep.attrs.get(paths_prefix, [""])
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   618
        files = file_dep.attrs[files_prefix]
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   619
        if isinstance(files, basestring):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   620
                files = [files]
1674
faf484754465 13059 pkgdep generate should analyze python modules using the version of python they use
Brock Pytlik <bpytlik@sun.com>
parents: 1581
diff changeset
   621
        if isinstance(rps, basestring):
faf484754465 13059 pkgdep generate should analyze python modules using the version of python they use
Brock Pytlik <bpytlik@sun.com>
parents: 1581
diff changeset
   622
                rps = [rps]
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   623
        return [os.path.join(rp, f) for rp in rps for f in files]
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   624
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   625
def resolve_links(path, files_dict, links, path_vars, file_dep_attrs, index=1):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   626
        """This method maps a path to one or more real paths and the variants
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   627
        under which each real path can exist.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   628
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   629
        'path' is the original text of the path which is being resolved to a
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   630
        real path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   631
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   632
        'files_dict' is a dictionary which maps package identity to the files
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   633
        the package delivers and the variants under which each file is present.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   634
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   635
        'links' is an Entries namedtuple which contains two dictionaries.  One
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   636
        dictionary maps package identity to the links that it delivers.  The
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   637
        other dictionary, contains the same information for links that are
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   638
        installed on the system.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   639
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   640
        'path_vars' is the set of variants under which 'path' exists.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   641
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   642
        'file_dep_attrs' is the dictonary of attributes for the file dependency
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   643
        for 'path'.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   644
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   645
        'index' indicates how much of 'path' should be checked against the file
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   646
        and link dictionaries."""
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   647
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   648
        res_paths = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   649
        res_links = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   650
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   651
        # If the current path is a known file, then we might be done resolving
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   652
        # the path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   653
        if path in files_dict:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   654
                # Copy the variants so that marking the variants as satisified
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   655
                # doesn't change the sate of 'path_vars.'
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   656
                tmp_vars = copy.copy(path_vars)
2191
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   657
                # If tmp_vars has been satisfied, then this function should
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   658
                # never have been called.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   659
                assert(tmp_vars.is_empty() or not tmp_vars.is_satisfied())
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   660
                # Check each package which delivers a file with this path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   661
                for pfmri, p_vc in files_dict[path]:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   662
                        # If the file is delivered under a set of variants which
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   663
                        # are irrelevant to the path being considered, skip it.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   664
                        if not path_vars.intersects(p_vc):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   665
                                continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   666
                        # The intersection of the variants which apply to the
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   667
                        # current path and the variants for the delivered file
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   668
                        # is the combination of variants where the original
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   669
                        # path resolves to the delivered file.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   670
                        inter = path_vars.intersection(p_vc)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   671
                        inter.mark_all_as_satisfied()
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   672
                        tmp_vars.mark_as_satisfied(p_vc)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   673
                        res_paths.append((path, pfmri, inter))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   674
                # If the path was resolved under all relevant variants, then
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   675
                # we're done.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   676
                if res_paths and tmp_vars.is_satisfied():
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   677
                        return res_paths, res_links
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   678
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   679
        lst = path.split(os.path.sep)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   680
        # If there aren't any more pieces of the path left to check, then
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   681
        # there's nothing to do so return whatever has been found so far.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   682
        if index > len(lst):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   683
                return res_paths, res_links
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   684
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   685
        # Create the path to check for links.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   686
        cur_path = os.path.join(*lst[0:index])
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   687
        # The links in delivered packages (ie, those current being resolved)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   688
        # should be preferred over links from the installed system.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   689
        rel_links = links.delivered.get(cur_path, [])
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   690
        tmp = set()
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   691
        for pfmri, vc, rel_target in rel_links:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   692
                tmp.add(pfmri.get_name())
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   693
        # Only considered links from installed packages which are not also being
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   694
        # resolved.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   695
        for pfmri, vc, rel_target in links.installed.get(cur_path, []):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   696
                if pfmri.get_name() in tmp:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   697
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   698
                rel_links.append((pfmri, vc, rel_target))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   699
        # If there weren't any relevant links, then add the next path component
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   700
        # to the path being considered and try again.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   701
        if not rel_links:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   702
                return resolve_links(path, files_dict, links, path_vars,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   703
                    file_dep_attrs, index=index+1)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   704
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   705
        for link_pfmri, link_vc, rel_target in rel_links:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   706
                # If the variants needed to reach the current path and the
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   707
                # variants for the link don't intersect, then the link
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   708
                # is irrelevant.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   709
                if not path_vars.intersects(link_vc):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   710
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   711
                vc_intersection = path_vars.intersection(link_vc)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   712
                # If the link only matters under variants that are satisfied,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   713
                # then it's not an interesting link for this purpose.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   714
                if vc_intersection.is_satisfied() and \
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   715
                    not vc_intersection.is_empty():
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   716
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   717
                # Apply the link to the current path to get the new relevant
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   718
                # path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   719
                next_path = os.path.normpath(os.path.join(
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   720
                    os.path.dirname(cur_path), rel_target,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   721
                    *lst[index:])).lstrip(os.path.sep)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   722
                # Index is reset back to the default because an element in path
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   723
                # the link provides could actually be a link.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   724
                rec_paths, link_deps = resolve_links(next_path, files_dict,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   725
                    links, vc_intersection, file_dep_attrs)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   726
                if not rec_paths:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   727
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   728
                # The current path was able to be resolved to a real path, so
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   729
                # add the paths and the dependencies from links found to the
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   730
                # results.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   731
                res_links.extend(link_deps)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   732
                res_paths.extend(rec_paths)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   733
                # Now add in the dependencies for the current link.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   734
                for rec_path, rec_pfmri, rec_vc in rec_paths:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   735
                        attrs = file_dep_attrs.copy()
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   736
                        attrs.update({
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   737
                            "fmri": link_pfmri.get_short_fmri(),
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   738
                            type_prefix: "link",
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   739
                            target_prefix: next_path,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   740
                            files_prefix: path
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   741
                        })
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   742
                        attrs.pop(paths_prefix, None)
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   743
                        attrs.pop(fullpaths_prefix, None)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   744
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   745
                        assert vc_intersection.intersects(rec_vc), \
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   746
                            "vc:%s\nvc_intersection:%s" % \
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   747
                            (rec_vc, vc_intersection)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   748
                        # The dependency is created with the same variants as
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   749
                        # the path.  This works because the set of relevant
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   750
                        # variants is restricted as links are applied so the
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   751
                        # variants used for the path are the intersection of
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   752
                        # the variants for each of the links used to reach the
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   753
                        # path and the variants under which the file is
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   754
                        # delivered.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   755
                        res_links.append((
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   756
                            actions.depend.DependencyAction(**attrs), rec_vc))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   757
        return res_paths, res_links
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   758
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   759
def find_package_using_delivered_files(files_dict, links, file_dep, dep_vars,
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   760
    orig_dep_vars):
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   761
        """Maps a dependency on a file to the packages which can satisfy that
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   762
        dependency.
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   763
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   764
        'files_dict' is a dictionary mapping paths to a list of fmri, variants
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   765
        pairs.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   766
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   767
        'links' is an Entries namedtuple which contains two dictionaries.  One
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   768
        dictionary maps package identity to the links that it delivers.  The
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   769
        other dictionary, contains the same information for links that are
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   770
        installed on the system.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   771
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   772
        'file_dep' is the dependency that is being resolved.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   773
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   774
        'dep_vars' are the variants for which the dependency has not yet been
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   775
        resolved.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   776
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   777
        'orig_dep_vars' is the original set of variants under which the
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   778
        dependency must be satisfied."""
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   779
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   780
        res = []
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   781
        errs = []
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   782
        link_deps = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   783
        multiple_path_errs = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   784
        multiple_path_pkgs = set()
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   785
        for p in make_paths(file_dep):
2191
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   786
                # If orig_dep_vars is satisfied, then this function should never
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   787
                # have been called.
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   788
                assert(orig_dep_vars.is_empty() or
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   789
                    not orig_dep_vars.is_satisfied())
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   790
                paths_info, path_deps = resolve_links(os.path.normpath(p),
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   791
                    files_dict, links, orig_dep_vars, file_dep.attrs.copy())
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   792
                link_deps.extend(path_deps)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   793
                delivered_list = \
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   794
                    [(pfmri, vc) for (path, pfmri, vc) in paths_info]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   795
                try:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   796
                        new_res, dep_vars = helper(delivered_list, file_dep,
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   797
                            dep_vars, orig_dep_vars)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   798
                except AmbiguousPathError, e:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   799
                        errs.append(e)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   800
                else:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   801
                        # We know which path satisfies this dependency, so
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   802
                        # remove the list of files and paths, and replace them
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   803
                        # with the single path that works.
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   804
                        for na, nv in new_res:
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   805
                                na.attrs.pop(paths_prefix, None)
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   806
                                na.attrs.pop(fullpaths_prefix, None)
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   807
                                na.attrs[files_prefix] = [p]
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   808
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   809
                        if not res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   810
                                res = new_res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   811
                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   812
                        # If there are previous results, then it's necessary to
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   813
                        # check the new results against the previous results
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   814
                        # to see if different paths for the same dependency are
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   815
                        # satisfied by different packages.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   816
                        for a, v in res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   817
                                for new_a, new_v in new_res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   818
                                        if a.attrs["fmri"] == \
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   819
                                            new_a.attrs["fmri"]:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   820
                                                a.attrs[files_prefix].extend(
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   821
                                                    new_a.attrs[files_prefix])
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   822
                                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   823
                                        # Check to see if there's a
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   824
                                        # configuration of variants under which
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   825
                                        # both packages can deliver a path which
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   826
                                        # satisfies the dependencies.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   827
                                        if v.intersects(new_v):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   828
                                                multiple_path_errs.append((a,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   829
                                                    new_a,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   830
                                                    v.intersection(new_v)))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   831
                                                multiple_path_pkgs.add(a)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   832
                                                multiple_path_pkgs.add(new_a)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   833
                                        elif new_v.intersects(v):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   834
                                                multiple_path_errs.append((a,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   835
                                                    new_a,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   836
                                                    new_v.intersection(v)))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   837
                                                multiple_path_pkgs.add(a)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   838
                                                multiple_path_pkgs.add(new_a)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   839
                                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   840
                                                res.append((new_a, new_v))
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   841
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   842
        for a1, a2, vc in multiple_path_errs:
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   843
                errs.append(MultiplePackagesPathError([a1, a2],
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   844
                    file_dep, vc))
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   845
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   846
        # Extract the actions from res, and only return those which don't have
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   847
        # multiple path errors.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   848
        return [(a, v) for a, v in res if a not in multiple_path_pkgs] + \
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   849
            link_deps, dep_vars, errs
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   850
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   851
def find_package(files, links, file_dep, pkg_vars, use_system):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   852
        """Find the packages which resolve the dependency. It returns a list of
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   853
        dependency actions with the fmri tag resolved.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   854
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   855
        'files' is an Entries namedtuple which contains two dictionaries.  One
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   856
        dictionary maps package identity to the files that it delivers.  The
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   857
        other dictionary, contains the same information for files that are
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   858
        installed on the system.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   859
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   860
        'links' is an Entries namedtuple which contains two dictionaries.  One
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   861
        dictionary maps package identity to the links that it delivers.  The
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   862
        other dictionary, contains the same information for links that are
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   863
        installed on the system.
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   864
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   865
        'file_dep' is the dependency being resolved.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   866
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   867
        'pkg_vars' is the variants against which the package was published."""
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   868
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   869
        file_dep, orig_dep_vars = split_off_variants(file_dep, pkg_vars)
2191
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   870
        # If the file dependency has already satisfied all its variants, then
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   871
        # this function should never have been called.
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   872
        assert(orig_dep_vars.is_empty() or not orig_dep_vars.is_satisfied())
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   873
        dep_vars = copy.copy(orig_dep_vars)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   874
        # First try to resolve the dependency against the delivered files.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   875
        res, dep_vars, errs = find_package_using_delivered_files(
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   876
                files.delivered, links, file_dep, dep_vars, orig_dep_vars)
2191
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   877
        # If dep_vars is satisfied then we found at least one solution.  It's
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   878
        # possible that more than one solution was found, causing an error.
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   879
        assert(not dep_vars.is_satisfied() or
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   880
            (res or errs or dep_vars.is_empty()))
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   881
        if ((res or errs) and dep_vars.is_satisfied()) or not use_system:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   882
                return res, dep_vars, errs
1934
4afdb552a5ec 15647 pkgdepend generates duplicate dependencies if dependency can't be satisfied for all variant values
Richard Lowe <richlowe@richlowe.net>
parents: 1933
diff changeset
   883
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   884
        # If the dependency isn't fully satisfied, resolve it against the
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   885
        # files installed in the current image.
1934
4afdb552a5ec 15647 pkgdepend generates duplicate dependencies if dependency can't be satisfied for all variant values
Richard Lowe <richlowe@richlowe.net>
parents: 1933
diff changeset
   886
        #
4afdb552a5ec 15647 pkgdepend generates duplicate dependencies if dependency can't be satisfied for all variant values
Richard Lowe <richlowe@richlowe.net>
parents: 1933
diff changeset
   887
        # We only need to resolve for the variants not already satisfied
4afdb552a5ec 15647 pkgdepend generates duplicate dependencies if dependency can't be satisfied for all variant values
Richard Lowe <richlowe@richlowe.net>
parents: 1933
diff changeset
   888
        # above.
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   889
        const_dep_vars = copy.copy(dep_vars)
2191
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   890
        # If dep_vars has been satisfied, then we should have exited the
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   891
        # function above.
da5a579210cc 17700 pkgdep can trace back when two packages deliver paths which satisfy a dependency
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2159
diff changeset
   892
        assert(const_dep_vars.is_empty() or not const_dep_vars.is_satisfied())
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   893
        inst_res, dep_vars, inst_errs = find_package_using_delivered_files(
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   894
            files.installed, links, file_dep, dep_vars, const_dep_vars)
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   895
        res.extend(inst_res)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   896
        errs.extend(inst_errs)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   897
        return res, dep_vars, errs
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   898
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   899
def is_file_dependency(act):
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   900
        return act.name == "depend" and \
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   901
            act.attrs.get("fmri", None) == base.Dependency.DUMMY_FMRI and \
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   902
            (files_prefix in act.attrs or fullpaths_prefix in act.attrs)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   903
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   904
def merge_deps(dest, src):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   905
        """Add the information contained in src's attrs to dest."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   906
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   907
        for k, v in src.attrs.items():
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   908
                # If any of these dependencies already have a variant set,
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   909
                # then something's gone horribly wrong.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   910
                assert(not k.startswith("variant."))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   911
                if k not in dest.attrs:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   912
                        dest.attrs[k] = v
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   913
                elif v != dest.attrs[k]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   914
                        # For now, just merge the values. Duplicate values
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   915
                        # will be removed in a later step.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   916
                        if isinstance(v, basestring):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   917
                                v = [v]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   918
                        if isinstance(dest.attrs[k], list):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   919
                                dest.attrs[k].extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   920
                        else:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   921
                                t = [dest.attrs[k]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   922
                                t.extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   923
                                dest.attrs[k] = t
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   924
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   925
def combine(deps, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   926
        """Combine duplicate dependency actions.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   927
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   928
        'deps' is a list of tuples. Each tuple contains a dependency action and
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   929
        the variants associated with that dependency.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   930
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   931
        'pkg_vars' are the variants that the package for which dependencies are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   932
        being generated was published against."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   933
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   934
        def action_group_key(d):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   935
                """Return a key on which the tuples can be sorted and grouped
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   936
                so that the groups match the duplicate actions that the code
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   937
                in pkg.manifest notices."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   938
2283
c368082b6a17 16499 pkgdepend resolve -mo includes manifest path in output stream
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2275
diff changeset
   939
                # d is a tuple containing two items.  d[0] is the action.  d[1]
c368082b6a17 16499 pkgdepend resolve -mo includes manifest path in output stream
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2275
diff changeset
   940
                # is the VariantCombination for this action.  The
c368082b6a17 16499 pkgdepend resolve -mo includes manifest path in output stream
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2275
diff changeset
   941
                # VariantCombination isn't useful for our grouping needs.
c368082b6a17 16499 pkgdepend resolve -mo includes manifest path in output stream
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2275
diff changeset
   942
                return d[0].name, d[0].attrs.get("type", None), \
c368082b6a17 16499 pkgdepend resolve -mo includes manifest path in output stream
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2275
diff changeset
   943
                    d[0].attrs.get(d[0].key_attr, id(d[0]))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   944
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   945
        def add_vars(d, d_vars, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   946
                """Add the variants 'd_vars' to the dependency 'd', after
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   947
                removing the variants matching those defined in 'pkg_vars'."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   948
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   949
                d_vars.simplify(pkg_vars)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   950
                res = []
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   951
                for s in d_vars.sat_set:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   952
                        attrs = d.attrs.copy()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   953
                        attrs.update(s)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   954
                        t = actions.depend.DependencyAction(**attrs)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   955
                        t.consolidate_attrs()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   956
                        res.append(t)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   957
                if not res:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   958
                        d.consolidate_attrs()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   959
                        res = [d]
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   960
                return res
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   961
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   962
        def key_on_variants(a):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   963
                """Return the key (the VariantSets) to sort the grouped tuples
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   964
                by."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   965
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   966
                return a[1]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   967
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   968
        def sort_by_variant_subsets(a, b):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   969
                """Sort the tuples so that those actions whose variants are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   970
                supersets of others are placed at the front of the list.  This
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   971
                function assumes that a and b are both VariantSets."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   972
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   973
                if a.issubset(b, satisfied=True):
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   974
                        return 1
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   975
                elif b.issubset(a, satisfied=True):
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   976
                        return -1
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   977
                return 0
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   978
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   979
        # Here is an example of how this code should work.  Assume that the code
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   980
        # is looking at dependencies for a package published against
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   981
        # variant.foo = bar, baz and variant.num = one, two.  These are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   982
        # abbreviated below as v.f and v.n.  The following dependencies have
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   983
        # been found for this package:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   984
        # 1) depend pkg_a reason=file_1, VariantSet is v.f=bar,baz v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   985
        # 2) depend pkg_a reason=file_2, VariantSet is v.f=bar v.n=one
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   986
        # 3) depend pkg_b reason=file_3, VariantSet is v.f=bar v.n=one
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   987
        # 4) depend pkg_b reason=file_3, VariantSet is v.f=baz v.n=two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   988
        # 5) depend pkg_b reason=file_3 path=p1, VariantSet is v.f=bar
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   989
        #        v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   990
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   991
        # First, these dependencies are grouped by their fmris.  This produces
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   992
        # two lists, the first contains dependencies 1 and 2, the second
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   993
        # contains dependencies 3, 4, and 5.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   994
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   995
        # The first group of dependencies is sorted by their VariantSet's.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   996
        # Dependency 1 comes before dependency 2 because 2's variants are a
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   997
        # subset of 1's variants.  Dependency 1 is put in the temporary result
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   998
        # list (subres) since at least one dependency on pkg_a must exist.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   999
        # Next, dependency 2 is compared to dependency 1 to see if it its
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1000
        # variants are subset of 1's. Since they are, the two dependencies are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1001
        # merged.  This means that values of all tags in either dependency
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1002
        # appear in the merged dependency.  In this case, the merged dependency
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1003
        # would look something like:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1004
        # depend pkg_a reason=file_1 reason=file_2
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1005
        # The variant set associated with the merged dependency would still be
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1006
        # dependency 1's variant set.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1007
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1008
        # The last thing that happens with this group of dependencies is that
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1009
        # add_vars is called on each result.  This first removes those variants
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1010
        # which match the package's identically.  What remains is added to the
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1011
        # dependency's attribute dictionary.  Since the package variants and the
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1012
        # dependency's variants are identical in this case, nothing is added.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1013
        # Lastly, any duplicate values for a tag are removed.  Again, since
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1014
        # there are no duplicates, nothing is changed.  The final dependency
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1015
        # that's added to final_res is:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1016
        # depend pkg_a reason=file_1 reason=file_2
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1017
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1018
        # The second group of dependencies is also sorted by their VariantSet's.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1019
        # This sort is a partial ordering.  Dependency 5 must come before
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1020
        # dependency 3, but dependency 4 can be anywhere in the list.  Let's
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1021
        # assume that the order is [4, 5, 3].
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1022
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1023
        # Dependency 4 is added to the temporary result list (subres).
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1024
        # Dependency 5 is checked to see if its variants are subset of 4's
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1025
        # variants.  Since they are not, dependency 5 is added to subres.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1026
        # Dependency 3 is checked against 4 to see if its variants are a subset.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1027
        # Since they're not, 3's variants are then checked against 5's variants.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1028
        # Since 3's variants are a subset of 5's variants, 3 is merged with 5,
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1029
        # producing this dependency:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1030
        # depend pkg_b reason=file_3 reason=file_3 path=p1, VariantSet is
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1031
        # v.f=bar v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1032
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1033
        # The two results from this group (dependency 4 and the merge of 5 and
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1034
        # 3) than has add_vars called on it.  The final results are:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1035
        # dependency pkg_b reason=file_3 v.f=baz v.n=two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1036
        # dependency pkg_b reason=file_3 path=p1 v.f=bar
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1037
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1038
        # The v.n tags have been removed from the second result because they
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1039
        # were identical to the package's variants.  The duplicate reasons have
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1040
        # also been coalesced.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1041
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1042
        # After everything is done, the final set of dependencies for this
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1043
        # package are:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1044
        # depend pkg_a reason=file_1 reason=file_2
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1045
        # dependency pkg_b reason=file_3 v.f=baz v.n=two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1046
        # dependency pkg_b reason=file_3 path=p1 v.f=bar
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1047
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1048
        res = []
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1049
        # For each group of dependencies (g) for a particular fmri (k) ...
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1050
        for k, g in itertools.groupby(sorted(deps, key=action_group_key),
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1051
            action_group_key):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1052
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1053
                # Sort the dependencies so that any dependency whose variants
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1054
                # are a subset of the variants of another dependency follow it.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1055
                glist = sorted(g, cmp=sort_by_variant_subsets,
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1056
                    key=key_on_variants)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1057
                subres = [glist[0]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1058
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1059
                # d is a dependency action. d_vars are the variants under which
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1060
                # d will be applied.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1061
                for d, d_vars in glist[1:]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1062
                        found_subset = False
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1063
                        for rel_res, rel_vars in subres:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1064
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1065
                                # If d_vars is a subset of any variant set
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1066
                                # already in the results, then d should be
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1067
                                # combined with that dependency.
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1068
                                if d_vars.issubset(rel_vars, satisfied=True):
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1069
                                        found_subset = True
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1070
                                        merge_deps(rel_res, d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1071
                                        break
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1072
                                assert(not rel_vars.issubset(d_vars,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1073
                                    satisfied=True))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1074
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1075
                        # If no subset was found, then d_vars is a new set of
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1076
                        # conditions under which the dependency d should apply
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1077
                        # so add it to the results.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1078
                        if not found_subset:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1079
                                subres.append((d, d_vars))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1080
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1081
                # Add the variants to the dependency action and remove any
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1082
                # variants that are identical to those defined by the package.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1083
                subres = [add_vars(d, d_vars, pkg_vars) for d, d_vars in subres]
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1084
                res.extend(itertools.chain.from_iterable(subres))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1085
        return res
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1086
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1087
def split_off_variants(dep, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1088
        """Take a dependency which may be tagged with variants and move those
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1089
        tags into a VariantSet."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1090
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1091
        dep_vars = dep.get_variant_template()
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1092
        dep_vars.merge_unknown(pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1093
        # Since all variant information is being kept in the above VariantSets,
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1094
        # remove the variant information from the action.  This prevents
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1095
        # confusion about which is the authoritative source of information.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1096
        dep.strip_variants()
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1097
        return dep, variants.VariantCombinations(dep_vars, satisfied=False)
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1098
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1099
def prune_debug_attrs(action):
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1100
        """Given a dependency action with pkg.debug.depend attributes
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1101
        return a matching action with those attributes removed"""
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1102
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1103
        attrs = dict((k, v) for k, v in action.attrs.iteritems()
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1104
                     if not k.startswith(base.Dependency.DEPEND_DEBUG_PREFIX))
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1105
        return actions.depend.DependencyAction(**attrs)
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1106
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1107
def add_fmri_path_mapping(files_dict, links_dict, pfmri, mfst,
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1108
    distro_vars=None):
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1109
        """Add mappings from path names to FMRIs and variants.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1110
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1111
        'files_dict' is a dictionary which maps package identity to the files
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1112
        the package delivers and the variants under which each file is
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1113
        present.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1114
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1115
        'links_dict' is a dictionary which maps package identity to the links
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1116
        the package delivers and the variants under which each link is
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1117
        present.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1118
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1119
        'pfmri' is the FMRI of the current manifest.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1120
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1121
        'mfst' is the manifest to process.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1122
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1123
        'distro_vars' is a VariantCombinationTemplate which contains all the
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1124
        variant types and values known."""
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1125
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1126
        pvariants = mfst.get_all_variants()
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1127
        if distro_vars:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1128
                pvariants.merge_unknown(distro_vars)
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1129
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1130
        for f in mfst.gen_actions_by_type("file"):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1131
                dep_vars = f.get_variant_template()
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1132
                dep_vars.merge_unknown(pvariants)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1133
                vc = variants.VariantCombinations(dep_vars,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1134
                    satisfied=True)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1135
                files_dict.setdefault(f.attrs["path"], []).append(
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1136
                    (pfmri, vc))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1137
        for f in itertools.chain(mfst.gen_actions_by_type("hardlink"),
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1138
             mfst.gen_actions_by_type("link")):
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1139
                dep_vars = f.get_variant_template()
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1140
                dep_vars.merge_unknown(pvariants)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1141
                vc = variants.VariantCombinations(dep_vars,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1142
                    satisfied=True)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1143
                links_dict.setdefault(f.attrs["path"], []).append(
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1144
                    (pfmri, vc, f.attrs["target"]))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1145
1886
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
  1146
def resolve_deps(manifest_paths, api_inst, prune_attrs=False, use_system=True):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1147
        """For each manifest given, resolve the file dependencies to package
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1148
        dependencies. It returns a mapping from manifest_path to a list of
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1149
        dependencies and a list of unresolved dependencies.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1150
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1151
        'manifest_paths' is a list of paths to the manifests being resolved.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1152
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1153
        'api_inst' is an ImageInterface which references the current image.
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1154
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1155
        'prune_attrs' is a boolean indicating whether debugging
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1156
        attributes should be stripped from returned actions."""
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1157
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1158
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1159
        # The variable 'manifests' is a list of 5-tuples. The first element
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1160
        # of the tuple is the path to the manifest. The second is the name of
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1161
        # the package contained in the manifest. The third is the manifest
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1162
        # object for the manifest in that location. The fourth is the list of
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1163
        # variants the package was published against. The fifth is the list of
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1164
        # files referenced in the manifest that couldn't be found.
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1165
        manifests = [
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1166
            (mp, choose_name(mp, mfst), mfst, mfst.get_all_variants(),
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1167
            missing_files)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1168
            for mp, (mfst, missing_files) in
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1169
            ((mp, __make_manifest(mp, load_data=False))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1170
            for mp in manifest_paths)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1171
        ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1172
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1173
        files = Entries({}, {})
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1174
        links = Entries({}, {})
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1175
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1176
        # This records all the variants used in any package known.  It is used
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1177
        # to ensure that all packages live in the same variant universe for
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1178
        # purposes of dependency resolution.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1179
        distro_vars = variants.VariantCombinationTemplate()
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1180
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1181
        for mp, name, mfst, pkg_vars, miss_files in manifests:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1182
                distro_vars.merge_values(pkg_vars)
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1183
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1184
        pkg_list = None
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1185
        if use_system:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1186
                # We make this a list because we want to reuse the list of
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1187
                # packages again, and despite it's name, get_pkg_list is a
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1188
                # generator.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1189
                pkg_list = list(api_inst.get_pkg_list(
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1190
                    api.ImageInterface.LIST_INSTALLED))
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1191
                for (pub, stem, ver), summ, cats, states in pkg_list:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1192
                        pfmri = fmri.PkgFmri("pkg:/%s@%s" % (stem, ver))
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1193
                        mfst = api_inst.get_manifest(pfmri, all_variants=True)
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1194
                        distro_vars.merge_values(mfst.get_all_variants())
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1195
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1196
        # Build a list of all files delivered in the manifests being resolved.
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1197
        for mp, name, mfst, pkg_vars, miss_files in manifests:
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1198
                pfmri = fmri.PkgFmri(name)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1199
                add_fmri_path_mapping(files.delivered, links.delivered, pfmri,
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1200
                    mfst, distro_vars)
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1201
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
  1202
        # Build a list of all files delivered in the packages installed on
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
  1203
        # the system.
1886
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
  1204
        if use_system:
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1205
                for (pub, stem, ver), summ, cats, states in pkg_list:
1886
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
  1206
                        pfmri = fmri.PkgFmri("pkg:/%s@%s" % (stem, ver))
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
  1207
                        mfst = api_inst.get_manifest(pfmri, all_variants=True)
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1208
                        add_fmri_path_mapping(files.installed, links.installed,
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1209
                            pfmri, mfst, distro_vars)
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1210
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1211
        if pkg_list:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1212
                del pkg_list
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
  1213
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1214
        pkg_deps = {}
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1215
        errs = []
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
  1216
        for mp, name, mfst, pkg_vars, miss_files in manifests:
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1217
                # The add_fmri_path_mapping function moved the actions it found
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1218
                # into the distro_vars universe of variants, so we need to move
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1219
                # pkg_vars (and by extension the variants on depend actions)
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1220
                # into that universe too.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1221
                pkg_vars.merge_unknown(distro_vars)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1222
                errs.extend(miss_files)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1223
                if mfst is None:
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1224
                        pkg_deps[mp] = None
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1225
                        continue
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1226
                pkg_res = [
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1227
                    (d, find_package(files, links, d, pkg_vars,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1228
                        use_system))
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1229
                    for d in mfst.gen_actions_by_type("depend")
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1230
                    if is_file_dependency(d)
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1231
                ]
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1232
                # Seed the final results with those dependencies defined
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1233
                # manually.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1234
                deps = [
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1235
                    split_off_variants(d, pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1236
                    for d in mfst.gen_actions_by_type("depend")
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1237
                    if not is_file_dependency(d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1238
                ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1239
                for file_dep, (res, dep_vars, pkg_errs) in pkg_res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1240
                        errs.extend(pkg_errs)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1241
                        dep_vars.simplify(pkg_vars)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1242
                        if not res:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1243
                                errs.append(UnresolvedDependencyError(mp,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1244
                                    file_dep, dep_vars))
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1245
                        else:
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1246
                                deps.extend(res)
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1247
                                if not dep_vars.is_satisfied():
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1248
                                        errs.append(UnresolvedDependencyError(
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1249
                                            mp, file_dep, dep_vars))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1250
                # Add variant information to the dependency actions and combine
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1251
                # what would otherwise be duplicate dependencies.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1252
                deps = combine(deps, pkg_vars)
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1253
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1254
                if prune_attrs:
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1255
                        deps = [prune_debug_attrs(d) for d in deps]
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1256
                pkg_deps[mp] = deps
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1257
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
  1258
        return pkg_deps, errs