$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r86703 - in trunk/tools/quickbook: src test/python
From: dnljms_at_[hidden]
Date: 2013-11-14 14:22:09
Author: danieljames
Date: 2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)
New Revision: 86703
URL: http://svn.boost.org/trac/boost/changeset/86703
Log:
Glob dependency tracking.
Added:
   trunk/tools/quickbook/test/python/include_glob.qbk   (contents, props changed)
   trunk/tools/quickbook/test/python/include_glob_deps.txt   (contents, props changed)
   trunk/tools/quickbook/test/python/include_glob_locs.txt   (contents, props changed)
Text files modified: 
   trunk/tools/quickbook/src/dependency_tracker.cpp        |    54 ++++++++++++++++++++++++++++++++++++--- 
   trunk/tools/quickbook/src/dependency_tracker.hpp        |    10 +++++++                                 
   trunk/tools/quickbook/src/include_paths.cpp             |     9 +++++-                                  
   trunk/tools/quickbook/test/python/include_glob.qbk      |    11 ++++++++                                
   trunk/tools/quickbook/test/python/include_glob_deps.txt |     6 ++++                                    
   trunk/tools/quickbook/test/python/include_glob_locs.txt |     9 ++++++                                  
   trunk/tools/quickbook/test/python/output-deps.py        |    32 +++++++++++++++++-----                  
   7 files changed, 116 insertions(+), 15 deletions(-)
Modified: trunk/tools/quickbook/src/dependency_tracker.cpp
==============================================================================
--- trunk/tools/quickbook/src/dependency_tracker.cpp	Thu Nov 14 14:21:37 2013	(r86702)
+++ trunk/tools/quickbook/src/dependency_tracker.cpp	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -100,12 +100,27 @@
         return generic;
     }
 
+    dependency_tracker::dependency_tracker() :
+        dependencies(), glob_dependencies(),
+        last_glob(glob_dependencies.end()) {}
+
     bool dependency_tracker::add_dependency(fs::path const& f) {
         bool found = fs::exists(fs::status(f));
         dependencies[normalize_path(f)] |= found;
         return found;
     }
 
