src/modules/publish/dependencies.py
author Richard Lowe <richlowe@richlowe.net>
Fri, 02 Apr 2010 19:53:57 -0400
changeset 1845 d9a33bd442b5
parent 1756 0dd15313e977
child 1856 68eb900fbed5
permissions -rw-r--r--
14870 pkgdep should strip dependency debugging information
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
#
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
    24
# Copyright 2010 Sun Microsystems, Inc.  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
# Use is subject to license terms.
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
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    28
import itertools
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    29
import os
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
    30
import urllib
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    31
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    32
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
    33
import pkg.client.api as api
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
    34
import pkg.client.api_errors as api_errors
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    35
import pkg.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
    36
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
    37
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
    38
import pkg.flavor.script as script
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    39
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
    40
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
    41
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
    42
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
    43
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    44
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
    45
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
    46
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    47
class DependencyError(Exception):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    48
        """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
    49
        pass
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    50
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    51
class MultiplePackagesPathError(DependencyError):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    52
        """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
    53
        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
    54
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    55
        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
    56
                self.res = res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    57
                self.source = source
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    58
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    59
        def __str__(self):
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
    60
                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
    61
                    "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
    62
                    (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
    63
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    64
class AmbiguousPathError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    65
        """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
    66
        is depended upon."""
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    67
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    68
        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
    69
                self.pkgs = pkgs
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    70
                self.source = source
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    71
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    72
        def __str__(self):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    73
                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
    74
                    "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
    75
                    (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
    76
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    77
class UnresolvedDependencyError(DependencyError):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    78
        """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
    79
        depended upon."""
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
    80
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    81
        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
    82
                self.path = pth
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    83
                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
    84
                self.pvars = pvars
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    85
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    86
        def __str__(self):
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    87
                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
    88
                    "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
    89
                    (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
    90
                    "\n".join([
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    91
                        " ".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
    92
                        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
    93
                    ]))
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
    94
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    95
def list_implicit_deps(file_path, proto_dir, dyn_tok_conv, kernel_paths,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
    96
    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
    97
        """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
    98
        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
    99
        the manifest have.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   100
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   101
        '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
   102
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   103
        'proto_dir' is the path to the proto area which holds 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
   104
        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
   105
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   106
        '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
   107
        $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
   108
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   109
        '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
   110
        """
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   111
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   112
        proto_dir = os.path.abspath(proto_dir)
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   113
        m, missing_manf_files = __make_manifest(file_path, [proto_dir])
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   114
        pkg_vars = m.get_all_variants()
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   115
        deps, elist, missing = list_implicit_deps_for_manifest(m, proto_dir,
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   116
            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
   117
        if remove_internal_deps:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   118
                deps = resolve_internal_deps(deps, m, proto_dir, pkg_vars)
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   119
        return deps, missing_manf_files + elist, missing
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   120
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   121
def resolve_internal_deps(deps, mfst, proto_dir, pkg_vars):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   122
        """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
   123
        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
   124
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   125
        '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
   126
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   127
        '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
   128
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   129
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   130
        '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
   131
        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
   132
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
   133
        '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
   134
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   135
        res = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   136
        delivered = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   137
        delivered_bn = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   138
        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
   139
                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
   140
                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
   141
                        pvars = 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)
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   144
                p = os.path.join(proto_dir, p)
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
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   166
        return [], [base.MissingFile(action.attrs["path"])]
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,
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   173
    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
   174
}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   175
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   176
def list_implicit_deps_for_manifest(mfst, proto_dir, pkg_vars, dyn_tok_conv,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   177
    kernel_paths):
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   178
        """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
   179
        files it installs.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   180
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   181
        '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
   182
        found in deps.
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   183
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   184
        '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
   185
        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
   186
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   187
        '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
   188
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   189
        '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
   190
        $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
   191
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   192
        '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
   193
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   194
        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
   195
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   196
        '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
   197
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   198
        '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
   199
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   200
        'missing' is a dictionary mapping a file type that isn't recognized by
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
   201
        portable.get_file_type to a file which produced that filetype."""
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   202
1231
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   203
        deps = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   204
        elist = []
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   205
        missing = {}
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   206
        act_list = list(mfst.gen_actions_by_type("file"))
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   207
        file_types = portable.get_file_type(act_list, proto_dir)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   208
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   209
        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
   210
                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
   211
                try:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   212
                        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
   213
                except KeyError:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   214
                        if file_type not in missing:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   215
                                missing[file_type] = os.path.join(proto_dir,
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   216
                                    a.attrs["path"])
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   217
                else:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   218
                        try:
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   219
                                ds, errs = func(action=a, proto_dir=proto_dir,
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   220
                                    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
   221
                                    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
   222
                                    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
   223
                                deps.extend(ds)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   224
                                elist.extend(errs)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   225
                        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
   226
                                elist.append(e)
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   227
        for a in mfst.gen_actions_by_type("hardlink"):
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   228
                deps.extend(hardlink.process_hardlink_deps(a, pkg_vars,
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   229
                    proto_dir))
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   230
        return deps, elist, missing
f7b99e8118d2 9290 need a way to find the file dependencies of a package
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   231
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   232
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
   233
        """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
   234
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   235
        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
   236
        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
   237
        acts = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   238
        missing_files = []
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   239
        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   240
        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
   241
                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
   242
                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
   243
                        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
   244
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   245
                elif accumulate:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   246
                        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
   247
                        accumulate = ""
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   248
                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
   249
                        continue
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   250
                try:
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   251
                        a, local_path = actions.internalizestr(l,
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   252
                            basedirs=basedirs,
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   253
                            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
   254
                        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
   255
                                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
   256
                                a.attrs[portable.PD_LOCAL_PATH] = local_path
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   257
                        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
   258
                except actions.ActionDataError, e:
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   259
                        new_a, local_path = actions.internalizestr(
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   260
                            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
   261
                        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
   262
                                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
   263
                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   264
                                path = e.path
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   265
                                # 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
   266
                                # 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
   267
                                # 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
   268
                                if not path:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   269
                                        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
   270
                                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
   271
        fh.close()
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   272
        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
   273
        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
   274
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   275
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
   276
        """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
   277
        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
   278
        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
   279
        '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
   280
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   281
        '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
   282
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   283
        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
   284
                return urllib.unquote(os.path.basename(fp))
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1337
diff changeset
   285
        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
   286
        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
   287
                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
   288
        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
   289
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   290
def helper(lst, file_dep, dep_vars, orig_dep_vars, pkg_vars):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   291
        """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
   292
        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
   293
52e101b7cc31 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
        '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
   295
        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
   296
        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
   297
52e101b7cc31 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
        '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
   299
52e101b7cc31 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
        '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
   301
        satisfied.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   302
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   303
        'orig_dep_vars' is the original set of variants under which the
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   304
        dependency must be satisfied.
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   305
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   306
        'pkg_vars' is the list of variants against which the package delivering
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   307
        the action 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
   308
52e101b7cc31 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
        res = []
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   310
        vars = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   311
        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
   312
        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
   313
                # 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
   314
                # 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
   315
                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
   316
                        continue
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   317
                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
   318
                        # 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
   319
                        # 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
   320
                        # 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
   321
                        # 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
   322
                        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
   323
                            (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
   324
                            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
   325
                                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
   326
                                errs.add(pfmri)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   327
                # 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
   328
                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
   329
                # 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
   330
                # 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
   331
                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
   332
                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
   333
                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
   334
                # 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
   335
                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
   336
                    action_vars))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   337
                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
   338
        if errs:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   339
                # 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
   340
                # 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
   341
                # situation is unresolvable.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   342
                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
   343
        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
   344
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   345
def make_paths(file_dep):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   346
        """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
   347
        'file_dep'."""
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   348
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   349
        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
   350
        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
   351
        if isinstance(files, basestring):
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   352
                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
   353
        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
   354
                rps = [rps]
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   355
        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
   356
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   357
def find_package_using_delivered_files(delivered, file_dep, dep_vars,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   358
    orig_dep_vars, pkg_vars):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   359
        """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
   360
        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
   361
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   362
        '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
   363
        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
   364
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   365
        '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
   366
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   367
        '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
   368
        resolved.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   369
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   370
        'orig_dep_vars' is the original set of variants under which the
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   371
        dependency must be satisfied.
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   372
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   373
        'pkg_vars' is the list of variants against which the package delivering
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   374
        the action 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
   375
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   376
        res = None
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   377
        variants_with_matches = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   378
        errs = []
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   379
        multiple_path_errs = {}
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   380
        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
   381
                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
   382
                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
   383
                        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
   384
                # 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
   385
                # 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
   386
                # 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
   387
                # published.
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   388
                try:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   389
                        new_res, dep_vars = helper(delivered_list, file_dep,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   390
                            dep_vars, orig_dep_vars, pkg_vars)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   391
                except AmbiguousPathError, e:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   392
                        errs.append(e)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   393
                else:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   394
                        # 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
   395
                        # 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
   396
                        # 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
   397
                        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
   398
                                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
   399
                                na.attrs[files_prefix] = [p]
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   400
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   401
                        if not res:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   402
                                res = new_res
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   403
                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   404
                        # 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
   405
                        # 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
   406
                        # 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
   407
                        # 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
   408
                        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
   409
                                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
   410
                                        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
   411
                                            new_a.attrs["fmri"]:
1580
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   412
                                                a.attrs[files_prefix].extend(
2763f36d0eda 13136 pkgdep test cases shouldn't reference installed image
Brock Pytlik <bpytlik@sun.com>
parents: 1544
diff changeset
   413
                                                    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
   414
                                                continue
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   415
                                        # 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
   416
                                        # 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
   417
                                        # 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
   418
                                        # satisfies the dependencies.
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   419
                                        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
   420
                                            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
   421
                                                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
   422
                                                    set([a]))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   423
                                                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
   424
                                        else:
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   425
                                                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
   426
        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
   427
                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
   428
                    file_dep))
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   429
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   430
        # 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
   431
        # multiple path errors.
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   432
        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
   433
            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
   434
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
   435
def find_package(delivered, installed, file_dep, pkg_vars):
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   436
        """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
   437
        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
   438
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   439
        '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
   440
        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
   441
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   442
        '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
   443
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   444
        '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
   445
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   446
        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
   447
        dep_vars = orig_dep_vars.copy()
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   448
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   449
        # 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
   450
        res, dep_vars, errs = find_package_using_delivered_files(delivered,
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   451
                file_dep, dep_vars, orig_dep_vars, pkg_vars)
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   452
        if res and 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
   453
                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
   454
        # 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
   455
        # files installed in the current image.
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   456
        inst_res, dep_vars, inst_errs = find_package_using_delivered_files(
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   457
            installed, file_dep, dep_vars, orig_dep_vars, pkg_vars)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   458
        res.extend(inst_res)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   459
        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
   460
        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
   461
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   462
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
   463
        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
   464
            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
   465
            "%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
   466
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   467
def merge_deps(dest, src):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   468
        """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
   469
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   470
        for k, v in src.attrs.items():
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   471
                # 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
   472
                # then something's gone horribly wrong.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   473
                assert(not k.startswith("variant."))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   474
                if k not in dest.attrs:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   475
                        dest.attrs[k] = v
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   476
                elif v != dest.attrs[k]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   477
                        # 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
   478
                        # will be removed in a later step.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   479
                        if isinstance(v, basestring):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   480
                                v = [v]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   481
                        if isinstance(dest.attrs[k], list):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   482
                                dest.attrs[k].extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   483
                        else:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   484
                                t = [dest.attrs[k]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   485
                                t.extend(v)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   486
                                dest.attrs[k] = t
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   487
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   488
def combine(deps, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   489
        """Combine duplicate dependency actions.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   490
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   491
        '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
   492
        the variants associated with that dependency.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   493
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   494
        '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
   495
        being generated was published against."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   496
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   497
        def action_group_key(d):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   498
                """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
   499
                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
   500
                in pkg.manifest notices."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   501
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   502
                # 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
   503
                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
   504
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   505
        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
   506
                """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
   507
                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
   508
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   509
                d_vars.remove_identical(pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   510
                d.attrs.update(d_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   511
                # Remove any duplicate values for any attributes.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   512
                d.consolidate_attrs()
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   513
                return d
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   514
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   515
        def key_on_variants(a):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   516
                """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
   517
                by."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   518
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   519
                return a[1]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   520
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   521
        def sort_by_variant_subsets(a, b):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   522
                """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
   523
                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
   524
                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
   525
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   526
                if a.issubset(b):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   527
                        return 1
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   528
                elif b.issubset(a):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   529
                        return -1
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   530
                return 0
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   531
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   532
        # 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
   533
        # 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
   534
        # 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
   535
        # 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
   536
        # been found for this package:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   537
        # 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
   538
        # 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
   539
        # 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
   540
        # 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
   541
        # 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
   542
        #        v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   543
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   544
        # 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
   545
        # 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
   546
        # contains dependencies 3, 4, and 5.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   547
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   548
        # 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
   549
        # 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
   550
        # 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
   551
        # 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
   552
        # 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
   553
        # 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
   554
        # 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
   555
        # 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
   556
        # would look something like:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   557
        # 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
   558
        # 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
   559
        # dependency 1's variant set.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   560
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   561
        # 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
   562
        # 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
   563
        # 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
   564
        # 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
   565
        # 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
   566
        # 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
   567
        # 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
   568
        # that's added to final_res is:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   569
        # 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
   570
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   571
        # 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
   572
        # 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
   573
        # 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
   574
        # 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
   575
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   576
        # 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
   577
        # 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
   578
        # 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
   579
        # 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
   580
        # 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
   581
        # 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
   582
        # producing this dependency:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   583
        # 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
   584
        # v.f=bar v.n=one,two
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   585
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   586
        # 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
   587
        # 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
   588
        # 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
   589
        # 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
   590
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   591
        # 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
   592
        # 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
   593
        # also been coalesced.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   594
        #
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   595
        # 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
   596
        # package are:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   597
        # 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
   598
        # 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
   599
        # 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
   600
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   601
        res = []
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   602
        # 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
   603
        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
   604
            action_group_key):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   605
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   606
                # 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
   607
                # 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
   608
                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
   609
                    key=key_on_variants)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   610
                subres = [glist[0]]
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   611
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   612
                # 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
   613
                # d will be applied.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   614
                for d, d_vars in glist[1:]:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   615
                        found_subset = False
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   616
                        for rel_res, rel_vars in subres:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   617
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   618
                                # 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
   619
                                # 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
   620
                                # combined with that dependency.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   621
                                if d_vars.issubset(rel_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   622
                                        found_subset = True
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   623
                                        merge_deps(rel_res, d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   624
                                        break
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   625
                                assert(not rel_vars.issubset(d_vars))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   626
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   627
                        # 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
   628
                        # 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
   629
                        # so add it to the results.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   630
                        if not found_subset:
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   631
                                subres.append((d, d_vars))
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   632
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   633
                # 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
   634
                # 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
   635
                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
   636
                res.extend(subres)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   637
        return res
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   638
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   639
def split_off_variants(dep, pkg_vars):
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   640
        """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
   641
        tags into a VariantSet."""
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   642
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   643
        dep_vars = variants.VariantSets(dep.get_variants())
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   644
        dep_vars.merge_unknown(pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   645
        # 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
   646
        # 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
   647
        # 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
   648
        dep.strip_variants()
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   649
        return dep, dep_vars
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   650
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   651
def prune_debug_attrs(action):
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   652
        """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
   653
        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
   654
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   655
        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
   656
                     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
   657
        return actions.depend.DependencyAction(**attrs)
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   658
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   659
def resolve_deps(manifest_paths, api_inst, prune_attrs=False):
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
   660
        """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
   661
        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
   662
        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
   663
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   664
        '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
   665
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   666
        '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
   667
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   668
        '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
   669
        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
   670
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   671
        # 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
   672
        # 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
   673
        # 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
   674
        # 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
   675
        # 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
   676
        # 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
   677
        manifests = [
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   678
            (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
   679
            missing_files)
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   680
            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
   681
            ((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
   682
            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
   683
        ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   684
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
   685
        delivered_files = {}
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   686
        installed_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
   687
        # Build a list of all files delivered in 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
   688
        for n, f_list, pkg_vars in (
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   689
            (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
   690
            itertools.chain(mfst.gen_actions_by_type("file"),
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   691
                mfst.gen_actions_by_type("hardlink"),
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   692
                mfst.gen_actions_by_type("link")),
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   693
            pv)
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   694
            for mp, name, mfst, pv, miss_files in manifests
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
   695
        ):
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   696
                for f in f_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
   697
                        dep_vars = variants.VariantSets(f.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
   698
                        dep_vars.merge_unknown(pkg_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
   699
                        delivered_files.setdefault(
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   700
                            f.attrs["path"], []).append((n, dep_vars))
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   701
        # 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
   702
        # the system.
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   703
        for (pub, stem, ver), summ, cats, states in api_inst.get_pkg_list(
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   704
            api.ImageInterface.LIST_INSTALLED):
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   705
                pfmri = fmri.PkgFmri("pkg:/%s@%s" % (stem, ver))
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   706
                mfst = api_inst.get_manifest(pfmri, all_variants=True)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   707
                pv = mfst.get_all_variants()
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   708
                for f in itertools.chain(mfst.gen_actions_by_type("file"),
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   709
                    mfst.gen_actions_by_type("hardlink"),
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   710
                    mfst.gen_actions_by_type("link")):
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   711
                        dep_vars = variants.VariantSets(f.get_variants())
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   712
                        dep_vars.merge_unknown(pkg_vars)
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   713
                        installed_files.setdefault(
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   714
                            f.attrs["path"], []).append((pfmri, dep_vars))
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
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
        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
   717
        errs = []
1500
fb15a23b6915 11805 pkgdep generate doesn't respect the payload path for file actions
Brock Pytlik <bpytlik@sun.com>
parents: 1431
diff changeset
   718
        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
   719
                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
   720
                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
   721
                        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
   722
                        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
   723
                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
   724
                    (d, find_package(delivered_files, installed_files,
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1580
diff changeset
   725
                        d, pkg_vars))
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1231
diff changeset
   726
                    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
   727
                    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
   728
                ]
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   729
                # 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
   730
                # manually.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   731
                deps = [
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   732
                    split_off_variants(d, pkg_vars)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   733
                    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
   734
                    if not is_file_dependency(d)
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   735
                ]
1544
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   736
                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
   737
                        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
   738
                        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
   739
                                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
   740
                                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
   741
                                    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
   742
                        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
   743
                                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
   744
                                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
   745
                                        errs.append(UnresolvedDependencyError(
e0ce5081236a 12697 pkgdep throws an exception for $PLATFORM or $ISALIST in runpath
Brock Pytlik <bpytlik@sun.com>
parents: 1516
diff changeset
   746
                                            mp, file_dep, dep_vars))
1756
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   747
                # 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
   748
                # what would otherwise be duplicate dependencies.
0dd15313e977 14118 pkgdepend resolve results in repeated dependencies
Brock Pytlik <bpytlik@sun.com>
parents: 1674
diff changeset
   749
                deps = combine(deps, pkg_vars)
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   750
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   751
                if prune_attrs:
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   752
                        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
   753
                pkg_deps[mp] = deps
1845
d9a33bd442b5 14870 pkgdep should strip dependency debugging information
Richard Lowe <richlowe@richlowe.net>
parents: 1756
diff changeset
   754
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
   755
        return pkg_deps, errs