Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77490 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2012-03-22 19:19:31


Author: danieljames
Date: 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
New Revision: 77490
URL: http://svn.boost.org/trac/boost/changeset/77490

Log:
Quickbook: Track dependencies in state. Refs #6691

- Use cananoical filenames where possible.
- Remove duplicates.
- Include SVG files.
- Less hacky.
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 3 +++
   trunk/tools/quickbook/src/files.cpp | 13 -------------
   trunk/tools/quickbook/src/files.hpp | 2 --
   trunk/tools/quickbook/src/quickbook.cpp | 16 +++++++++-------
   trunk/tools/quickbook/src/state.cpp | 8 ++++++++
   trunk/tools/quickbook/src/state.hpp | 6 ++++++
   6 files changed, 26 insertions(+), 22 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
@@ -936,6 +936,7 @@
            //
            // Now load the SVG file:
            //
+ state.add_loaded_file(img);
            std::string svg_text;
            fs::ifstream fs(img);
            char c;
@@ -1920,6 +1921,7 @@
                 qbk_version_n >= 106u ? file_state::scope_callables :
                 file_state::scope_macros);
 
+ state.add_loaded_file(paths.filename);
             state.current_file = load(paths.filename); // Throws load_error
             state.filename_relative = paths.filename_relative;
             state.imported = (load_type == block_tags::import);
@@ -1951,6 +1953,7 @@
 
         std::string ext = paths.filename.extension().generic_string();
         std::vector<template_symbol> storage;
+ state.add_loaded_file(paths.filename);
         // Throws load_error
         state.error_count +=
             load_snippets(paths.filename, storage, ext, load_type);

Modified: trunk/tools/quickbook/src/files.cpp
==============================================================================
--- trunk/tools/quickbook/src/files.cpp (original)
+++ trunk/tools/quickbook/src/files.cpp 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
@@ -135,19 +135,6 @@
         return pos->second;
     }
 
- std::vector<fs::path> loaded_files()
- {
- std::vector<fs::path> file_list;
- typedef std::pair<fs::path const, file_ptr> pair;
-
- BOOST_FOREACH(pair const& p, files)
- {
- file_list.push_back(p.first);
- }
-
- return file_list;
- }
-
     file_position relative_position(
         std::string::const_iterator begin,
         std::string::const_iterator iterator)

Modified: trunk/tools/quickbook/src/files.hpp
==============================================================================
--- trunk/tools/quickbook/src/files.hpp (original)
+++ trunk/tools/quickbook/src/files.hpp 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
@@ -16,7 +16,6 @@
 #include <boost/intrusive_ptr.hpp>
 #include <stdexcept>
 #include <cassert>
-#include <vector>
 #include "intrusive_base.hpp"
 
 namespace quickbook {
@@ -76,7 +75,6 @@
     // If version isn't supplied then it must be set later.
     file_ptr load(fs::path const& filename,
         unsigned qbk_version = 0);
- std::vector<fs::path> loaded_files();
 
     struct load_error : std::runtime_error
     {

Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
@@ -130,6 +130,7 @@
             set_macros(state);
 
             if (state.error_count == 0) {
+ state.add_loaded_file(filein_);
                 state.current_file = load(filein_); // Throws load_error
 
                 parse_file(state);
@@ -141,19 +142,20 @@
             }
 
             result = state.error_count ? 1 : 0;
+
+ if (!deps_out_.empty())
+ {
+ fs::ofstream deps_out(deps_out_);
+ BOOST_FOREACH(fs::path const& f, state.loaded_files)
+ deps_out << detail::path_to_generic(f) << std::endl;
+ }
+
         }
         catch (load_error& e) {
             detail::outerr(filein_) << e.what() << std::endl;
             result = 1;
         }
 
- if (!deps_out_.empty())
- {
- fs::ofstream deps_out(deps_out_);
- BOOST_FOREACH(fs::path const& f, loaded_files())
- deps_out << detail::path_to_generic(fs::absolute(f)) << std::endl;
- }
-
         if (!fileout_.empty() && result == 0)
         {
             std::string stage2 = ids.replace_placeholders(buffer.str());

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp (original)
+++ trunk/tools/quickbook/src/state.cpp 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
@@ -13,6 +13,7 @@
 #include "quickbook.hpp"
 #include "grammar.hpp"
 #include "input_path.hpp"
+#include <boost/filesystem/operations.hpp>
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
 #pragma warning(disable:4355)
@@ -70,6 +71,13 @@
         return *grammar_;
     }
 
+ void state::add_loaded_file(fs::path const& f) {
+ boost::system::error_code ec;
+ fs::path p = fs::canonical(f, ec);
+ if (ec) p = fs::absolute(f);
+ loaded_files.insert(p);
+ }
+
     file_state::file_state(quickbook::state& state, scope_flags scope)
         : state(state)
         , scope(scope)

Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp (original)
+++ trunk/tools/quickbook/src/state.hpp 2012-03-22 19:19:30 EDT (Thu, 22 Mar 2012)
@@ -10,6 +10,7 @@
 #if !defined(BOOST_SPIRIT_ACTIONS_CLASS_HPP)
 #define BOOST_SPIRIT_ACTIONS_CLASS_HPP
 
+#include <set>
 #include <boost/scoped_ptr.hpp>
 #include "parsers.hpp"
 #include "values_parse.hpp"
@@ -49,6 +50,7 @@
         id_manager& ids;
         value_builder callouts; // callouts are global as
         int callout_depth; // they don't nest.
+ std::set<fs::path> loaded_files;
 
     // state saved for files and templates.
         bool imported;
@@ -75,6 +77,10 @@
     // actions
     ///////////////////////////////////////////////////////////////////////////
 
+ // Call this before loading any file so that it will be included in the
+ // list of dependencies.
+ void add_loaded_file(fs::path const&);
+
         void start_list(char mark);
         void end_list(char mark);
         void start_list_item();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk