[libvirt] [PATCH 0/4] apibuild: Fix several issues

My home directory contains src/upstream/libvirt - git repository src/libvirt - symbolic link to the above and since d195cffa2e1b I can no longer build in-tree because make passes srcdir=. builddir=$HOME/src/libvirt/docs to apibuild.py, which get converted to srcdir=$HOME/src/upstream/libvirt/docs builddir=$HOME/src/libvirt/docs inside the script and thus considered separate directories. This in turn leads to files being processed twice, and a bunch of definitions being reported as duplicates. ... Well, kind of. The script *attempts* to report the failures, but fails while doing so :) This series fixes both the build issue (1/4) and the failure to report build issues properly (2/4), plus some more of the latter that I noticed while working on the code (3/4, 4/4). Last but not least: I'm not a pythonista, so feel free to point out unpythonic code. Andrea Bolognani (4): docs: Pass relative paths to apibuild.py apibuild: Add index.warning() method apibuild: Introduce app class apibuild: Fix method call docs/Makefile.am | 2 +- docs/apibuild.py | 103 +++++++++++++++++++++++++++++++------------------------ 2 files changed, 59 insertions(+), 46 deletions(-) -- 2.5.5

Since commit d195cffa2e1b, both $(srcdir) and $(abs_builddir) are passed to the apibuild.py script; however, since the former is a relative path and the latter an absolute one, the script might not be able to detect whether they point to the same location. Pass both as relative paths to avoid the issue. --- docs/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile.am b/docs/Makefile.am index 1b21b5c..282d101 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -325,7 +325,7 @@ $(APIBUILD_STAMP): $(srcdir)/apibuild.py \ $(top_srcdir)/src/util/virerror.c \ $(top_srcdir)/src/util/virevent.c \ $(top_srcdir)/src/util/virtypedparam.c - $(AM_V_GEN)srcdir=$(srcdir) builddir=$(abs_builddir) $(PYTHON) $(APIBUILD) + $(AM_V_GEN)srcdir=$(srcdir) builddir=$(builddir) $(PYTHON) $(APIBUILD) touch $@ -- 2.5.5

This method is used in eg. index.merge(), but is not defined anywhere. The implementation has been copied from docBuilder. --- docs/apibuild.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/apibuild.py b/docs/apibuild.py index 648036f..b1a9d41 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -240,6 +240,11 @@ class index: self.references = {} self.info = {} + def warning(self, msg): + global warnings + warnings = warnings + 1 + print msg + def add_ref(self, name, header, module, static, type, lineno, info=None, extra=None, conditionals = None): if name[0:2] == '__': return None -- 2.5.5

