--- a/src/pkgdep.py Thu Jul 28 14:24:17 2011 +1200
+++ b/src/pkgdep.py Wed Jul 27 19:53:47 2011 -0700
@@ -37,6 +37,7 @@
import pkg.client.api as api
import pkg.client.api_errors as api_errors
import pkg.client.progress as progress
+import pkg.manifest as manifest
import pkg.misc as misc
import pkg.publish.dependencies as dependencies
from pkg.misc import msg, emsg, PipeError
@@ -353,7 +354,7 @@
emsg(e)
return ret_code
-def resolve_echo_line(l):
+def __resolve_echo_line(l):
"""Given a line from a manifest, determines whether that line should
be repeated in the output file if echo manifest has been set."""
@@ -366,6 +367,34 @@
else:
return not act.name == "depend"
+def __echo_manifest(pth, out_func, strip_newline=False):
+ try:
+ with open(pth, "rb") as fh:
+ text = ""
+ act = ""
+ for l in fh:
+ text += l
+ act += l.rstrip()
+ if act.endswith("\\"):
+ act = act.rstrip("\\")
+ continue
+ if __resolve_echo_line(act):
+ if strip_newline:
+ text = text.rstrip()
+ elif text[-1] != "\n":
+ text += "\n"
+ out_func(text)
+ text = ""
+ act = ""
+ if text != "" and __resolve_echo_line(act):
+ if text[-1] != "\n":
+ text += "\n"
+ out_func(text)
+ except EnvironmentError:
+ ret_code = 1
+ emsg(_("Could not open %s to echo manifest") %
+ manifest_path)
+
def pkgdeps_to_screen(pkg_deps, manifest_paths, echo_manifest):
"""Write the resolved package dependencies to stdout.
@@ -386,16 +415,7 @@
first = False
msg("# %s" % p)
if echo_manifest:
- try:
- fh = open(p, "rb")
- for l in fh:
- if resolve_echo_line(l):
- msg(l.rstrip())
- fh.close()
- except EnvironmentError:
- emsg(_("Could not open %s to echo manifest") %
- p)
- ret_code = 1
+ __echo_manifest(p, msg, strip_newline=True)
for d in pkg_deps[p]:
msg(d)
return ret_code
@@ -423,18 +443,7 @@
out_file)
return ret_code
if echo_manifest:
- try:
- fh = open(manifest_path, "rb")
- except EnvironmentError:
- ret_code = 1
- emsg(_("Could not open %s to echo manifest") %
- manifest_path)
- for l in fh:
- if resolve_echo_line(l):
- if l[-1] != "\n":
- l += "\n"
- out_fh.write(l)
- fh.close()
+ __echo_manifest(manifest_path, out_fh.write)
for d in deps:
out_fh.write("%s\n" % d)
out_fh.close()
--- a/src/tests/cli/t_pkgdep.py Thu Jul 28 14:24:17 2011 +1200
+++ b/src/tests/cli/t_pkgdep.py Wed Jul 27 19:53:47 2011 -0700
@@ -268,20 +268,23 @@
two_v_deps_output = """\
# %(m1_path)s
+set name=variant.foo value=bar value=baz
+set name=variant.num value=one value=three value=two
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_fmt)s
# %(m3_path)s
-
+%(m3_fmt)s
# %(m4_path)s
+%(m4_fmt)s
"""
dup_variant_deps = """\
@@ -1297,14 +1300,22 @@
m2_path = self.make_manifest(self.two_v_deps_bar)
m3_path = self.make_manifest(self.two_v_deps_baz_one)
m4_path = self.make_manifest(self.two_v_deps_baz_two)
- self.pkgdepend_resolve("-o %s" %
+ # Use pkgfmt on the manifest to test for bug 18740.
+ self.pkgfmt(m1_path)
+ with open(m1_path, "rb") as fh:
+ m1_fmt = fh.read()
+ self.pkgdepend_resolve("-o -m %s" %
" ".join([m1_path, m2_path, m3_path, m4_path]), exit=1)
self.check_res(self.two_v_deps_output % {
"m1_path": m1_path,
"m2_path": m2_path,
"m3_path": m3_path,
- "m4_path": m4_path
+ "m4_path": m4_path,
+ "m1_fmt": m1_fmt,
+ "m2_fmt": self.two_v_deps_bar,
+ "m3_fmt": self.two_v_deps_baz_one,
+ "m4_fmt": self.two_v_deps_baz_two,
}, self.output)
self.check_res(self.two_v_deps_resolve_error % {
@@ -1630,6 +1641,10 @@
# that manually added dependencies are propogated correctly.
m8_path = self.make_manifest("\n\n")
+ # Test that resolve handles multiline actions correctly when
+ # echoing the manifest. Bug 18740
+ self.pkgfmt(m1_path)
+
self.pkgdepend_resolve(" -vm %s" % " ".join([m1_path, m2_path,
m3_path, m4_path, m5_path, m6_path, m7_path, m8_path]))
fh = open(m1_path + ".res")
--- a/src/tests/cli/t_pkgfmt.py Thu Jul 28 14:24:17 2011 +1200
+++ b/src/tests/cli/t_pkgfmt.py Wed Jul 27 19:53:47 2011 -0700
@@ -1216,10 +1216,6 @@
"wb") as f:
f.write(self.needs_formatting)
- def pkgfmt(self, args, exit=0, su_wrap=False):
- cmd="%s/usr/bin/pkgfmt %s" % (pkg5unittest.g_proto_area, args)
- self.cmdline_run(cmd, exit=exit, su_wrap=su_wrap)
-
def test_0_checkfmt(self):
"""Verify that pkgfmt -c format checking works as expected."""
--- a/src/tests/pkg5unittest.py Thu Jul 28 14:24:17 2011 +1200
+++ b/src/tests/pkg5unittest.py Wed Jul 27 19:53:47 2011 -0700
@@ -1618,6 +1618,10 @@
return self.cmdline_run(cmdline, comment=comment, exit=exit,
su_wrap=su_wrap)
+ def pkgfmt(self, args, exit=0, su_wrap=False):
+ cmd="%s/usr/bin/pkgfmt %s" % (g_proto_area, args)
+ self.cmdline_run(cmd, exit=exit, su_wrap=su_wrap)
+
def pkglint(self, args, exit=0, comment="", testrc=True):
if testrc:
rcpath = "%s/pkglintrc" % self.test_root