16499 pkgdepend resolve -mo includes manifest path in output stream
authorBrock Pytlik <brock.pytlik@oracle.com>
Tue, 29 Mar 2011 15:08:42 -0700
changeset 2283 c368082b6a17
parent 2282 35bb44f90dcd
child 2284 7e9dfdc8fc7c
16499 pkgdepend resolve -mo includes manifest path in output stream 18019 pkgdepend resolves to double up group dependencies 18077 resolve traces back if two dependencies of different types are given 18082 it should be clear that -o is not parseable
src/man/pkgdepend.1.txt
src/modules/publish/dependencies.py
src/pkgdep.py
src/tests/cli/t_pkgdep.py
src/tests/cli/t_pkgdep_resolve.py
--- a/src/man/pkgdepend.1.txt	Thu Mar 24 19:50:31 2011 -0700
+++ b/src/man/pkgdepend.1.txt	Tue Mar 29 15:08:42 2011 -0700
@@ -141,7 +141,11 @@
           by the generate step removed, before adding the resolved
           dependencies.
 
-          With -o, write the results to standard output.
+          With -o, write the results to standard output.  This option is
+          intended for human consumption.  If its output is appended to a file,
+          it may result in an invalid manifest.  For use in a pipe line for
+          manifest processing, using -d or -s instead of -o is strongly
+          recommended.
 
           With -d, write the resolved dependencies for each manifest
           provided in a separate file in output_dir.  By default, each
--- a/src/modules/publish/dependencies.py	Thu Mar 24 19:50:31 2011 -0700
+++ b/src/modules/publish/dependencies.py	Tue Mar 29 15:08:42 2011 -0700
@@ -936,9 +936,11 @@
                 so that the groups match the duplicate actions that the code
                 in pkg.manifest notices."""
 
-                # d[0] is the action.  d[1] is the VariantCombination for this
-                # action.
-                return d[0].name, d[0].attrs.get(d[0].key_attr, id(d[0]))
+                # d is a tuple containing two items.  d[0] is the action.  d[1]
+                # is the VariantCombination for this action.  The
+                # VariantCombination isn't useful for our grouping needs.
+                return d[0].name, d[0].attrs.get("type", None), \
+                    d[0].attrs.get(d[0].key_attr, id(d[0]))
 
         def add_vars(d, d_vars, pkg_vars):
                 """Add the variants 'd_vars' to the dependency 'd', after
--- a/src/pkgdep.py	Thu Mar 24 19:50:31 2011 -0700
+++ b/src/pkgdep.py	Tue Mar 29 15:08:42 2011 -0700
@@ -354,8 +354,7 @@
         except actions.ActionError:
                 return True
         else:
-                return not act.name == "depend" or \
-                    act.attrs["type"] != "require"
+                return not act.name == "depend"
 
 def pkgdeps_to_screen(pkg_deps, manifest_paths, echo_manifest):
         """Write the resolved package dependencies to stdout.
@@ -370,8 +369,12 @@
         manifest will be written out or not."""
 
         ret_code = 0
+        first = True
         for p in manifest_paths:
-                msg(p)
+                if not first:
+                        msg("\n\n")
+                first = False
+                msg("# %s" % p)
                 if echo_manifest:
                         try:
                                 fh = open(p, "rb")
@@ -385,7 +388,6 @@
                                 ret_code = 1
                 for d in pkg_deps[p]:
                         msg(d)
-                msg(_("\n\n"))
         return ret_code
 
 def write_res(deps, out_file, echo_manifest, manifest_path):
@@ -419,6 +421,8 @@
                             manifest_path)
                 for l in fh:
                         if resolve_echo_line(l):
+                                if l[-1] != "\n":
+                                        l += "\n"
                                 out_fh.write(l)
                 fh.close()
         for d in deps:
--- a/src/tests/cli/t_pkgdep.py	Thu Mar 24 19:50:31 2011 -0700
+++ b/src/tests/cli/t_pkgdep.py	Tue Mar 29 15:08:42 2011 -0700
@@ -236,44 +236,39 @@
 """
 
         two_v_deps_verbose_output = """\
-%(m1_path)s
+# %(m1_path)s
 depend fmri=pkg:/s-v-bar pkg.debug.depend.file=var/log/authlog pkg.debug.depend.file=var/log/file2 pkg.debug.depend.reason=baz pkg.debug.depend.type=hardlink type=require
 depend fmri=pkg:/s-v-baz-one pkg.debug.depend.file=var/log/authlog pkg.debug.depend.reason=baz pkg.debug.depend.type=hardlink type=require variant.foo=baz variant.num=one
 depend fmri=pkg:/s-v-baz-two pkg.debug.depend.file=var/log/authlog pkg.debug.depend.reason=baz pkg.debug.depend.type=hardlink type=require variant.foo=baz variant.num=two
 
 
-%(m2_path)s
-
-
-
-%(m3_path)s
+# %(m2_path)s
 
 
 
-%(m4_path)s
+# %(m3_path)s
 
 
 
+# %(m4_path)s
 """
 
         two_v_deps_output = """\
-%(m1_path)s
+# %(m1_path)s
 depend fmri=pkg:/s-v-bar type=require
 depend fmri=pkg:/s-v-baz-one type=require variant.foo=baz variant.num=one
 depend fmri=pkg:/s-v-baz-two type=require variant.foo=baz variant.num=two
 
 
