src/modules/publish/dependencies.py
author Tim Foster <tim.s.foster@oracle.com>
Tue, 08 Jun 2010 12:17:06 +1200
changeset 1933 5193ac03ad9f
parent 1908 4bdaf0463bae
child 1934 4afdb552a5ec
permissions -rw-r--r--
15305 need to generate dependency information from SMF manifests 15306 need an attribute to declare the SMF services a package delivers 15722 pkgdepend doesn't always remove internal deps when variants taken into account
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
#
1887
757d613561da 15777 pkgdep resolve should provide an option to only resolve against the manifests provided (fix copyright)
Brock Pytlik <bpytlik@sun.com>
parents: 1886
diff changeset
    24
# Copyright (c) 2009, 2010, 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
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    27
import itertools
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    28
import os
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
    29
import urllib
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    30
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    31
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
    32
import pkg.client.api as api
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    33
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
    34
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
    35
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
    36
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
    37
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
    38
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
    39
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
    40
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
    41
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
    42
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    43
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
    44
files_prefix = "%s.file" % base.Dependency.DEPEND_DEBUG_PREFIX
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    45
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    46
class DependencyError(Exception):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    47
        """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
    48
        pass
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    49
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    50
class MultiplePackagesPathError(DependencyError):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    51
        """This exception is used when a file dependency has paths which
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    52
        cause two packages to deliver files which fulfill the dependency."""
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    53
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    54
        def __init__(self, res, source):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    55
                self.res = res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    56
                self.source = source
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    57
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    58
        def __str__(self):
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    59
                return _("The file dependency %s has paths which resolve "
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    60
                    "to multiple packages. The actions are as follows:\n%s" %
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    61
                    (self.source, "\n".join(["\t%s" % a for a in self.res])))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    62
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    63
class AmbiguousPathError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    64
        """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
    65
        is depended upon."""
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    66
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    67
        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
    68
                self.pkgs = pkgs
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    69
                self.source = source
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    70
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    71
        def __str__(self):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    72
                return _("The file dependency %s depends on a path delivered "
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    73
                    "by multiple packages. Those packages are:%s" %
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    74
                    (self.source, " ".join([str(p) for p in self.pkgs])))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    75
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    76
class UnresolvedDependencyError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    77
        """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
    78
        depended upon."""
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
    79
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    80
        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
    81
                self.path = pth
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    82
                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
    83
                self.pvars = pvars
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    84
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    85
        def __str__(self):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    86
                return _("%s has unresolved dependency '%s' under the "
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    87
                    "following combinations of variants:\n%s") % \
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    88
                    (self.path, self.file_dep,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    89
                    "\n".join([
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    90
                        " ".join([("%s:%s" % (name, val)) for name, val in grp])
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    91
                        for grp in self.pvars.get_unsatisfied()
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    92
                    ]))
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
    93
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
    94
def list_implicit_deps(file_path, proto_dirs, dyn_tok_conv, kernel_paths,
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    95
    remove_internal_deps=True):
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    96
        """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
    97
        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
    98
        the manifest have.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    99
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   100
        '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
   101
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   102
        '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
   103
        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
   104
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   105
        '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
   106
        $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
   107
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   108
        'kernel_paths' contains the run paths which kernel modules should use.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   109
        """
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   110
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   111
        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
   112
        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
   113
        deps, elist, missing, pkg_attrs = list_implicit_deps_for_manifest(m,
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   114
            proto_dirs, pkg_vars, dyn_tok_conv, kernel_paths)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   115
        if remove_internal_deps:
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   116
                deps = resolve_internal_deps(deps, m, proto_dirs, pkg_vars)
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   117
        return deps, missing_manf_files + elist, missing, pkg_attrs
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   118
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   119
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
   120
        """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
   121
        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
   122
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   123
        '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
   124
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   125
        '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
   126
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   127
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   128
        '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
   129
        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
   130
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
   131
        '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
   132
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   133
        res = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   134
        delivered = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   135
        delivered_bn = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   136
        for a in mfst.gen_actions_by_type("file"):
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
   137
                pvars = variants.VariantSets(a.get_variants())
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
   138
                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
   139
                        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
   140
                else:
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   141
                        pvars.merge_unknown(pkg_vars)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   142
                p = a.attrs["path"]
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
   143
                delivered.setdefault(p, variants.VariantSets()).merge(pvars)
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   144
                p = os.path.join(a.attrs[portable.PD_PROTO_DIR], p)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   145
                np = os.path.normpath(p)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   146
                rp = os.path.realpath(p)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   147
                # adding the normalized path
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
   148
                delivered.setdefault(np, variants.VariantSets()).merge(pvars)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   149
                # adding the real path
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
   150
                delivered.setdefault(rp, variants.VariantSets()).merge(pvars)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   151
                bn = os.path.basename(p)
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
   152
                delivered_bn.setdefault(bn, variants.VariantSets()).merge(pvars)
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   153
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   154
        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
   155
                etype, pvars = d.resolve_internal(delivered_files=delivered,
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   156
                    delivered_base_names=delivered_bn)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   157
                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
   158
                        continue
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
   159
                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
   160
                res.append(d)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   161
        return res
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   162
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   163
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
   164
        """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
   165
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   166
        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
   167
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   168
# 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
   169
# 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
   170
dispatch_dict = {
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   171
    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
   172
    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
   173
    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
   174
    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
   175
}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   176
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   177
def list_implicit_deps_for_manifest(mfst, proto_dirs, pkg_vars, dyn_tok_conv,
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   178
    kernel_paths):
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   179
        """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
   180
        files it installs.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   181
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   182
        '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
   183
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   184
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   185
        '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
   186
        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
   187
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   188
        '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
   189
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   190
        '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
   191
        $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
   192
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   193
        'kernel_paths' contains the run paths which kernel modules should use.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   194
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   195
        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
   196
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   197
        '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
   198
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   199
        '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
   200
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   201
        '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
   202
        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
   203
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   204
        '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
   205
        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
   206
        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
   207
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   208
        deps = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   209
        elist = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   210
        missing = {}
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   211
        pkg_attrs = {}
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   212
        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
   213
        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
   214
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   215
        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
   216
                a = act_list[i]
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   217
                try:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   218
                        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
   219
                except KeyError:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   220
                        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
   221
                                missing[file_type] = \
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   222
                                    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
   223
                else:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   224
                        try:
