Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77442 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2012-03-20 19:43:33


Author: danieljames
Date: 2012-03-20 19:43:33 EDT (Tue, 20 Mar 2012)
New Revision: 77442
URL: http://svn.boost.org/trac/boost/changeset/77442

Log:
Quickbook: Rough stab at outputting dependencies. Refs #6691

Adds `--output-deps` flag. To write out dependencies to `deps.txt`:
{{{
quickbook --output-deps deps.txt source.qbk
}}}

If `--output-deps` is specified, quickbook won't generate an output file
unless one is specified with `--output-file`. If there is an error it
will return an error code, but it will still write out all the opened
files.

Known issues:
- If the same file is included/imported twice it may or may not list it
  twice. Should be consistent.
- Doesn't include SVG files. It probably should as they can affect the
  output.
- Need to check some of the path issues for things such as xinclude
  paths which depend on the output file path.
- Needs tests and documentation.
Text files modified:
   trunk/tools/quickbook/src/files.cpp | 14 ++++++++++++++
   trunk/tools/quickbook/src/files.hpp | 2 ++
   trunk/tools/quickbook/src/quickbook.cpp | 33 +++++++++++++++++++++++++++------
   3 files changed, 43 insertions(+), 6 deletions(-)

Modified: trunk/tools/quickbook/src/files.cpp
==============================================================================
--- trunk/tools/quickbook/src/files.cpp (original)
+++ trunk/tools/quickbook/src/files.cpp 2012-03-20 19:43:33 EDT (Tue, 20 Mar 2012)
@@ -12,6 +12,7 @@
 #include <boost/unordered_map.hpp>
 #include <boost/range/algorithm/upper_bound.hpp>
 #include <boost/range/algorithm/transform.hpp>
+#include <boost/foreach.hpp>
 #include <fstream>
 #include <iterator>
 
@@ -134,6 +135,19 @@
         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-20 19:43:33 EDT (Tue, 20 Mar 2012)
@@ -16,6 +16,7 @@
 #include <boost/intrusive_ptr.hpp>
 #include <stdexcept>
 #include <cassert>
+#include <vector>
 #include "intrusive_base.hpp"
 
 namespace quickbook {
@@ -75,6 +76,7 @@
     // 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-20 19:43:33 EDT (Tue, 20 Mar 2012)
@@ -23,6 +23,7 @@
 #include <boost/range/algorithm.hpp>
 #include <boost/ref.hpp>
 #include <boost/version.hpp>
+#include <boost/foreach.hpp>
 
 #include <stdexcept>
 #include <vector>
@@ -113,6 +114,7 @@
     parse_document(
         fs::path const& filein_
       , fs::path const& fileout_
+ , fs::path const& deps_out_
       , fs::path const& xinclude_base_
       , int indent
       , int linewidth
@@ -145,7 +147,14 @@
             result = 1;
         }
 
- if (result == 0)
+ 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());
 
@@ -245,6 +254,7 @@
             ("linewidth", PO_VALUE<int>(), "line width")
             ("input-file", PO_VALUE<input_string>(), "input file")
             ("output-file", PO_VALUE<input_string>(), "output file")
+ ("output-deps", PO_VALUE<input_string>(), "output dependency file")
             ("debug", "debug mode (for developers)")
             ("ms-errors", "use Microsoft Visual Studio style error & warn message format")
             ("include-path,I", PO_VALUE< std::vector<input_string> >(), "include path")
@@ -388,17 +398,24 @@
             fs::path filein = quickbook::detail::input_to_path(
                 vm["input-file"].as<input_string>());
             fs::path fileout;
+ fs::path depsout;
 
             if (vm.count("output-file"))
             {
                 fileout = quickbook::detail::input_to_path(
                     vm["output-file"].as<input_string>());
             }
- else
+ else if (!vm.count("output-deps"))
             {
                 fileout = filein;
                 fileout.replace_extension(".xml");
             }
+
+ if (vm.count("output-deps"))
+ {
+ depsout = quickbook::detail::input_to_path(
+ vm["output-deps"].as<input_string>());
+ }
             
             fs::path xinclude_base;
             if (vm.count("xinclude-base"))
@@ -432,12 +449,16 @@
                 quickbook::image_location = filein.parent_path() / "html";
             }
 
- quickbook::detail::out() << "Generating Output File: "
- << fileout
- << std::endl;
+ if (!fileout.empty()) {
+ quickbook::detail::out() << "Generating Output File: "
+ << fileout
+ << std::endl;
+ }
 
             if (!error_count)
- error_count += quickbook::parse_document(filein, fileout, xinclude_base, indent, linewidth, pretty_print);
+ error_count += quickbook::parse_document(
+ filein, fileout, depsout, xinclude_base,
+ indent, linewidth, pretty_print);
 
             if (expect_errors)
             {


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