src/modules/publish/dependencies.py
author Brock Pytlik <brock.pytlik@oracle.com>
Fri, 24 Jun 2011 18:55:54 -0700
changeset 2428 25adeb0b7928
parent 2411 936617650fa1
child 2462 d89a0da0a548
permissions -rw-r--r--
16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
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
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
    29
import operator
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    30
import os
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    31
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
    32
import urllib
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    33
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    34
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
    35
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    36
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
    37
import pkg.client.api as api
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
    38
import pkg.client.api_errors as apx
1231
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.base as base
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.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
    41
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
    42
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
    43
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
    44
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
    45
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
    46
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
    47
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
    48
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    49
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
    50
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
    51
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
    52
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
    53
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
    54
bypassed_prefix = "%s.bypassed" % base.Dependency.DEPEND_DEBUG_PREFIX
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
    55
via_links_prefix = "%s.via-links" % base.Dependency.DEPEND_DEBUG_PREFIX
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    56
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    57
# 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
    58
# contents, used when bypassing dependency generation
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
    59
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
    60
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
    61
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
    62
# 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
    63
# 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
    64
# 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
    65
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    66
class DependencyError(Exception):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    67
        """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
    68
        pass
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    69
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    70
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
    71
        """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
    72
        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
    73
        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
    74
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    75
        def __set_pkg_name(self, name):
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    76
                self.__pkg_name = str(name)
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    77
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    78
        pkg_name = property(lambda self: self.__pkg_name, __set_pkg_name)
2428
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
    79
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    80
        def __init__(self, res, source, vc, pkg_name=None):
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    81
                self.res = res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    82
                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
    83
                self.vc = vc
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    84
                self.pkg_name = pkg_name