1933
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   225
                                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
   226
                                    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
   227
                                    dyn_tok_conv=dyn_tok_conv,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   228
                                    kernel_paths=kernel_paths)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   229
                                deps.extend(ds)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   230
                                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
   231
                                __update_pkg_attrs(pkg_attrs, attrs)
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   232
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   233
                        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
   234
                                elist.append(e)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   235
        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
   236
                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
   237
        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
   238
5193ac03ad9f 15305 need to generate dependency information from SMF manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 1908
diff changeset
   239
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
   240
        """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
   241
        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
   242
                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
   243
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   244
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
   245
        """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
   246
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
   247
        m = manifest.Manifest()
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   248
        fh = open(fp, "rb")
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   249
        acts = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   250
        missing_files = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   251
        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   252
        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
   253
                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
   254
                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
   255
                        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
   256
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   257
                elif accumulate:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   258
                        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
   259
                        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   260
                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
   261
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   262
                try:
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1887
diff changeset
   263
                        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
   264
                            basedirs=basedirs,
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   265
                            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
   266
                        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
   267
                                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
   268
                                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
   269
                                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
   270
                                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
   271
                        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
   272
                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
   273
                        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
   274
                            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
   275
                        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
   276
                                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
   277
                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   278
                                path = e.path
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   279
                                # If the path was not set, then parse the
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   280
                                # action, without trying to load the data and
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   281
                                # use the path defined in the action.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   282
                                if not path:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   283
                                        path = new_a.attrs["path"]
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   284
                                missing_files.append(base.MissingFile(path))
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   285
        fh.close()
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   286
        m.set_content(acts)
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   287
        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
   288
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
   289
