diff mbox

[ovs-dev] xml2nroff: Fix build breakage when srcdir differs from builddir.

Message ID 1452623999-25314-1-git-send-email-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff Jan. 12, 2016, 6:39 p.m. UTC
When the source directory and build directory differ, xml2nroff needs
to pull include files from the source directory, but it was blindly
using the current working directory (the build directory) instead.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Fixes: 7ba0c32f610 ("ovn-nbctl: add db commands help and manpage")
---
 Makefile.am         |  3 ++-
 build-aux/xml2nroff | 30 +++++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 8 deletions(-)

Comments

Joe Stringer Jan. 12, 2016, 6:47 p.m. UTC | #1
On 12 January 2016 at 10:39, Ben Pfaff <blp@ovn.org> wrote:
> When the source directory and build directory differ, xml2nroff needs
> to pull include files from the source directory, but it was blindly
> using the current working directory (the build directory) instead.
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> Fixes: 7ba0c32f610 ("ovn-nbctl: add db commands help and manpage")

Thanks, this fixes the build for me too.

Acked-by: Joe Stringer <joe@ovn.org>
Ben Pfaff Jan. 12, 2016, 6:55 p.m. UTC | #2
On Tue, Jan 12, 2016 at 10:47:48AM -0800, Joe Stringer wrote:
> On 12 January 2016 at 10:39, Ben Pfaff <blp@ovn.org> wrote:
> > When the source directory and build directory differ, xml2nroff needs
> > to pull include files from the source directory, but it was blindly
> > using the current working directory (the build directory) instead.
> >
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > Fixes: 7ba0c32f610 ("ovn-nbctl: add db commands help and manpage")
> 
> Thanks, this fixes the build for me too.
> 
> Acked-by: Joe Stringer <joe@ovn.org>

Thanks, applied to master.
Russell Bryant Jan. 12, 2016, 7:16 p.m. UTC | #3
On 01/12/2016 01:55 PM, Ben Pfaff wrote:
> On Tue, Jan 12, 2016 at 10:47:48AM -0800, Joe Stringer wrote:
>> On 12 January 2016 at 10:39, Ben Pfaff <blp@ovn.org> wrote:
>>> When the source directory and build directory differ, xml2nroff needs
>>> to pull include files from the source directory, but it was blindly
>>> using the current working directory (the build directory) instead.
>>>
>>> Signed-off-by: Ben Pfaff <blp@ovn.org>
>>> Fixes: 7ba0c32f610 ("ovn-nbctl: add db commands help and manpage")
>>
>> Thanks, this fixes the build for me too.
>>
>> Acked-by: Joe Stringer <joe@ovn.org>
> 
> Thanks, applied to master.

Sorry for the trouble!
diff mbox

Patch

diff --git a/Makefile.am b/Makefile.am
index 9be2b96..9ee2229 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@ 
-# Copyright (C) 2007-2015 Nicira, Inc.
+# Copyright (C) 2007-2016 Nicira, Inc.
 #
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
@@ -183,6 +183,7 @@  SUFFIXES += .in
 SUFFIXES += .xml
 %: %.xml
 	$(AM_V_GEN)$(run_python) $(srcdir)/build-aux/xml2nroff $< > $@.tmp \
+		-I $(srcdir) \
 		--version=$(VERSION) \
 		PKIDIR='$(PKIDIR)' \
 		LOGDIR='$(LOGDIR)' \
diff --git a/build-aux/xml2nroff b/build-aux/xml2nroff
index 01e79f1..df1df28 100755
--- a/build-aux/xml2nroff
+++ b/build-aux/xml2nroff
@@ -1,6 +1,6 @@ 
 #! /usr/bin/python
 
-# Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+# Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -34,13 +34,14 @@  Each VAR, when enclosed by "@"s in the input, is replaced by its
 corresponding VALUE, with characters &<>"' in VALUE escaped.
 
 The following options are also available:
+  -I, --include=DIR           search DIR for include files (default: .)
   --version=VERSION           use VERSION to display on document footer
   -h, --help                  display this help message\
 """ % {'argv0': argv0}
     sys.exit(0)
 
 
-def manpage_to_nroff(xml_file, subst, version=None):
+def manpage_to_nroff(xml_file, subst, include_path, version=None):
     with open(xml_file) as f:
         content = f.read()
     for k, v in subst.iteritems():
@@ -49,8 +50,18 @@  def manpage_to_nroff(xml_file, subst, version=None):
 
     xi_nodes = doc.getElementsByTagName("xi:include")
     for node in xi_nodes:
-        with open(node.getAttribute("href")) as xi_f:
-            content = xi_f.read()
+        fn = node.getAttribute("href")
+        content = None
+        for dir in include_path:
+            try:
+                with open("%s/%s" % (dir, fn)) as xi_f:
+                    content = xi_f.read()
+            except IOError:
+                pass
+        if not content:
+            sys.stderr.write("%s: could not open include file %s\n"
+                             % (argv0, fn))
+            sys.exit(1)
         for k, v in subst.iteritems():
             content = content.replace(k, v)
         xi_doc = xml.dom.minidom.parseString(content).documentElement
@@ -89,8 +100,8 @@  def manpage_to_nroff(xml_file, subst, version=None):
 
 if __name__ == "__main__":
     try:
-        options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
-                                          ['version=', 'help'])
+        options, args = getopt.gnu_getopt(sys.argv[1:], 'hVI:',
+                                          ['version=', 'help', 'include='])
     except getopt.GetoptError, geo:
         sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
         sys.exit(1)
@@ -98,13 +109,18 @@  if __name__ == "__main__":
     er_diagram = None
     title = None
     version = None
+    include_path = []
     for key, value in options:
         if key == '--version':
             version = value
         elif key in ['-h', '--help']:
             usage()
+        elif key in ['-I', '--include']:
+            include_path.append(value)
         else:
             sys.exit(0)
+    if not include_path:
+        include_path = ['.']
 
     if len(args) < 1:
         sys.stderr.write("%s: exactly 1 non-option arguments required "
@@ -122,7 +138,7 @@  if __name__ == "__main__":
         subst['@%s@' % var] = value
 
     try:
-        s = manpage_to_nroff(args[0], subst, version)
+        s = manpage_to_nroff(args[0], subst, include_path, version)
     except build.nroff.error.Error, e:
         sys.stderr.write("%s: %s\n" % (argv0, e.msg))
         sys.exit(1)