-%(m2_path)s
+# %(m2_path)s
 
 
 
-%(m3_path)s
+# %(m3_path)s
 
 
 
-%(m4_path)s
-
-
+# %(m4_path)s
 """
 
         dup_variant_deps = """\
@@ -545,7 +540,8 @@
 """
 
         satisfying_out = """\
-depend fmri=pkg:/satisfying_manf type=require variant.foo=baz"""
+depend fmri=pkg:/satisfying_manf type=require variant.foo=baz
+"""
 
         def make_pyver_python_res(self, ver, proto_area=None):
                 """Create the python dependency results with paths expected for
@@ -969,7 +965,7 @@
 
                 # Check that -S doesn't prevent the resolution from happening.
                 self.pkgdepend_resolve("-S -o %s" % res_path, exit=1)
-                self.check_res("%s" % res_path, self.output)
+                self.check_res("# %s" % res_path, self.output)
                 self.check_res(self.resolve_error % {
                         "manf_path": res_path,
                         "pfx":
@@ -1407,14 +1403,16 @@
 
                 self.pkgdepend_resolve("-o %s %s %s" %
                     (col_path, bar_path, foo_path), exit=1)
-                self.check_res("\n\n".join([col_path, bar_path, foo_path]),
+                self.check_res("\n\n".join(
+                    ["# %s" % l for l in [col_path, bar_path, foo_path]]),
                     self.output)
                 self.check_res(self.run_path_errors %
                     {"unresolved_path": col_path, "vc": ""}, self.errout)
 
                 self.pkgdepend_resolve("-o %s %s %s" %
                     (col_path, bar_path, bar2_path), exit=1)
-                self.check_res("\n\n".join([col_path, bar_path, bar2_path]),
+                self.check_res("\n\n".join(
+                    ["# %s" % l for l in [col_path, bar_path, bar2_path]]),
                     self.output)
                 self.check_res(self.amb_path_errors %
                     {"unresolved_path": col_path}, self.errout)
@@ -1452,8 +1450,8 @@
                 self.pkgdepend_resolve(" -o %s %s" % (partial, satisfying),
                     exit=1)
                 self.check_res(self.unsatisfied_error_2 % partial, self.errout)
-                self.check_res("%s\n\n%s\n%s" % (partial, satisfying,
-                    self.satisfying_out), self.output)
+                self.check_res("# %s\n%s\n\n# %s\n" % (partial,
+                    self.satisfying_out, satisfying), self.output)
 
                 # No dependencies at all
                 self.pkgdepend_resolve(" -o %s" % satisfying)
--- a/src/tests/cli/t_pkgdep_resolve.py	Thu Mar 24 19:50:31 2011 -0700
+++ b/src/tests/cli/t_pkgdep_resolve.py	Tue Mar 29 15:08:42 2011 -0700
@@ -32,6 +32,7 @@
 import unittest
 
 import pkg.client.api as api
+import pkg.actions.depend as depend
 import pkg.client.progress as progress
 import pkg.flavor.base as base
 from pkg.fmri import PkgFmri
@@ -929,6 +930,24 @@
                             isinstance(e,
                             dependencies.UnresolvedDependencyError))
 
+        def test_bug_18019(self):
+                """Test that a package with manually annotated group,
+                incorporate, or other types of dependencies doesn't end up with
+                two copies of any dependencies."""
+
+                manf = ["set name=pkg.fmri [email protected],5.11-1"]
+                for t in depend.known_types:
+                        manf.append("depend fmri=pkg:/%(type)s@0,5.11-1 "
+                            "type=%(type)s" % {"type": t})
+                manf_path = self.make_manifest("\n".join(manf))
+                self.pkgdepend_resolve("-m %s" % manf_path)
+                res_path = manf_path + ".res"
+                with open(res_path, "r") as fh:
+                        s = fh.read()
+                s = s.splitlines()
+                self.assertEqualDiff("\n".join(sorted(manf)),
+                    "\n".join(sorted(s)))
+
         def test_bug_18045_normal(self):
                 """Test that when a package without variants has a file
                 dependency on a file in a package that declares variants,
@@ -995,6 +1014,24 @@
                 self.assert_(pkg_deps[dep_path][0].attrs["fmri"].startswith(
                     "pkg:/runtime/[email protected]"))
 
+        def test_bug_18077(self):
+                """Test that a package with manually annotated group,
+                incorporate, or other types of dependencies on the same package
+                doesn't cause pkgdep resolve to traceback."""
+
+                manf = ["set name=pkg.fmri [email protected],5.11-1"]
+                for t in depend.known_types:
+                        manf.append("depend fmri=pkg:/foo@0,5.11-1 "
+                            "type=%(type)s" % {"type": t})
+                manf_path = self.make_manifest("\n".join(manf))
+                self.pkgdepend_resolve("-m %s" % manf_path)
+                res_path = manf_path + ".res"
+                with open(res_path, "r") as fh:
+                        s = fh.read()
+                s = s.splitlines()
+                self.assertEqualDiff("\n".join(sorted(manf)),
+                    "\n".join(sorted(s)))
+
 
 if __name__ == "__main__":
         unittest.main()