From bdbec3056ac52764d46207afc1140ce00a74a1e2 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sat, 28 Sep 2013 19:52:22 +0200 Subject: [PATCH] Improve checking for modified files https://review.openstack.org/#/c/48726/ introduced a typo in the filename of an include directive that was not detected by our validation scripts since we did only check whether a file included a modified file but omit checking pom.xml for modification of included files. So, if bk-* gets modified, we do not notice it and therefore won't build the book. With this change, the books will be build. I also added a couple of comments. Change-Id: Idba71ac4f9f1e4de2c414bcc0110351966df3248 --- test.py | 66 ++++++++++++++++++++++++++++++++--------------------- validate.py | 66 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 82 insertions(+), 50 deletions(-) diff --git a/test.py b/test.py index a84d27f2..054bb5ab 100755 --- a/test.py +++ b/test.py @@ -415,36 +415,50 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, os.chdir(root) - for f in files: - if (f.endswith('.xml') and - f != 'pom.xml' and - f not in file_exceptions): - path = os.path.abspath(os.path.join(root, f)) - doc = etree.parse(path) - - # Check for inclusion of files as part of imagedata - for node in doc.findall( - '//{http://docbook.org/ns/docbook}imagedata'): - href = node.get('fileref') - if (f not in file_exceptions and - os.path.abspath(href) in modified_files): + # We can scan only for depth of one of inclusion + # therefore skip the common directory since there's no + # book build in it. + if not root.endswith('doc/common'): + for f in files: + if (f.endswith('.xml') and + f != 'pom.xml' and + f not in file_exceptions): + path = os.path.abspath(os.path.join(root, f)) + # If the file itself is modified, build the book + if path in modified_files: affected_books.append(book_root) break + # If the file itself is modified, build the book. + # Note this is an optimization in most cases but + # needed for bk-*.xml since those are included by + # pom.xml and pom.xml is not checked for + # modification of included files. + doc = etree.parse(path) + + # Check for inclusion of files as part of imagedata + for node in doc.findall( + '//{http://docbook.org/ns/docbook}imagedata'): + href = node.get('fileref') + if (f not in file_exceptions and + os.path.abspath(href) in modified_files): + affected_books.append(book_root) + break + + if book_root in affected_books: + break + + # Check for inclusion of files as part of xi:include + ns = {"xi": "http://www.w3.org/2001/XInclude"} + for node in doc.xpath('//xi:include', namespaces=ns): + href = node.get('href') + if (f not in file_exceptions and + os.path.abspath(href) in modified_files): + affected_books.append(book_root) + break if book_root in affected_books: break - - # Check for inclusion of files as part of xi:include - ns = {"xi": "http://www.w3.org/2001/XInclude"} - for node in doc.xpath('//xi:include', namespaces=ns): - href = node.get('href') - if (f not in file_exceptions and - os.path.abspath(href) in modified_files): - affected_books.append(book_root) - break - if book_root in affected_books: - break - + if not force and affected_books: books = affected_books else: @@ -478,7 +492,7 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, if voting and any_failures: sys.exit(1) - + print("Building finished.") def main(args): diff --git a/validate.py b/validate.py index 1be79c0c..7d37940e 100755 --- a/validate.py +++ b/validate.py @@ -407,36 +407,53 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, force): os.chdir(root) - for f in files: - if (f.endswith('.xml') and - f != 'pom.xml' and - f not in file_exceptions): - path = os.path.abspath(os.path.join(root, f)) - doc = etree.parse(path) + # We can scan only for depth of one of inclusion + # therefore skip the common directory since there's no + # book build in it. + if not root.endswith('doc/common'): + for f in files: + if (f.endswith('.xml') and + f != 'pom.xml' and + f not in file_exceptions): + path = os.path.abspath(os.path.join(root, f)) - # Check for inclusion of files as part of imagedata - for node in doc.findall( - '//{http://docbook.org/ns/docbook}imagedata'): - href = node.get('fileref') - if (f not in file_exceptions and - os.path.abspath(href) in modified_files): + # If the file itself is modified, build the book. + # Note this is an optimization in most cases but + # needed for bk-*.xml since those are included by + # pom.xml and pom.xml is not checked for + # modification of included files. + if path in modified_files: affected_books.append(book_root) break + # Now check whether the file includes a file that + # was modified (scanning one level only) + + doc = etree.parse(path) + + # Check for inclusion of files as part of imagedata + for node in doc.findall( + '//{http://docbook.org/ns/docbook}imagedata'): + href = node.get('fileref') + if (f not in file_exceptions and + os.path.abspath(href) in modified_files): + affected_books.append(book_root) + break + + if book_root in affected_books: + break + + # Check for inclusion of files as part of xi:include + ns = {"xi": "http://www.w3.org/2001/XInclude"} + for node in doc.xpath('//xi:include', namespaces=ns): + href = node.get('href') + if (f not in file_exceptions and + os.path.abspath(href) in modified_files): + affected_books.append(book_root) + break if book_root in affected_books: break - - # Check for inclusion of files as part of xi:include - ns = {"xi": "http://www.w3.org/2001/XInclude"} - for node in doc.xpath('//xi:include', namespaces=ns): - href = node.get('href') - if (f not in file_exceptions and - os.path.abspath(href) in modified_files): - affected_books.append(book_root) - break - if book_root in affected_books: - break - + if not force and affected_books: books = affected_books else: @@ -469,6 +486,7 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, force): print("\n%s" % output) if any_failures: sys.exit(1) + print("Building finished.") def main(rootdir, force, verbose):