def choose_name(fp, mfst):
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   290
        """Find the package name for this manifest. If it's defined in a set
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   291
        action in the manifest, use that. Otherwise use the basename of the
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   292
        path to the manifest as the name.
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   293
        '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
   294
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
   295
        '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
   296
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
   297
        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
   298
                return urllib.unquote(os.path.basename(fp))
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1337
diff changeset
   299
        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
   300
        if name is not None:
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   301
                return name
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   302
        return urllib.unquote(os.path.basename(fp))
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   303
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   304
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
   305
        """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
   306
        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
   307
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
   308
        '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
   309
        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
   310
        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
   311
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
   312
        '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
   313
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
   314
        '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
   315
        satisfied.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   316
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   317
        '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
   318
        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
   319
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
   320
        res = []
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   321
        vars = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   322
        errs = set()
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   323
        for pfmri, delivered_vars in lst:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   324
                # 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
   325
                # where the dependency is, skip it.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   326
                if not orig_dep_vars.intersects(delivered_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
   327
                        continue
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   328
                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
   329
                        # 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
   330
                        # 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
   331
                        # 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
   332
                        # 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
   333
                        if found_fmri != pfmri and \
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   334
                            (delivered_vars.intersects(found_vars) or
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   335
                            found_vars.intersects(delivered_vars)):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   336
                                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
   337
                                errs.add(pfmri)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   338
                # Find the variants under which pfmri is relevant.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   339
                action_vars = orig_dep_vars.intersection(delivered_vars)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   340
                # 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
   341
                # 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
   342
                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
   343
                attrs = file_dep.attrs.copy()
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
   344
                attrs.update({"fmri":str(pfmri)})
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   345
                # 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
   346
                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
   347
                    action_vars))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   348
                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
   349
        if errs:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   350
                # If any packages are in errs, then more than one file delivered
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   351
                # the same path under some configuaration of variants. This
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   352
                # situation is unresolvable.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   353
                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
   354
        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
   355
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   356
def make_paths(file_dep):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   357
        """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
   358
        'file_dep'."""
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   359
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   360
        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
   361
        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
   362
        if isinstance(files, basestring):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   363
                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
   364
        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
   365
                rps = [rps]
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   366
        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
   367
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   368
def find_package_using_delivered_files(delivered, 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
   369
    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
   370
        """Uses a dictionary mapping file paths to packages to determine which
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
   371
        package delivers the dependency under which variants.
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
   372
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
   373
        'delivered' is a dictionary mapping paths to a list of fmri, variants
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
   374
        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
   375
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
   376
        '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
   377
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
   378
        '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
   379
        resolved.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   380
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   381
        '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
   382
        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
   383
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   384
        res = None
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   385
        errs = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   386
        multiple_path_errs = {}
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   387
        for p in make_paths(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
   388
                delivered_list = []
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
   389
                if p in delivered:
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
   390
                        delivered_list = delivered[p]
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
   391
                # XXX Eventually, this needs to be changed to use the
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   392
                # link information provided by the manifests being
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
   393
                # resolved against, including the packages currently being
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
   394
                # published.
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   395
                try:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   396
                        new_res, dep_vars = helper(delivered_list, file_dep,
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   397
                            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
   398
                except AmbiguousPathError, e:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   399
                        errs.append(e)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   400
                else:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   401
                        # We know which path satisfies this dependency, so
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   402
                        # remove the list of files and paths, and replace them
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   403
                        # with the single path that works.
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   404
                        for na, nv in new_res:
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   405
                                na.attrs.pop(paths_prefix, None)
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   406
                                na.attrs[files_prefix] = [p]
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   407
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   408
                        if not res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   409
                                res = new_res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   410
                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   411
                        # 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
   412
                        # 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
   413
                        # 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
   414
                        # 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
   415
                        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
   416
                                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
   417
                                        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
   418
                                            new_a.attrs["fmri"]:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   419
                                                a.attrs[files_prefix].extend(
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   420
                                                    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
   421
                                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   422
                                        # 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
   423
                                        # 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
   424
                                        # 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
   425
                                        # satisfies the dependencies.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   426
                                        if v.intersects(new_v) or \
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   427
                                            new_v.intersects(v):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   428
                                                multiple_path_errs.setdefault(a,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   429
                                                    set([a]))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   430
                                                multiple_path_errs[a].add(new_a)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   431
                                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   432
                                                res.append((new_a, new_v))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   433
        for a in multiple_path_errs:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   434
                errs.append(MultiplePackagesPathError(multiple_path_errs[a],
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   435
                    file_dep))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   436
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   437
        # 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
   438
        # multiple path errors.
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   439
        return [(a, v) for a, v in res if a not in multiple_path_errs], \
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   440
            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
   441
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
   442
def find_package(delivered, installed, 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
   443
        """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
   444
        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
   445
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
   446
        'delivered' is a dictionary mapping paths to a list of fmri, variants
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
   447
        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
   448
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
   449
        '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
   450
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   451
        '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
   452
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   453
        file_dep, orig_dep_vars = split_off_variants(file_dep, pkg_vars)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   454
        dep_vars = orig_dep_vars.copy()
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   455
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   456
        # First try to resolve the dependency against the delivered files.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   457
        res, dep_vars, errs = find_package_using_delivered_files(delivered,
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   458
                file_dep, dep_vars, orig_dep_vars)
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
   459
        if (res 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
   460
                return res, dep_vars, errs
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   461
        # 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
   462
        # files installed in the current image.
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   463
        inst_res, dep_vars, inst_errs = find_package_using_delivered_files(
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   464
            installed, file_dep, dep_vars, orig_dep_vars)
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   465
        res.extend(inst_res)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   466
        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
   467
        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
   468
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
   469
def is_file_dependency(act):
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
   470
        return act.name == "depend" and \
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
   471
            act.attrs.get("fmri", None) == base.Dependency.DUMMY_FMRI and \
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
   472
            "%s.file" % base.Dependency.DEPEND_DEBUG_PREFIX in act.attrs
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
   473
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   474
def merge_deps(dest, src):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   475
        """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
   476
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   477
        for k, v in src.attrs.items():
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   478
                # 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
   479
                # then something's gone horribly wrong.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   480
                assert(not k.startswith("variant."))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   481
                if k not in dest.attrs:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   482
                        dest.attrs[k] = v
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   483
                elif v != dest.attrs[k]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   484
                        # 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
   485
                        # will be removed in a later step.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   486
                        if isinstance(v, basestring):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   487
                                v = [v]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   488
                        if isinstance(dest.attrs[k], list):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   489
                                dest.attrs[k].extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   490
                        else:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   491
                                t = [dest.attrs[k]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   492
                                t.extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   493
                                dest.attrs[k] = t
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   494
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   495
def combine(deps, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   496
        """Combine duplicate dependency actions.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   497
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   498
        '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
   499
        the variants associated with that dependency.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   500
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   501
        'pkg_vars' are the variants that the package for which dependencies are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   502
        being generated was published against."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   503
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   504
        def action_group_key(d):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   505
                """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
   506
                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
   507
                in pkg.manifest notices."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   508
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   509
                # d[0] is the action.  d[1] is the VariantSet for this action.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   510
                return d[0].name, d[0].attrs.get(d[0].key_attr, id(d[0]))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   511
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   512
        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
   513
                """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
   514
                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
   515
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   516
                d_vars.remove_identical(pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   517
                d.attrs.update(d_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   518
                # Remove any duplicate values for any attributes.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   519
                d.consolidate_attrs()
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   520
                return d
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   521
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   522
        def key_on_variants(a):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   523
                """Return the key (the VariantSets) to sort the grouped tuples
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   524
                by."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   525
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   526
                return a[1]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   527
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   528
        def sort_by_variant_subsets(a, b):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   529
                """Sort the tuples so that those actions whose variants are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   530
                supersets of others are placed at the front of the list.  This
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   531
                function assumes that a and b are both VariantSets."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   532
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   533
                if a.issubset(b):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   534
                        return 1
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   535
                elif b.issubset(a):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   536
                        return -1
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   537
                return 0
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   538
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   539
        # Here is an example of how this code should work.  Assume that the code
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   540
        # is looking at dependencies for a package published against
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   541
        # variant.foo = bar, baz and variant.num = one, two.  These are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   542
        # abbreviated below as v.f and v.n.  The following dependencies have
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   543
        # been found for this package:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   544
        # 1) depend pkg_a reason=file_1, VariantSet is v.f=bar,baz v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   545
        # 2) depend pkg_a reason=file_2, VariantSet is v.f=bar v.n=one
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   546
        # 3) depend pkg_b reason=file_3, VariantSet is v.f=bar v.n=one
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   547
        # 4) depend pkg_b reason=file_3, VariantSet is v.f=baz v.n=two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   548
        # 5) depend pkg_b reason=file_3 path=p1, VariantSet is v.f=bar
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   549
        #        v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   550
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   551
        # First, these dependencies are grouped by their fmris.  This produces
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   552
        # two lists, the first contains dependencies 1 and 2, the second
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   553
        # contains dependencies 3, 4, and 5.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   554
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   555
        # The first group of dependencies is sorted by their VariantSet's.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   556
        # Dependency 1 comes before dependency 2 because 2's variants are a
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   557
        # subset of 1's variants.  Dependency 1 is put in the temporary result
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   558
        # list (subres) since at least one dependency on pkg_a must exist.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   559
        # Next, dependency 2 is compared to dependency 1 to see if it its
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   560
        # variants are subset of 1's. Since they are, the two dependencies are
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   561
        # merged.  This means that values of all tags in either dependency
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   562
        # appear in the merged dependency.  In this case, the merged dependency
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   563
        # would look something like:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   564
        # depend pkg_a reason=file_1 reason=file_2
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   565
        # The variant set associated with the merged dependency would still be
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   566
        # dependency 1's variant set.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   567
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   568
        # The last thing that happens with this group of dependencies is that
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   569
        # add_vars is called on each result.  This first removes those variants
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   570
        # which match the package's identically.  What remains is added to the
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   571
        # dependency's attribute dictionary.  Since the package variants and the
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   572
        # dependency's variants are identical in this case, nothing is added.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   573
        # Lastly, any duplicate values for a tag are removed.  Again, since
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   574
        # there are no duplicates, nothing is changed.  The final dependency
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   575
        # that's added to final_res is:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   576
        # depend pkg_a reason=file_1 reason=file_2
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   577
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   578
        # The second group of dependencies is also sorted by their VariantSet's.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   579
        # This sort is a partial ordering.  Dependency 5 must come before
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   580
        # dependency 3, but dependency 4 can be anywhere in the list.  Let's
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   581
        # assume that the order is [4, 5, 3].
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   582
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   583
        # Dependency 4 is added to the temporary result list (subres).
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   584
        # Dependency 5 is checked to see if its variants are subset of 4's
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   585
        # variants.  Since they are not, dependency 5 is added to subres.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   586
        # Dependency 3 is checked against 4 to see if its variants are a subset.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   587
        # Since they're not, 3's variants are then checked against 5's variants.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   588
        # Since 3's variants are a subset of 5's variants, 3 is merged with 5,
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   589
        # producing this dependency:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   590
        # depend pkg_b reason=file_3 reason=file_3 path=p1, VariantSet is
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   591
        # v.f=bar v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   592
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   593
        # The two results from this group (dependency 4 and the merge of 5 and
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   594
        # 3) than has add_vars called on it.  The final results are:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   595
        # dependency pkg_b reason=file_3 v.f=baz v.n=two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   596
        # dependency pkg_b reason=file_3 path=p1 v.f=bar
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   597
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   598
        # The v.n tags have been removed from the second result because they
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   599
        # were identical to the package's variants.  The duplicate reasons have
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   600
        # also been coalesced.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   601
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   602
        # After everything is done, the final set of dependencies for this
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   603
        # package are:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   604
        # depend pkg_a reason=file_1 reason=file_2
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   605
        # dependency pkg_b reason=file_3 v.f=baz v.n=two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   606
        # dependency pkg_b reason=file_3 path=p1 v.f=bar
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   607
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   608
        res = []
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   609
        # For each group of dependencies (g) for a particular fmri (k) ...
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   610
        for k, g in itertools.groupby(sorted(deps, key=action_group_key),
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   611
            action_group_key):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   612
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   613
                # Sort the dependencies so that any dependency whose variants
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   614
                # are a subset of the variants of another dependency follow it.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   615
                glist = sorted(g, cmp=sort_by_variant_subsets,
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   616
                    key=key_on_variants)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   617
                subres = [glist[0]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   618
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   619
                # d is a dependency action. d_vars are the variants under which
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   620
                # d will be applied.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   621
                for d, d_vars in glist[1:]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   622
                        found_subset = False
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   623
                        for rel_res, rel_vars in subres:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   624
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   625
                                # If d_vars is a subset of any variant set
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   626
                                # already in the results, then d should be
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   627
                                # combined with that dependency.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   628
                                if d_vars.issubset(rel_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   629
                                        found_subset = True
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   630
                                        merge_deps(rel_res, d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   631
                                        break
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   632
                                assert(not rel_vars.issubset(d_vars))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   633
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   634
                        # If no subset was found, then d_vars is a new set of
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   635
                        # conditions under which the dependency d should apply
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   636
                        # so add it to the results.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   637
                        if not found_subset:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   638
                                subres.append((d, d_vars))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   639
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   640
                # Add the variants to the dependency action and remove any
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   641
                # variants that are identical to those defined by the package.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   642
                subres = [add_vars(d, d_vars, pkg_vars) for d, d_vars in subres]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   643
                res.extend(subres)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   644
        return res
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   645
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   646
def split_off_variants(dep, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   647
        """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
   648
        tags into a VariantSet."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   649
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   650
        dep_vars = variants.VariantSets(dep.get_variants())
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   651
        dep_vars.merge_unknown(pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   652
        # 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
   653
        # 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
   654
        # 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
   655
        dep.strip_variants()
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   656
        return dep, dep_vars
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   657
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   658
def prune_debug_attrs(action):
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   659
        """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
   660
        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
   661
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   662
        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
   663
                     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
   664
        return actions.depend.DependencyAction(**attrs)
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   665
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
   666
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
   667
        """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
   668
        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
   669
        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
   670
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
   671
        '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
   672
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   673
        '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
   674
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   675
        '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
   676
        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
   677
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   678
        def add_fmri_path_mapping(pathdict, pfmri, mfst):
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   679
                """Add mappings from path names to FMRIs and variants.
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   680
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   681
                'pathdict' is a dict path -> (fmri, variants) to which
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   682
                entries are added.
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   683
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   684
                'pfmri' is the FMRI of the current manifest
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   685
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   686
                'mfst' is the manifest to process."""
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   687
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   688
                pvariants = mfst.get_all_variants()
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   689
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   690
                for f in itertools.chain(mfst.gen_actions_by_type("file"),
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   691
                     mfst.gen_actions_by_type("hardlink"),
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   692
                     mfst.gen_actions_by_type("link")):
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   693
                        dep_vars = variants.VariantSets(f.get_variants())
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   694
                        dep_vars.merge_unknown(pvariants)
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   695
                        pathdict.setdefault(f.attrs["path"], []).append(
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   696
                            (pfmri, dep_vars))
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   697
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   698
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   699
        # 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
   700
        # 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
   701
        # 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
   702
        # 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
   703
        # 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
   704
        # 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
   705
        manifests = [
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   706
            (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
   707
            missing_files)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   708
            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
   709
            ((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
   710
            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
   711
        ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   712
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
   713
        delivered_files = {}
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   714
        installed_files = {}
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   715
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
   716
        # Build a list of all files delivered in the manifests being resolved.
1856
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   717
        for mp, name, mfst, pkg_vars, miss_files in manifests:
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   718
                pfmri = fmri.PkgFmri(name).get_short_fmri()
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   719
                add_fmri_path_mapping(delivered_files, pfmri, mfst)
68eb900fbed5 14869 pkgdepend shouldn't include the timestamp in resolved dependencies
Richard Lowe <richlowe@richlowe.net>
parents: 1845
diff changeset
   720
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   721
        # 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
   722
        # 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
   723
        if use_system:
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
   724
                for (pub, stem, ver), summ, cats, states in \
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
   725
                    api_inst.get_pkg_list(api.ImageInterface.LIST_INSTALLED):
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
   726
                        pfmri = fmri.PkgFmri("pkg:/%s@%s" % (stem, ver))
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
   727
                        mfst = api_inst.get_manifest(pfmri, all_variants=True)
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
   728
                        add_fmri_path_mapping(installed_files,
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1856
diff changeset
   729
                            pfmri.get_short_fmri(), mfst)
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   730
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
   731
        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
   732
        errs = []
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   733
        for mp, name, mfst, pkg_vars, miss_files in manifests:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   734
                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
   735
                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
   736
                        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
   737
                        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
   738
                pkg_res = [
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
   739
                    (d, find_package(delivered_files, installed_files,
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
   740
                        d, 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
   741
                    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
   742
                    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
   743
                ]
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   744
                # 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
   745
                # manually.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   746
                deps = [
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   747
                    split_off_variants(d, pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   748
                    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
   749
                    if not is_file_dependency(d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   750
                ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   751
                for file_dep, (res, dep_vars, pkg_errs) in pkg_res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   752
                        errs.extend(pkg_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
   753
                        if not 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
   754
                                dep_vars.merge_unknown(pkg_vars)
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   755
                                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
   756
                                    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
   757
                        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
   758
                                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
   759
                                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
   760
                                        errs.append(UnresolvedDependencyError(
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   761
                                            mp, file_dep, dep_vars))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   762
                # 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
   763
                # what would otherwise be duplicate dependencies.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   764
                deps = combine(deps, pkg_vars)
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   765
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   766
                if prune_attrs:
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   767
                        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
   768
                pkg_deps[mp] = deps
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   769
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
   770
        return pkg_deps, errs