All top-level functions have been moved to this class. On top of that, the app.warning() method has been defined, so that calls to it - already present in rebuild() - can actually succeed. --- docs/apibuild.py | 98 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index b1a9d41..6161336 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -2584,57 +2584,65 @@ class docBuilder: output.close() -def rebuild(name): - if name not in ["libvirt", "libvirt-qemu", "libvirt-lxc", "libvirt-admin"]: - self.warning("rebuild() failed, unknown module %s") % name - return None - builder = None - srcdir = os.path.abspath((os.environ["srcdir"])) - builddir = os.path.abspath((os.environ["builddir"])) - if srcdir == builddir: - builddir = None - if glob.glob(srcdir + "/../src/libvirt.c") != [] : - if not quiet: - print "Rebuilding API description for %s" % name - dirs = [srcdir + "/../src", - srcdir + "/../src/util", - srcdir + "/../include/libvirt"] - if builddir: - dirs.append(builddir + "/../include/libvirt") - if glob.glob(srcdir + "/../include/libvirt/libvirt.h") == [] : - dirs.append("../include/libvirt") - builder = docBuilder(name, srcdir, dirs, []) - elif glob.glob("src/libvirt.c") != [] : - if not quiet: - print "Rebuilding API description for %s" % name - builder = docBuilder(name, srcdir, - ["src", "src/util", "include/libvirt"], - []) - else: - self.warning("rebuild() failed, unable to guess the module") - return None - builder.scan() - builder.analyze() - builder.serialize() - return builder +class app: + def warning(self, msg): + global warnings + warnings = warnings + 1 + print msg + + def rebuild(self, name): + if name not in ["libvirt", "libvirt-qemu", "libvirt-lxc", "libvirt-admin"]: + self.warning("rebuild() failed, unknown module %s") % name + return None + builder = None + srcdir = os.path.abspath((os.environ["srcdir"])) + builddir = os.path.abspath((os.environ["builddir"])) + if srcdir == builddir: + builddir = None + if glob.glob(srcdir + "/../src/libvirt.c") != [] : + if not quiet: + print "Rebuilding API description for %s" % name + dirs = [srcdir + "/../src", + srcdir + "/../src/util", + srcdir + "/../include/libvirt"] + if builddir: + dirs.append(builddir + "/../include/libvirt") + if glob.glob(srcdir + "/../include/libvirt/libvirt.h") == [] : + dirs.append("../include/libvirt") + builder = docBuilder(name, srcdir, dirs, []) + elif glob.glob("src/libvirt.c") != [] : + if not quiet: + print "Rebuilding API description for %s" % name + builder = docBuilder(name, srcdir, + ["src", "src/util", "include/libvirt"], + []) + else: + self.warning("rebuild() failed, unable to guess the module") + return None + builder.scan() + builder.analyze() + builder.serialize() + return builder + + # + # for debugging the parser + # + def parse(self, filename): + parser = CParser(filename) + idx = parser.parse() + return idx -# -# for debugging the parser -# -def parse(filename): - parser = CParser(filename) - idx = parser.parse() - return idx if __name__ == "__main__": + app = app() if len(sys.argv) > 1: debug = 1 - parse(sys.argv[1]) + app.parse(sys.argv[1]) else: - rebuild("libvirt") - rebuild("libvirt-qemu") - rebuild("libvirt-lxc") - rebuild("libvirt-admin") + app.rebuild("libvirt") + app.rebuild("libvirt-qemu") + app.rebuild("libvirt-lxc") + app.rebuild("libvirt-admin") if warnings > 0: sys.exit(2) else: -- 2.5.5

--- docs/apibuild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index 6161336..7e4a526 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -2592,7 +2592,7 @@ class app: def rebuild(self, name): if name not in ["libvirt", "libvirt-qemu", "libvirt-lxc", "libvirt-admin"]: - self.warning("rebuild() failed, unknown module %s") % name + self.warning("rebuild() failed, unknown module %s" % name) return None builder = None srcdir = os.path.abspath((os.environ["srcdir"])) -- 2.5.5

On 04/25/2016 09:20 AM, Andrea Bolognani wrote:
My home directory contains
src/upstream/libvirt - git repository src/libvirt - symbolic link to the above
and since d195cffa2e1b I can no longer build in-tree because make passes
srcdir=. builddir=$HOME/src/libvirt/docs
to apibuild.py, which get converted to
srcdir=$HOME/src/upstream/libvirt/docs builddir=$HOME/src/libvirt/docs
inside the script and thus considered separate directories. This in turn leads to files being processed twice, and a bunch of definitions being reported as duplicates.
... Well, kind of. The script *attempts* to report the failures, but fails while doing so :)
This series fixes both the build issue (1/4) and the failure to report build issues properly (2/4), plus some more of the latter that I noticed while working on the code (3/4, 4/4).
Last but not least: I'm not a pythonista, so feel free to point out unpythonic code.
The entire file is quite unpythonic by modern standards so IMO not worth nitpicking over. All 4 look fine to me, ACK - Cole

On Mon, 2016-04-25 at 15:40 -0400, Cole Robinson wrote:
This series fixes both the build issue (1/4) and the failure to report build issues properly (2/4), plus some more of the latter that I noticed while working on the code (3/4, 4/4).
Last but not least: I'm not a pythonista, so feel free to point out unpythonic code.
The entire file is quite unpythonic by modern standards so IMO not worth nitpicking over.
All 4 look fine to me, ACK
Pushed, thanks :) -- Andrea Bolognani Software Engineer - Virtualization Team
participants (2)
-
Andrea Bolognani
-
Cole Robinson