+    void dependency_tracker::add_glob(fs::path const& f) {
+        std::pair<glob_list::iterator, bool> r = glob_dependencies.insert(
+                std::make_pair(normalize_path(f), glob_list::mapped_type()));
+        last_glob = r.first;
+    }
+
+    void dependency_tracker::add_glob_match(fs::path const& f) {
+        assert(last_glob != glob_dependencies.end());
+        last_glob->second.insert(normalize_path(f));
+    }
+
     void dependency_tracker::write_dependencies(fs::path const& file_out,
             flags f)
     {
@@ -124,17 +139,46 @@
     void dependency_tracker::write_dependencies(std::ostream& out,
             flags f)
     {
-        BOOST_FOREACH(dependency_list::value_type const& d, dependencies)
-        {
-            if (f & checked) {
+        if (f & checked) {
+            BOOST_FOREACH(dependency_list::value_type const& d, dependencies)
+            {
                 out << (d.second ? "+ " : "- ")
                     << get_path(d.first, f) << std::endl;
             }
-            else {
+
+            BOOST_FOREACH(glob_list::value_type const& g, glob_dependencies)
+            {
+                out << "g "
+                    << get_path(g.first, f) << std::endl;
+
+                BOOST_FOREACH(fs::path const& p, g.second)
+                {
+                    out << "+ " << get_path(p, f) << std::endl;
+                }
+            }
+        }
+        else {
+            std::set<std::string> paths;
+
+            BOOST_FOREACH(dependency_list::value_type const& d, dependencies)
+            {
                 if (d.second) {
-                    out << get_path(d.first, f) << std::endl;
+                    paths.insert(get_path(d.first, f));
+                }
+            }
+
+            BOOST_FOREACH(glob_list::value_type const& g, glob_dependencies)
+            {
+                BOOST_FOREACH(fs::path const& p, g.second)
+                {
+                    paths.insert(get_path(p, f));
                 }
             }
+
+            BOOST_FOREACH(std::string const& p, paths)
+            {
+                out << p << std::endl;
+            }
         }
     }
 }
Modified: trunk/tools/quickbook/src/dependency_tracker.hpp
==============================================================================
--- trunk/tools/quickbook/src/dependency_tracker.hpp	Thu Nov 14 14:21:37 2013	(r86702)
+++ trunk/tools/quickbook/src/dependency_tracker.hpp	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -10,6 +10,7 @@
 #define QUICKBOOK_DEPENDENCY_TRACKER_HPP
 
 #include <map>
+#include <set>
 #include <iosfwd>
 #include <boost/filesystem/path.hpp>
 
@@ -21,7 +22,11 @@
     private:
 
         typedef std::map<fs::path, bool> dependency_list;
+        typedef std::map<fs::path, std::set<fs::path> > glob_list;
+
         dependency_list dependencies;
+        glob_list glob_dependencies;
+        glob_list::iterator last_glob;
 
     public:
 
@@ -31,10 +36,15 @@
             escaped = 2
         };
 
+        dependency_tracker();
+
         // Call this before loading any file so that it will be included in the
         // list of dependencies. Returns true if file exists.
         bool add_dependency(fs::path const&);
 
+        void add_glob(fs::path const&);
+        void add_glob_match(fs::path const&);
+
         void write_dependencies(fs::path const&, flags = default_);
         void write_dependencies(std::ostream&, flags = default_);
     };
Modified: trunk/tools/quickbook/src/include_paths.cpp
==============================================================================
--- trunk/tools/quickbook/src/include_paths.cpp	Thu Nov 14 14:21:37 2013	(r86702)
+++ trunk/tools/quickbook/src/include_paths.cpp	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -81,8 +81,9 @@
         {
             quickbook_path complete_path = location / path;
 
-            if (state.dependencies.add_dependency(complete_path.file_path))
+            if (fs::exists(complete_path.file_path))
             {
+                state.dependencies.add_glob_match(complete_path.file_path);
                 result.insert(complete_path);
             }
             return;
@@ -125,7 +126,9 @@
             {
                 if (fs::is_regular_file(dir_i->status()))
                 {
-                    result.insert(new_location / generic_path);
+                    quickbook_path r = new_location / generic_path;
+                    state.dependencies.add_glob_match(r.file_path);
+                    result.insert(r);
                 }
             }
             // If it's a matching dir, we recurse looking for more files.
@@ -152,6 +155,7 @@
             fs::path current = state.current_file->path.parent_path();
 
             // Search for the current dir accumulating to the result.
+            state.dependencies.add_glob(current / parameter.value);
             include_search_glob(result,
                     quickbook_path(current,
                         state.abstract_file_path.parent_path()),
@@ -160,6 +164,7 @@
             // Search the include path dirs accumulating to the result.
             BOOST_FOREACH(fs::path dir, include_path)
             {
+                state.dependencies.add_glob(dir / parameter.value);
                 include_search_glob(result, quickbook_path(dir, fs::path()),
                         parameter.value, state);
             }
Added: trunk/tools/quickbook/test/python/include_glob.qbk
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tools/quickbook/test/python/include_glob.qbk	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -0,0 +1,11 @@
+[/
+    Copyright 2012-2013 Daniel James
+
+    Distributed under the Boost Software License, Version 1.0.
+    (See accompanying file LICENSE_1_0.txt or copy at
+    http://www.boost.org/LICENSE_1_0.txt)
+]
+
+[quickbook 1.7]
+[article Include Path]
+[include ?.qbk]
Added: trunk/tools/quickbook/test/python/include_glob_deps.txt
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tools/quickbook/test/python/include_glob_deps.txt	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -0,0 +1,6 @@
+# Copyright 2012-2013 Daniel James
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+include_glob.qbk
+sub1/a.qbk
+sub2/b.qbk
Added: trunk/tools/quickbook/test/python/include_glob_locs.txt
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tools/quickbook/test/python/include_glob_locs.txt	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -0,0 +1,9 @@
+# Copyright 2012-2013 Daniel James
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
++ include_glob.qbk
+g ?.qbk
+g sub1/?.qbk
++ sub1/a.qbk
+g sub2/?.qbk
++ sub2/b.qbk
Modified: trunk/tools/quickbook/test/python/output-deps.py
==============================================================================
--- trunk/tools/quickbook/test/python/output-deps.py	Thu Nov 14 14:21:37 2013	(r86702)
+++ trunk/tools/quickbook/test/python/output-deps.py	2013-11-14 14:22:09 EST (Thu, 14 Nov 2013)	(r86703)
@@ -24,6 +24,10 @@
             deps_gold = 'include_path_deps.txt',
             locations_gold = 'include_path_locs.txt',
             input_path = ['sub1', 'sub2'])
+    failures += run_quickbook(quickbook_command, 'include_glob.qbk',
+            deps_gold = 'include_glob_deps.txt',
+            locations_gold = 'include_glob_locs.txt',
+            input_path = ['sub1', 'sub2'])
 
     if failures == 0:
         print "Success"
@@ -123,22 +127,34 @@
     return dependencies
 
 def load_locations(filename, adjust_paths = False):
-    line_matcher = re.compile("^([+-]) (.*)$")
+    line_matcher = re.compile("^([+-g]) (.*)$")
     dependencies = {}
     f = open(filename, 'r')
+    glob = None
+    globs = {}
     for line in f:
         if line[0] == '#': continue
         m = line_matcher.match(line)
-        if not m:
-            raise Exception("Invalid dependency file: %1s" % filename)
-        found = m.group(1) == '+'
+
         path = m.group(2)
         if adjust_paths:
             path = os.path.realpath(path)
-        if path in dependencies:
-            raise Exception("Duplicate path (%1s) in %2s" % (path, filename))
-        dependencies[path] = found
-    return dependencies
+
+        if not m:
+            raise Exception("Invalid dependency file: %1s" % filename)
+        if m.group(1) == 'g':
+            globs[path] = []
+            glob = path
+        elif glob:
+            if m.group(1) != '+':
+                raise Exception("Negative match in glob.")
+            globs[glob].append(path)
+        else:
+            found = m.group(1) == '+'
+            if path in dependencies:
+                raise Exception("Duplicate path (%1s) in %2s" % (path, filename))
+            dependencies[path] = found
+    return { 'dependencies': dependencies, 'globs': globs }
 
 def temp_filename(extension):
     file = tempfile.mkstemp(suffix = extension)