Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86708 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-11-14 15:00:24


Author: danieljames
Date: 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013)
New Revision: 86708
URL: http://svn.boost.org/trac/boost/changeset/86708

Log:
Make include file order more consistent on different machines.

Sometimes when including files on the path the same glob will match the
same relative path from different include paths. In this case the paths
were ordered by their absolute paths. Instead use the order they occur
in the include path, which is a little more independent of the local
machine.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 2
   trunk/tools/quickbook/src/include_paths.cpp | 54 +++++++++++++++++++++++++++------------
   trunk/tools/quickbook/src/include_paths.hpp | 20 ++++++++++----
   trunk/tools/quickbook/src/state.cpp | 9 +++--
   trunk/tools/quickbook/src/state.hpp | 6 +--
   trunk/tools/quickbook/src/state_save.hpp | 2
   6 files changed, 60 insertions(+), 33 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Thu Nov 14 14:24:34 2013 (r86707)
+++ trunk/tools/quickbook/src/actions.cpp 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013) (r86708)
@@ -1942,7 +1942,7 @@
                 state_save::scope_macros);
 
             state.current_file = load(path.file_path); // Throws load_error
- state.abstract_file_path = path.abstract_file_path;
+ state.current_path = path;
             state.imported = (load_type == block_tags::import);
 
             // update the __FILENAME__ macro

Modified: trunk/tools/quickbook/src/include_paths.cpp
==============================================================================
--- trunk/tools/quickbook/src/include_paths.cpp Thu Nov 14 14:24:34 2013 (r86707)
+++ trunk/tools/quickbook/src/include_paths.cpp 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013) (r86708)
@@ -172,16 +172,17 @@
 
                 // 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()),
+ include_search_glob(result, state.current_path.parent_path(),
                         parameter.value, state);
 
                 // Search the include path dirs accumulating to the result.
+ unsigned count = 0;
                 BOOST_FOREACH(fs::path dir, include_path)
                 {
+ ++count;
                     state.dependencies.add_glob(dir / parameter.value);
- include_search_glob(result, quickbook_path(dir, fs::path()),
+ include_search_glob(result,
+ quickbook_path(dir, count, fs::path()),
                             parameter.value, state);
                 }
 
@@ -196,26 +197,26 @@
                 // If the path is relative, try and resolve it.
                 if (!path.has_root_directory() && !path.has_root_name())
                 {
- fs::path local_path =
- state.current_file->path.parent_path() / path;
+ quickbook_path path2 =
+ state.current_path.parent_path() / parameter.value;
 
                     // See if it can be found locally first.
- if (state.dependencies.add_dependency(local_path))
+ if (state.dependencies.add_dependency(path2.file_path))
                     {
- result.insert(quickbook_path(
- local_path,
- state.abstract_file_path.parent_path() / path));
+ result.insert(path2);
                         return result;
                     }
 
                     // Search in each of the include path locations.
+ unsigned count = 0;
                     BOOST_FOREACH(fs::path full, include_path)
                     {
+ ++count;
                         full /= path;
 
                         if (state.dependencies.add_dependency(full))
                         {
- result.insert(quickbook_path(full, path));
+ result.insert(quickbook_path(full, count, path));
                             return result;
                         }
                     }
@@ -223,7 +224,7 @@
                 else
                 {
                     if (state.dependencies.add_dependency(path)) {
- result.insert(quickbook_path(path, path));
+ result.insert(quickbook_path(path, 0, path));
                         return result;
                     }
                 }
@@ -250,11 +251,23 @@
     // quickbook_path
     //
 
+ void swap(quickbook_path& x, quickbook_path& y) {
+ boost::swap(x.file_path, y.file_path);
+ boost::swap(x.include_path_offset, y.include_path_offset);
+ boost::swap(x.abstract_file_path, y.abstract_file_path);
+ }
+
     bool quickbook_path::operator<(quickbook_path const& other) const
     {
- if (abstract_file_path < other.abstract_file_path) return true;
- else if (other.abstract_file_path < abstract_file_path) return false;
- else return file_path < other.file_path;
+ // TODO: Is comparing file_path redundant? Surely if quickbook_path
+ // and abstract_file_path are equal, it must also be.
+ // (but not vice-versa)
+ return
+ abstract_file_path != other.abstract_file_path ?
+ abstract_file_path < other.abstract_file_path :
+ include_path_offset != other.include_path_offset ?
+ include_path_offset < other.include_path_offset :
+ file_path < other.file_path;
     }
 
     quickbook_path quickbook_path::operator/(boost::string_ref x) const
@@ -264,8 +277,15 @@
 
     quickbook_path& quickbook_path::operator/=(boost::string_ref x)
     {
- file_path.append(x.begin(), x.end());
- abstract_file_path.append(x.begin(), x.end());
+ fs::path x2 = detail::generic_to_path(x);
+ file_path /= x2;
+ abstract_file_path /= x2;
         return *this;
     }
+
+ quickbook_path quickbook_path::parent_path() const
+ {
+ return quickbook_path(file_path.parent_path(), include_path_offset,
+ abstract_file_path.parent_path());
+ }
 }

Modified: trunk/tools/quickbook/src/include_paths.hpp
==============================================================================
--- trunk/tools/quickbook/src/include_paths.hpp Thu Nov 14 14:24:34 2013 (r86707)
+++ trunk/tools/quickbook/src/include_paths.hpp 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013) (r86708)
@@ -38,19 +38,27 @@
 
     struct quickbook_path
     {
- quickbook_path(fs::path const& x, fs::path const& y)
- : file_path(x), abstract_file_path(y) {}
+ quickbook_path(fs::path const& x, unsigned offset, fs::path const& y)
+ : file_path(x), include_path_offset(offset), abstract_file_path(y) {}
+
+ friend void swap(quickbook_path&, quickbook_path&);
+
+ quickbook_path parent_path() const;
+
+ bool operator<(quickbook_path const& other) const;
+ quickbook_path operator/(boost::string_ref) const;
+ quickbook_path& operator/=(boost::string_ref);
 
         // The actual location of the file.
         fs::path file_path;
 
+ // The member of the include path that this file is relative to.
+ // (1-indexed, 0 == original quickbook file)
+ unsigned include_path_offset;
+
         // A machine independent representation of the file's
         // path - not unique per-file
         fs::path abstract_file_path;
-
- bool operator<(quickbook_path const& other) const;
- quickbook_path operator/(boost::string_ref) const;
- quickbook_path& operator/=(boost::string_ref);
     };
 
     std::set<quickbook_path> include_search(path_parameter const&,

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Thu Nov 14 14:24:34 2013 (r86707)
+++ trunk/tools/quickbook/src/state.cpp 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013) (r86708)
@@ -53,7 +53,7 @@
         , source_mode_next()
         , source_mode_next_pos()
         , current_file(0)