2428
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
    85
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    86
        def __str__(self):
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    87
                if self.vc.sat_set and self.pkg_name:
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    88
                        return _("The file dependency %(src)s delivered in "
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    89
                            "package %(pkg)s has paths which resolve to "
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    90
                            "multiple packages under this combination of "
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    91
                            "variants:\n%(vars)s\nThe actions "
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    92
                            "are:\n%(acts)s") % {
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    93
                                "src":self.source,
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    94
                                "acts":"\n".join(
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    95
                                    ["\t%s" % a for a in self.res]),
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    96
                                "vars":"\n".join([
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    97
                                    " ".join([
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    98
                                        ("%s:%s" % (name, val))
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
    99
                                        for name, val in grp
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   100
                                    ])
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   101
                                    for grp in self.vc.sat_set]),
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   102
                                "pkg": self.pkg_name
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   103
                            }
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   104
                elif self.vc.sat_set:
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   105
                        return _("The file dependency %(src)s has paths which"
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   106
                            "resolve to multiple packages under this "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   107
                            "combination of variants:\n%(vars)s\nThe actions "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   108
                            "are:\n%(acts)s") % {
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   109
                                "src":self.source,
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   110
                                "acts":"\n".join(
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   111
                                    ["\t%s" % a for a in self.res]),
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   112
                                "vars":"\n".join([
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   113
                                    " ".join([
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   114
                                        ("%s:%s" % (name, val))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   115
                                        for name, val in grp
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   116
                                    ])
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   117
                                    for grp in self.vc.sat_set])
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   118
                            }
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   119
                elif self.pkg_name:
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   120
                        return _("The file dependency %(src)s delivered in "
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   121
                            "%(pkg)s has paths which resolve to multiple "
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   122
                            "packages.\nThe actions are:\n%(acts)s") % {
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   123
                                "src":self.source,
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   124
                                "acts":"\n".join(
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   125
                                ["\t%s" % a for a in self.res]),
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   126
                                "pkg":self.pkg_name
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
   127
                            }
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   128
                else:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   129
                        return _("The file dependency %(src)s has paths which "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   130
                            "resolve to multiple packages.\nThe actions "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   131
                            "are:\n%(acts)s") % {
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   132
                                "src":self.source,
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   133
                                "acts":"\n".join(
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   134
                                ["\t%s" % a for a in self.res])
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   135
                            }
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   136
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   137
class AmbiguousPathError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   138
        """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
   139
        is depended upon."""
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   140
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   141
        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
   142
                self.pkgs = pkgs
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   143
                self.source = source
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   144
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   145
        def __str__(self):
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   146
                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
   147
                    "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
   148
                    "are:%(pkgs)s") % {
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   149
                        "src":self.source,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   150
                        "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
   151
                    }
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   152
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   153
class UnresolvedDependencyError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   154
        """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
   155
        depended upon."""
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   156
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   157
        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
   158
                self.path = pth
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   159
                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
   160
                self.pvars = pvars
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
        def __str__(self):
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   163
                if self.pvars.not_sat_set:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   164
                        return _("%(pth)s has unresolved dependency '%(dep)s' "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   165
                            "under the following combinations of "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   166
                            "variants:\n%(combo)s") % \
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   167
                            {
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   168
                                "pth":self.path,
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   169
                                "dep":self.file_dep,
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   170
                                "combo":"\n".join([
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   171
                                    " ".join([
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   172
                                        ("%s:%s" % (name, val))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   173
                                        for name, val in sorted(grp)
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   174
                                    ])
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   175
                                    for grp in self.pvars.not_sat_set
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   176
                            ])}
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   177
                else:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   178
                        return _("%(pth)s has unresolved dependency "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   179
                            "'%(dep)s'.") % \
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   180
                            { "pth":self.path, "dep":self.file_dep }
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   181
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   182
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   183
class MissingPackageVariantError(DependencyError):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   184
        """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
   185
        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
   186
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   187
        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
   188
                self.act_vars = act_vars
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   189
                self.pkg_vars = pkg_vars
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   190
                self.path = pth
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   191
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   192
        def __str__(self):
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   193
                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
   194
                    "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
   195
                    "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
   196
                    "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
   197
                    "variants are: %(pkg)s") % {
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   198
                        "path": self.path,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   199
                        "act": self.act_vars,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   200
                        "pkg": self.pkg_vars
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   201
                    }
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   202
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   203
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   204
class BadDependencyFmri(DependencyError):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   205
        """This exception is used when dependency actions have text in their
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   206
        fmri attributes which are not valid fmris."""
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   207
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   208
        def __init__(self, pkg, fmris):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   209
                self.pkg = pkg
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   210
                self.fmris = fmris
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   211
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   212
        def __str__(self):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   213
                return _("The package %(pkg)s contains depend actions with "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   214
                    "values in their fmri attributes which are not valid "
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   215
                    "fmris.  The bad values are:\n%(fmris)s\n") % {
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   216
                    "pkg": self.pkg,
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   217
                    "fmris": "\n".join(["\t%s" % f for f in sorted(self.fmris)])
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   218
                }
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   219
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   220
2428
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   221
class BadPackageFmri(DependencyError):
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   222
        """This exception is used when a manifest's fmri isn't a valid fmri."""
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   223
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   224
        def __init__(self, path, e):
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   225
                self.path = path
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   226
                self.exc = e
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   227
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   228
        def __str__(self):
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   229
                return _("The manifest '%(path)s' has an invalid package "
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   230
                    "FMRI:\n\t%(exc)s") % { "path": self.path, "exc": self.exc }
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   231
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
   232
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   233
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
   234
    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
   235
        """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
   236
        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
   237
        the manifest have.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   238
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   239
        '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
   240
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   241
        '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
   242
        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
   243
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   244
        '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
   245
        $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
   246
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   247
        '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
   248
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   249
        '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
   250
        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
   251
        option to facilitate testing and debugging.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   252
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   253
        '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
   254
        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
   255
        facilitate testing and debugging.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   256
        """
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   257
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   258
        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
   259
        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
   260
        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
   261
            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
   262
            ignore_bypass=ignore_bypass)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   263
        rid_errs = []
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   264
        if remove_internal_deps:
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   265
                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
   266
                    pkg_vars)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   267
        if convert:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   268
                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
   269
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   270
        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
   271
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   272
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
   273
        """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
   274
        pkg.actions.dependency.Dependency objects."""
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   275
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   276
        res = []
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   277
        for d in deps:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   278
                tmp = []
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   279
                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
   280
                        attrs = d.attrs.copy()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   281
                        attrs.update(c)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   282
                        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
   283
                if not tmp:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   284
                        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
   285
                res.extend(tmp)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   286
        return res
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   287
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   288
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
   289
        """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
   290
        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
   291
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   292
        '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
   293
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   294
        '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
   295
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   296
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   297
        '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
   298
        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
   299
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
   300
        '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
   301
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   302
        res = []
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   303
        errs = []
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   304
        delivered = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   305
        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
   306
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   307
        files = Entries({}, {})
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   308
        links = {}
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   309
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   310
        # 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
   311
        # 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
   312
        # a private construction which should not escape to the user.
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   313
        add_fmri_path_mapping(files.delivered, links,
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   314
            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
   315
        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
   316
                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
   317
                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
   318
                        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
   319
                else:
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   320
                        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
   321
                                # 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
   322
                                # 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
   323
                                # 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
   324
                                errs.append(
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   325
                                    MissingPackageVariantError(pvars, pkg_vars,
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   326
                                        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
   327
                        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
   328
                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
   329
                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
   330
                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
   331
                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
   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 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
   334
                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
   335
                    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
   336
                    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
   337
                    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
   338
                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
   339
                        continue
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   340
                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
   341
                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
   342
                res.append(d)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   343
        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
   344
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   345
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
   346
        """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
   347
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   348
        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
   349
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   350
# 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
   351
# 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
   352
dispatch_dict = {
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   353
    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
   354
    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
   355
    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
   356
    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
   357
}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   358
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   359
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
   360
    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
   361
        """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
   362
        files it installs.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   363
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   364
        '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
   365
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   366
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   367
        '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
   368
        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
   369
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   370
        '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
   371
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   372
        '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
   373
        $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
   374
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   375
        '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
   376
        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
   377
        '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
   378
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   379
        '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
   380
        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
   381
        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
   382
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   383
        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
   384
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   385
        '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
   386
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   387
        '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
   388
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   389
        '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
   390
        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
   391
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   392
        '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
   393
        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
   394
        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
   395
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   396
        deps = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   397
        elist = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   398
        missing = {}
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   399
        pkg_attrs = {}
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   400
        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
   401
        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
   402
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   403
        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
   404
                # 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
   405
                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
   406
                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
   407
                if es:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   408
                        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
   409
                run_paths = run_path_str.split(":")
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   410
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   411
        mf_bypass = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   412
        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
   413
                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
   414
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   415
        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
   416
                a = act_list[i]
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   417
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   418
                a_run_paths = run_paths
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   419
                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
   420
                        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
   421
                        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
   422
                        if es:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   423
                                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
   424
                        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
   425
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   426
                bypass = __makelist(
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   427
                    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
   428
                # 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
   429
                # calling our dispatch_dict function altogether.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   430
                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
   431
                        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
   432
                        continue
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   433
                try:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   434
                        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
   435
                except KeyError:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   436
                        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
   437
                                missing[file_type] = \
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   438
                                    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
   439
                else:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   440
                        try:
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   441
                                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
   442
                                    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
   443
                                    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
   444
                                    run_paths=a_run_paths)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   445
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   446
                                # 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
   447
                                # 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
   448
                                if bypass and not ignore_bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   449
                                        ds = \
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   450
                                            __bypass_deps(ds, bypass, pkg_attrs)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   451
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   452
                                deps.extend(ds)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   453
                                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
   454
                                __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
   455
                        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
   456
                                elist.append(e)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   457
        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
   458
                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
   459
        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
   460
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   461
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
   462
        """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
   463
        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
   464
                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
   465
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   466
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
   467
        """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
   468
        at least one non-null string."""
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   469
        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
   470
                # 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
   471
                # ordering in the future
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   472
                return [base.DependencyAnalysisError(
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   473
                    _("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
   474
                    "than a single colon-separated string.") %
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   475
                    portable.PD_RUN_PATH)]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   476
        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
   477
                return [base.DependencyAnalysisError(
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   478
                    _("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
   479
                    "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
   480
        return []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   481
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   482
def __makelist(value):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   483
        """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
   484
        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
   485
        if isinstance(value, list):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   486
                return value
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   487
        elif isinstance(value, str):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   488
                if value:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   489
                        return [value]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   490
                else:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   491
                        return []
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
                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
   494
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   495
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
   496
        """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
   497
        bypassed.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   498
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   499
        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
   500
        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
   501
        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
   502
                   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
   503
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   504
        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
   505
        one or more files.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   506
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   507
        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
   508
        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
   509
        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
   510
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   511
        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
   512
        rooted at ^ and $.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   513
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   514
        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
   515
        by list_implicit_deps_for_manifest(..)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   516
        """
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   517
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   518
        new_ds = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   519
        for dep in ds:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   520
                full_paths = set(make_paths(dep))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   521
                bypassed_files = set()
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   522
                bypass_regexps = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   523
                try:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   524
                        for item in bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   525
                                # 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
   526
                                # rather than a filename
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   527
                                if "*" in item or "?" in item:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   528
                                        pass
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   529
                                # 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
   530
                                # all paths to that filename.
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   531
                                elif "/" not in item:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   532
                                        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
   533
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   534
                                # always anchor our regular expressions,
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   535
                                # 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
   536
                                # 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
   537
                                # bypass "foo.cc"
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   538
                                if item:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   539
                                        if not item.endswith("$"):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   540
                                                item = item + "$"
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   541
                                        if not item.startswith("^"):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   542
                                                item = "^" + item
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   543
                                        bypass_regexps.append(re.compile(item))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   544
                except re.error, e:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   545
                        raise base.InvalidDependBypassValue(item, e)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   546
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   547
                for path in full_paths:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   548
                        if path in bypass:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   549
                                bypassed_files.add(path)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   550
                                continue
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   551
                        for regexp in bypass_regexps:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   552
                                if regexp.match(path):
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   553
                                        bypassed_files.add(path)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   554
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   555
                if bypassed_files:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   556
                        # 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
   557
                        # the dependency if they were present
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   558
                        dep.attrs.pop(files_prefix, None)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   559
                        dep.attrs.pop(paths_prefix, None)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   560
                        dep.base_names = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   561
                        dep.run_paths = []
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   562
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   563
                        # determine our new list of paths
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   564
                        full_paths = full_paths - bypassed_files
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   565
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   566
                        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
   567
                        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
   568
                        pkg_attrs[bypassed_prefix] = \
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   569
                            sorted(list(bypassed_files))
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   570
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   571
                        # 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
   572
                        if full_paths:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   573
                                new_ds.append(dep)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   574
                else:
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   575
                        new_ds.append(dep)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   576
        return new_ds
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   577
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   578
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
   579
        """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
   580
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
   581
        m = manifest.Manifest()
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   582
        try:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   583
                fh = open(fp, "rb")
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   584
        except EnvironmentError, e:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   585
                raise apx._convert_error(e)
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   586
        acts = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   587
        missing_files = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   588
        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   589
        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
   590
                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
   591
                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
   592
                        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
   593
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   594
                elif accumulate:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   595
                        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
   596
                        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   597
                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
   598
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   599
                try:
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   600
                        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
   601
                            basedirs=basedirs,
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   602
                            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
   603
                        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
   604
                                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
   605
                                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
   606
                                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
   607
                                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
   608
                        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
   609
                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
   610
                        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
   611
                            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
   612
                        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
   613
                                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
   614
                        else:
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   615
                                missing_files.append(base.MissingFile(
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   616
                                    new_a.attrs["path"], basedirs))
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   617
        fh.close()
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 1934
diff changeset
   618
        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
   619
        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
   620
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
   621
def choose_name(fp, mfst):
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   622
        """Find the package name for this manifest.  If it's defined in a set
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   623
        action in the manifest, use that.  Otherwise use the basename of the
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   624
        path to the manifest as the name.  If a proper package fmri is found,
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   625
        then also return a PkgFmri object so that we can track which packages
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   626
        are being processed.
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   627
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
   628
        '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
   629
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
   630
        '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
   631
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
   632
        if mfst is None:
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   633
                return urllib.unquote(os.path.basename(fp)), None
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1337
diff changeset
   634
        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
   635
        if name is not None:
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   636
                try:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   637
                        pfmri = fmri.PkgFmri(name)
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   638
                except fmri.IllegalFmri:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   639
                        pfmri = None
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   640
                return name, pfmri
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   641
        return urllib.unquote(os.path.basename(fp)), 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
   642
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   643
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
   644
        """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
   645
        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
   646
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
   647
        '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
   648
        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
   649
        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
   650
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
   651
        '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
   652
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
   653
        '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
   654
        satisfied.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   655
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   656
        '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
   657
        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
   658
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
   659
        res = []
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   660
        vars = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   661
        errs = set()
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   662
        for path, pfmri, delivered_vars, via_links in lst:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   663
                # 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
   664
                # 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
   665
                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
   666
                    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
   667
                        continue
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   668
                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
   669
                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
   670
                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
   671
                        # 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
   672
                        # 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
   673
                        # 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
   674
                        # 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
   675
                        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
   676
                            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
   677
                                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
   678
                                errs.add(pfmri)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   679
                # 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
   680
                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
   681
                # 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
   682
                # 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
   683
                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
   684
                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
   685
                attrs.update({"fmri":pfmri.get_short_fmri()})
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   686
                # We know which path satisfies this dependency, so remove the
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   687
                # list of files and paths, and replace them with the single path
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   688
                # that works.
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   689
                attrs.pop(paths_prefix, None)
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   690
                attrs.pop(fullpaths_prefix, None)
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   691
                attrs[files_prefix] = [path]
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   692
                if via_links:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   693
                        via_links.reverse()
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   694
                        attrs[via_links_prefix] = ":".join(via_links)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   695
                # 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
   696
                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
   697
                    action_vars))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   698
                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
   699
        if errs:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   700
                # 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
   701
                # 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
   702
                # situation is unresolvable.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   703
                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
   704
        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
   705
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   706
def make_paths(file_dep):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   707
        """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
   708
        'file_dep'."""
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   709
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   710
        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
   711
                return file_dep.attrs[fullpaths_prefix]
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   712
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   713
        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
   714
        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
   715
        if isinstance(files, basestring):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   716
                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
   717
        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
   718
                rps = [rps]
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   719
        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
   720
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   721
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
   722
        """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
   723
        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
   724
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   725
        '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
   726
        real path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   727
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   728
        '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
   729
        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
   730
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   731
        '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
   732
        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
   733
        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
   734
        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
   735
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   736
        '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
   737
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   738
        '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
   739
        for 'path'.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   740
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   741
        '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
   742
        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
   743
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   744
        res_paths = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   745
        res_links = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   746
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   747
        # 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
   748
        # the path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   749
        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
   750
                # 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
   751
                # 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
   752
                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
   753
                # 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
   754
                # 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
   755
                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
   756
                # 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
   757
                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
   758
                        # 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
   759
                        # 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
   760
                        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
   761
                                continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   762
                        # 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
   763
                        # 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
   764
                        # 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
   765
                        # 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
   766
                        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
   767
                        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
   768
                        tmp_vars.mark_as_satisfied(p_vc)
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   769
                        res_paths.append((path, pfmri, inter, []))
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   770
                # 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
   771
                # 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
   772
                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
   773
                        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
   774
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   775
        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
   776
        # 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
   777
        # 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
   778
        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
   779
                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
   780
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   781
        # 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
   782
        cur_path = os.path.join(*lst[0:index])
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   783
        # Find the links which match the path being checked.
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   784
        rel_links = links.get(cur_path, False)
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   785
        # 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
   786
        # 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
   787
        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
   788
                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
   789
                    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
   790
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   791
        links_found = {}
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   792
        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
   793
                # If the variants needed to reach the current path and the
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   794
                # variants for the link don't intersect, then the link is
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   795
                # irrelevant.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   796
                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
   797
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   798
                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
   799
                # 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
   800
                # 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
   801
                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
   802
                    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
   803
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   804
                # 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
   805
                # path.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   806
                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
   807
                    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
   808
                    *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
   809
                # 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
   810
                # 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
   811
                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
   812
                    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
   813
                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
   814
                        continue
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   815
                # 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
   816
                # 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
   817
                # results.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   818
                res_links.extend(link_deps)
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   819
                for rec_path, rec_pfmri, rec_vc, via_links in rec_paths:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   820
                        via_links.append(path)
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   821
                        assert vc_intersection.intersects(rec_vc), \
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   822
                            "vc:%s\nvc_intersection:%s" % \
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   823
                            (rec_vc, vc_intersection)
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   824
                res_paths.extend(rec_paths)
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   825
                links_found.setdefault(next_path, []).append(
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   826
                    (link_pfmri, rec_vc))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   827
        # Now add in the dependencies for the current link.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   828
        for next_path in links_found.keys():
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   829
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   830
                # Create a bin for each possible variant combination.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   831
                vcs = [(vc, []) for vc in path_vars.split_combinations()]
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   832
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   833
                # For each pfmri which delivers this link, if it intersects with
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   834
                # a variant combination, add it to that combination's bin.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   835
                for pfmri, pvc in links_found[next_path]:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   836
                        for vc, l in vcs:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   837
                                if pvc.intersects(vc):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   838
                                        l.append(pfmri)
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   839
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   840
                # Group the variant combinations by their bin of fmris.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   841
                sort_key = operator.itemgetter(1)
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   842
                for pfmris, group in itertools.groupby(
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   843
                    sorted(vcs, key=sort_key),
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   844
                    key=sort_key):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   845
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   846
                        # If pfmris is empty, then no packages delivered the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   847
                        # link under this combination of variants, so skip it.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   848
                        if not pfmris:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   849
                                continue
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   850
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   851
                        # Make a copy of path_vars which is unsatisfied, then
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   852
                        # mark the specific combinations which are satisfied by
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   853
                        # this group of pfmris.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   854
                        dep_vc = path_vars.unsatisfied_copy()
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   855
                        for vc, pfmris in group:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   856
                                dep_vc.mark_as_satisfied(vc)
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   857
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   858
                        dep_type = "require-any"
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   859
                        names = [p.get_short_fmri() for p in pfmris]
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   860
                        # If there's only one fmri delivering this link, then
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   861
                        # it's a require dependency, not a require-any.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   862
                        if len(pfmris) == 1:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   863
                                dep_type = "require"
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   864
                                names = names[0]
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   865
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   866
                        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
   867
                        attrs.update({
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   868
                            "fmri": names,
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   869
                            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
   870
                            target_prefix: next_path,
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   871
                            files_prefix: [path],
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   872
                            "type": dep_type
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   873
                        })
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   874
                        attrs.pop(paths_prefix, None)
2236
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   875
                        attrs.pop(fullpaths_prefix, None)
7b074b5316ec 16015 pkgdepend needs python runpath hints
Tim Foster <tim.s.foster@oracle.com>
parents: 2191
diff changeset
   876
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   877
                        # 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
   878
                        # 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
   879
                        # variants is restricted as links are applied so the
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   880
                        # variants used for the path are the intersection of the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   881
                        # variants for each of the links used to reach the path
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   882
                        # and the variants under which the file is delivered.
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   883
                        res_links.append((
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   884
                            actions.depend.DependencyAction(**attrs), dep_vc))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
   885
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   886
        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
   887
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   888
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
   889
    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
   890
        """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
   891
        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
   892
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   893
        '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
   894
        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
   895
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   896
        '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
   897
        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
   898
        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
   899
        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
   900
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
   901
        '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
   902
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
        '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
   904
        resolved.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   905
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   906
        '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
   907
        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
   908
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
   909
        res = []
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   910
        errs = []
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   911
        link_deps = []
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   912
        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
   913
        multiple_path_pkgs = set()
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   914
        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
   915
                # 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
   916
                # 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
   917
                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
   918
                    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
   919
                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
   920
                    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
   921
                link_deps.extend(path_deps)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   922
                try:
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
   923
                        new_res, dep_vars = helper(paths_info, file_dep,
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   924
                            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
   925
                except AmbiguousPathError, e:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   926
                        errs.append(e)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   927
                else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   928
                        if not res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   929
                                res = new_res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   930
                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   931
                        # 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
   932
                        # 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
   933
                        # 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
   934
                        # 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
   935
                        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
   936
                                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
   937
                                        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
   938
                                            new_a.attrs["fmri"]:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   939
                                                a.attrs[files_prefix].extend(
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   940
                                                    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
   941
                                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   942
                                        # 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
   943
                                        # 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
   944
                                        # 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
   945
                                        # 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
   946
                                        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
   947
                                                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
   948
                                                    new_a,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   949
                                                    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
   950
                                                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
   951
                                                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
   952
                                        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
   953
                                                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
   954
                                                    new_a,
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   955
                                                    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
   956
                                                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
   957
                                                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
   958
                                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   959
                                                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
   960
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   961
        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
   962
                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
   963
                    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
   964
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   965
        # 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
   966
        # 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
   967
        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
   968
            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
   969
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   970
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
   971
        """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
   972
        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
   973
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   974
        '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
   975
        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
   976
        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
   977
        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
   978
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
   979
        '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
   980
        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
   981
        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
   982
        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
   983
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
   984
        '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
   985
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   986
        '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
   987
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   988
        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
   989
        # 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
   990
        # 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
   991
        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
   992
        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
   993
        # 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
   994
        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
   995
                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
   996
        # 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
   997
        # 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
   998
        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
   999
            (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
  1000
        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
  1001
                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
  1002
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1003
        # 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
  1004
        # 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
  1005
        #
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
  1006
        # 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
  1007
        # above.
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1008
        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
  1009
        # 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
  1010
        # 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
  1011
        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
  1012
        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
  1013
            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
  1014
        res.extend(inst_res)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
  1015
        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
  1016
        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
  1017
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
  1018
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
  1019
        return act.name == "depend" and \
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1020
            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
  1021
            (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
  1022
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1023
def merge_deps(dest, src):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1024
        """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
  1025
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1026
        for k, v in src.attrs.items():
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1027
                # 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
  1028
                # then something's gone horribly wrong.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1029
                assert(not k.startswith("variant."))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1030
                if k not in dest.attrs:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1031
                        dest.attrs[k] = v
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1032
                elif v != dest.attrs[k]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1033
                        # 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
  1034
                        # will be removed in a later step.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1035
                        if isinstance(v, basestring):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1036
                                v = [v]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1037
                        if isinstance(dest.attrs[k], list):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1038
                                dest.attrs[k].extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1039
                        else:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1040
                                t = [dest.attrs[k]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1041
                                t.extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1042
                                dest.attrs[k] = t
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1043
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1044
def combine(deps, pkg_vars, pkg_fmri, pkg_name):
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1045
        """Combine duplicate dependency actions.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1046
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1047
        '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
  1048
        the variants associated with that dependency.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1049
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1050
        'pkg_vars' are the variants that the package for which dependencies are
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1051
        being generated was published against.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1052
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1053
        'pkg_fmri' is the name of the package being resolved.  This can be None.
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1054
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1055
        'pkg_name' is either the same as 'pkg_fmri', if 'pkg_fmri' is not None,
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1056
        or it's the basename of the path to the manifest being resolved."""
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1057
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1058
        def action_group_key(d):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1059
                """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
  1060
                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
  1061
                in pkg.manifest notices."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1062
2283
c368082b6a17 16499 pkgdepend resolve -mo includes manifest path in output stream
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2275
diff changeset
  1063
                # 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
  1064
                # 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
  1065
                # 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
  1066
                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
  1067
                    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
  1068
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1069
        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
  1070
                """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
  1071
                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
  1072
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1073
                d_vars.simplify(pkg_vars)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1074
                res = []
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1075
                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
  1076
                        attrs = d.attrs.copy()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1077
                        attrs.update(s)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1078
                        t = actions.depend.DependencyAction(**attrs)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1079
                        t.consolidate_attrs()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1080
                        res.append(t)
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1081
                if not res:
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1082
                        d.consolidate_attrs()
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1083
                        res = [d]
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1084
                return res
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1085
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1086
        res = []
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1087
        req_fmris = []
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1088
        bad_fmris = set()
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1089
        errs = []
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1090
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1091
        # For each group of dependencies (g) for a particular fmri (k) ...
2288
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1092
        for k, group in itertools.groupby(sorted(deps, key=action_group_key),
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1093
            action_group_key):
2288
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1094
                group = list(group)
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1095
                res_dep = group[0][0]
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1096
                res_vars = variants.VariantCombinations(pkg_vars, False)
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1097
                for cur_dep, cur_vars in group:
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1098
                        merge_deps(res_dep, cur_dep)
29c3afa79a1b 18130 pkgdepend doesn't simplify variants where it should
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2283
diff changeset
  1099
                        res_vars.mark_as_satisfied(cur_vars)
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1100
                res.append((res_dep, res_vars))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1101
        new_res = []
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1102
        for cur_dep, cur_vars in res:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1103
                if cur_dep.attrs["type"] not in ("require", "require-any"):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1104
                        new_res.append((cur_dep, cur_vars))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1105
                        continue
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1106
                cur_fmris = []
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1107
                for f in cur_dep.attrlist("fmri"):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1108
                        try:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1109
                                # XXX version requires build string; 5.11 is not
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1110
                                # sane.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1111
                                cur_fmris.append(
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1112
                                    fmri.PkgFmri(f, build_release="5.11"))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1113
                        except fmri.IllegalFmri:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1114
                                bad_fmris.add(f)
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1115
                skip = False
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1116
                # If we're resolving a pkg with a known name ...
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1117
                if pkg_fmri is not None:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1118
                        for pfmri in cur_fmris:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1119
                                # Then if this package is a successor to any of
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1120
                                # the packages the dependency requires, then we
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1121
                                # can omit the dependency.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1122
                                if pkg_fmri.is_successor(pfmri):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1123
                                        skip = True
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1124
                if skip:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1125
                        continue
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1126
                # If this dependency isn't a require-any dependency, then it
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1127
                # should be included in the output.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1128
                if cur_dep.attrs["type"] != "require-any":
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1129
                        new_res.append((cur_dep, cur_vars))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1130
                        continue
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1131
                marked = False
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1132
                # Now the require-any dependency is going to be compared to all
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1133
                # the known require dependencies to see if it can be omitted.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1134
                # It can be omitted if one of the packages it requires is
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1135
                # already required.  Because a require-any dependency could be
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1136
                # omitted under some, but not all, variant combinations, the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1137
                # satisfied set of the variant combination of the require-any
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1138
                # dependency is used for bookkeeping.  Each require dependency
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1139
                # which has a successor to one of the packages in the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1140
                # require-any dependency marks the variant combinations under
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1141
                # which it's valid as unsatisfied in the require-any dependency.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1142
                # At the end, if the require-any dependency is still satisfied
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1143
                # under any variant combinations, then it's included in the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1144
                # result.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1145
                for comp_dep, comp_vars in res:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1146
                        if comp_dep.attrs["type"] != "require":
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1147
                                continue
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1148
                        comp_fmri = fmri.PkgFmri(comp_dep.attrs["fmri"],
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1149
                            build_release="5.11")
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1150
                        successor = False
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1151
                        # Check to see whether the package required by the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1152
                        # require dependency is a successor to any of the
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1153
                        # packages required by the require-any dependency.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1154
                        for c in cur_fmris:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1155
                                if c.is_successor(comp_fmri):
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1156
                                        successor = True
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1157
                                        break
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1158
                        if not successor:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1159
                                continue
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1160
                        # If comp_vars is empty, then no variants have been
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1161
                        # declared for these packages, so having a matching
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1162
                        # require dependency is enough to omit this require-any
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1163
                        # dependency.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1164
                        if cur_vars.mark_as_unsatisfied(comp_vars) or \
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1165
                            comp_vars.is_empty():
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1166
                                marked = True
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1167
                # If the require-any dependency was never changed, then include
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1168
                # it.  If it was changed, check whether there are situations
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1169
                # where the require-any dependency is needed.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1170
                if not marked or cur_vars.sat_set:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1171
                        new_res.append((cur_dep, cur_vars))
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1172
        res = []
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1173
        # Merge the variant information into the depend action.
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1174
        for d, vc in new_res:
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1175
                res.extend(add_vars(d, vc, pkg_vars))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1176
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1177
        if bad_fmris:
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1178
                errs.append(BadDependencyFmri(pkg_name, bad_fmris))
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1179
        return res, errs
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1180
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1181
def split_off_variants(dep, pkg_vars, satisfied=False):
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1182
        """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
  1183
        tags into a VariantSet."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1184
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1185
        dep_vars = dep.get_variant_template()
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1186
        dep_vars.merge_unknown(pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1187
        # 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
  1188
        # 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
  1189
        # 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
  1190
        dep.strip_variants()
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1191
        return dep, variants.VariantCombinations(dep_vars, satisfied=satisfied)
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1192
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1193
def prune_debug_attrs(action):
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1194
        """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
  1195
        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
  1196
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1197
        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
  1198
                     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
  1199
        return actions.depend.DependencyAction(**attrs)
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1200
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1201
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
  1202
    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
  1203
        """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
  1204
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1205
        '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
  1206
        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
  1207
        present.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1208
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1209
        '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
  1210
        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
  1211
        present.
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1212
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1213
        '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
  1214
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1215
        '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
  1216
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1217
        '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
  1218
        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
  1219
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1220
        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
  1221
        if distro_vars:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1222
                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
  1223
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1224
        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
  1225
                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
  1226
                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
  1227
                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
  1228
                    satisfied=True)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1229
                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
  1230
                    (pfmri, vc))
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1231
        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
  1232
             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
  1233
                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
  1234
                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
  1235
                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
  1236
                    satisfied=True)
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1237
                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
  1238
                    (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
  1239
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
  1240
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
  1241
        """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
  1242
        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
  1243
        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
  1244
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
        '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
  1246
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1247
        '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
  1248
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1249
        '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
  1250
        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
  1251
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1252
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1253
        # 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
  1254
        # 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
  1255
        # 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
  1256
        # 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
  1257
        # 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
  1258
        # 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
  1259
        manifests = [
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1260
            (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
  1261
            missing_files)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1262
            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
  1263
            ((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
  1264
            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
  1265
        ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1266
2159
be07d9cad5a7 16013 ON build noise from pkgdepend about perl's complicated symlinks
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2091
diff changeset
  1267
        files = Entries({}, {})
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1268
        links = {}
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1269
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1270
        # 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
  1271
        # 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
  1272
        # purposes of dependency resolution.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1273
        distro_vars = variants.VariantCombinationTemplate()
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1274
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1275
        resolving_pkgs = set()
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1276
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1277
        for mp, (name, pfmri), 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
  1278
                distro_vars.merge_values(pkg_vars)
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1279
                if pfmri:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1280
                        resolving_pkgs.add(pfmri.pkg_name)
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1281
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1282
        pkg_list = None
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1283
        if use_system:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1284
                # 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
  1285
                # 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
  1286
                # generator.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1287
                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
  1288
                    api.ImageInterface.LIST_INSTALLED))
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1289
                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
  1290
                        pfmri = fmri.PkgFmri("pkg:/%s@%s" % (stem, ver))
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1291
                        if pfmri.pkg_name in resolving_pkgs:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1292
                                continue
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1293
                        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
  1294
                        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
  1295
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
  1296
        # Build a list of all files delivered in the manifests being resolved.
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1297
        for mp, (name, pfmri), mfst, pkg_vars, miss_files in manifests:
2428
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1298
                try:
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1299
                        if pfmri is None:
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1300
                                pfmri = fmri.PkgFmri(name, "5.11")
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1301
                except fmri.IllegalFmri, e:
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1302
                        raise BadPackageFmri(mp, e)
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1303
                add_fmri_path_mapping(files.delivered, links, pfmri, mfst,
25adeb0b7928 16849 pkgdepend doesn't handle invalid or incomplete package FMRIs gracefully
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2411
diff changeset
  1304
                    distro_vars)
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
  1305
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
  1306
        # 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
  1307
        # 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
  1308
        if use_system:
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1309
                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
  1310
                        pfmri = fmri.PkgFmri("pkg:/%s@%s" % (stem, ver))
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1311
                        if pfmri.pkg_name in resolving_pkgs:
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1312
                                continue
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
  1313
                        mfst = api_inst.get_manifest(pfmri, all_variants=True)
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1314
                        add_fmri_path_mapping(files.installed, links,
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1315
                            pfmri, mfst, distro_vars)
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1316
        if pkg_list:
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1317
                del pkg_list
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
  1318
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
  1319
        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
  1320
        errs = []
2298
c15c3c1a5590 18172 p.d.d.file is misleading when links are involved
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2288
diff changeset
  1321
        for mp, (name, pfmri), mfst, pkg_vars, miss_files in manifests:
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1322
                name_to_use = pfmri or name
2275
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1323
                # 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
  1324
                # 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
  1325
                # 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
  1326
                # into that universe too.
eed34df93728 18045 pkgdepend resolve fails to recognize unvarianted dependencies
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2236
diff changeset
  1327
                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
  1328
                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
  1329
                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
  1330
                        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
  1331
                        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
  1332
                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
  1333
                    (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
  1334
                        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
  1335
                    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
  1336
                    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
  1337
                ]
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1338
                # 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
  1339
                # manually.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1340
                deps = [
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1341
                    split_off_variants(d, pkg_vars, satisfied=True)
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1342
                    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
  1343
                    if not is_file_dependency(d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1344
                ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1345
                for file_dep, (res, dep_vars, pkg_errs) in pkg_res:
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1346
                        for e in pkg_errs:
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1347
                                if hasattr(e, "pkg_name"):
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1348
                                        e.pkg_name = name_to_use
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1349
                        errs.extend(pkg_errs)
2091
824491c11ff3 15958 generate gets partially satisfied internal dependencies wrong
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2073
diff changeset
  1350
                        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
  1351
                        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
  1352
                                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
  1353
                                    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
  1354
                        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
  1355
                                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
  1356
                                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
  1357
                                        errs.append(UnresolvedDependencyError(
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
  1358
                                            mp, file_dep, dep_vars))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
  1359
                # 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
  1360
                # what would otherwise be duplicate dependencies.
2411
936617650fa1 18150 MultiplePackagesPathError should include package
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2381
diff changeset
  1361
                deps, combine_errs = combine(deps, pkg_vars, pfmri, name_to_use)
2381
45a20c3a277a 11307 pkgdep can traceback for unprivileged user
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2298
diff changeset
  1362
                errs.extend(combine_errs)
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1363
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1364
                if prune_attrs:
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1365
                        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
  1366
                pkg_deps[mp] = deps
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
  1367
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
  1368
        return pkg_deps, errs