- , abstract_file_path(filein_.filename())
+ , current_path(filein_, 0, filein_.filename())
 
         , template_depth(0)
         , min_section_level(1)
@@ -84,7 +84,8 @@
 
     void state::update_filename_macro() {
         *boost::spirit::classic::find(macro, "__FILENAME__")
- = detail::encode_string(detail::path_to_generic(abstract_file_path));
+ = detail::encode_string(
+ detail::path_to_generic(current_path.abstract_file_path));
     }
     
     unsigned state::get_new_order_pos() {
@@ -146,7 +147,7 @@
         , qbk_version(qbk_version_n)
         , imported(state.imported)
         , current_file(state.current_file)
- , abstract_file_path(state.abstract_file_path)
+ , current_path(state.current_path)
         , xinclude_base(state.xinclude_base)
         , source_mode(state.source_mode)
         , macro()
@@ -167,7 +168,7 @@
         boost::swap(qbk_version_n, qbk_version);
         boost::swap(state.imported, imported);
         boost::swap(state.current_file, current_file);
- boost::swap(state.abstract_file_path, abstract_file_path);
+ boost::swap(state.current_path, current_path);
         boost::swap(state.xinclude_base, xinclude_base);
         boost::swap(state.source_mode, source_mode);
         if (scope & scope_output) {

Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp Thu Nov 14 14:24:34 2013 (r86707)
+++ trunk/tools/quickbook/src/state.hpp 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013) (r86708)
@@ -19,6 +19,7 @@
 #include "symbols.hpp"
 #include "dependency_tracker.hpp"
 #include "syntax_highlight.hpp"
+#include "include_paths.hpp"
 
 namespace quickbook
 {
@@ -65,10 +66,7 @@
         std::vector<source_mode_info>
                                 tagged_source_mode_stack;
         file_ptr current_file;
-
- // A machine independent representation of the current file's
- // path - not unique per-file.
- fs::path abstract_file_path;
+ quickbook_path current_path;
 
     // state saved for templates.
         int template_depth;

Modified: trunk/tools/quickbook/src/state_save.hpp
==============================================================================
--- trunk/tools/quickbook/src/state_save.hpp Thu Nov 14 14:24:34 2013 (r86707)
+++ trunk/tools/quickbook/src/state_save.hpp 2013-11-14 15:00:24 EST (Thu, 14 Nov 2013) (r86708)
@@ -38,7 +38,7 @@
         bool imported;
         std::string doc_type;
         file_ptr current_file;
- fs::path abstract_file_path;
+ quickbook_path current_path;
         fs::path xinclude_base;
         source_mode_info source_mode;
         string_symbols macro;


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