|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70230 - in trunk/tools/quickbook: src test test/include test/include/sub
From: dnljms_at_[hidden]
Date: 2011-03-20 17:41:20
Author: danieljames
Date: 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
New Revision: 70230
URL: http://svn.boost.org/trac/boost/changeset/70230
Log:
Quickbook: use relative paths in errors and `__FILENAME__`.
This is more consistent than it is at the moment. For the __FILENAME__
macro, use the path relative to the original file or the location last
matched on the include path. This ensures that the macro is consistent
no matter which directory you call quickbook from.
Also enable `__FILENAME__` in debug mode - so I can test this.
Added:
trunk/tools/quickbook/test/include/
trunk/tools/quickbook/test/include/Jamfile.v2 (contents, props changed)
trunk/tools/quickbook/test/include/filename-path.gold (contents, props changed)
trunk/tools/quickbook/test/include/filename-path.quickbook (contents, props changed)
trunk/tools/quickbook/test/include/filename.gold (contents, props changed)
trunk/tools/quickbook/test/include/filename.quickbook (contents, props changed)
trunk/tools/quickbook/test/include/filename_include2.quickbook (contents, props changed)
trunk/tools/quickbook/test/include/sub/
trunk/tools/quickbook/test/include/sub/filename_include1.quickbook (contents, props changed)
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 42 +++++++++++++++++++++++++++------------
trunk/tools/quickbook/src/actions_class.cpp | 10 ++------
trunk/tools/quickbook/src/actions_class.hpp | 3 ++
trunk/tools/quickbook/test/quickbook-testing.jam | 4 ++
4 files changed, 38 insertions(+), 21 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -1573,8 +1573,19 @@
namespace
{
- fs::path include_search(fs::path const & current, std::string const & name)
+ struct include_search_return
{
+ include_search_return(fs::path const& x, fs::path const& y)
+ : filename(x), filename_relative(y) {}
+
+ fs::path filename;
+ fs::path filename_relative;
+ };
+
+ include_search_return include_search(std::string const & name,
+ quickbook::actions const& actions)
+ {
+ fs::path current = actions.filename.parent_path();
fs::path path(name);
// If the path is relative, try and resolve it.
@@ -1583,7 +1594,9 @@
// See if it can be found locally first.
if (fs::exists(current / path))
{
- return current / path;
+ return include_search_return(
+ current / path,
+ actions.filename_relative.parent_path() / path);
}
// Search in each of the include path locations.
@@ -1592,12 +1605,13 @@
full /= path;
if (fs::exists(full))
{
- return full;
+ return include_search_return(full, path);
}
}
}
- return path;
+ return include_search_return(path,
+ actions.filename_relative.parent_path() / path);
}
}
@@ -1606,14 +1620,14 @@
if(!actions.output_pre(actions.out)) return;
value_consumer values = import;
- fs::path path = include_search(actions.filename.parent_path(),
- check_path(values.consume(), actions));
+ include_search_return paths = include_search(
+ check_path(values.consume(), actions), actions);
values.finish();
- std::string ext = path.extension().generic_string();
+ std::string ext = paths.filename.extension().generic_string();
std::vector<template_symbol> storage;
actions.error_count +=
- load_snippets(path.string(), storage, ext, actions.doc_id);
+ load_snippets(paths.filename.string(), storage, ext, actions.doc_id);
BOOST_FOREACH(template_symbol& ts, storage)
{
@@ -1634,14 +1648,15 @@
value_consumer values = include;
value include_doc_id = values.optional_consume(general_tags::include_id);
- fs::path filein = include_search(actions.filename.parent_path(),
- check_path(values.consume(), actions));
+ include_search_return filein = include_search(
+ check_path(values.consume(), actions), actions);
values.finish();
std::string doc_type, doc_id;
// swap the filenames
- std::swap(actions.filename, filein);
+ std::swap(actions.filename, filein.filename);
+ std::swap(actions.filename_relative, filein.filename_relative);
// save the doc info strings and source mode
if(qbk_version_n >= 106) {
@@ -1670,7 +1685,7 @@
// update the __FILENAME__ macro
*boost::spirit::classic::find(actions.macro, "__FILENAME__")
- = detail::path_to_generic(actions.filename);
+ = detail::path_to_generic(actions.filename_relative);
// save values
actions.values.builder.save();
@@ -1681,7 +1696,8 @@
// restore the values
actions.values.builder.restore();
- std::swap(actions.filename, filein);
+ std::swap(actions.filename, filein.filename);
+ std::swap(actions.filename_relative, filein.filename_relative);
actions.doc_type.swap(doc_type);
actions.doc_id.swap(doc_id);
Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp (original)
+++ trunk/tools/quickbook/src/actions_class.cpp 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -45,7 +45,8 @@
, scoped_context(*this)
// state
- , filename(fs::absolute(filein_))
+ , filename(filein_)
+ , filename_relative(filein_.filename())
, xinclude_base(xinclude_base_)
, macro_change_depth(0)
, macro()
@@ -90,16 +91,11 @@
, output_pre(*this)
{
- // turn off __FILENAME__ macro on debug mode = true
- std::string filename_str = debug_mode ?
- std::string("NO_FILENAME_MACRO_GENERATED_IN_DEBUG_MODE") :
- detail::path_to_generic(filename);
-
// add the predefined macros
macro.add
("__DATE__", std::string(quickbook_get_date))
("__TIME__", std::string(quickbook_get_time))
- ("__FILENAME__", filename_str)
+ ("__FILENAME__", detail::path_to_generic(filename_relative))
;
boost::scoped_ptr<quickbook_grammar> g(
Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp (original)
+++ trunk/tools/quickbook/src/actions_class.hpp 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -65,6 +65,9 @@
// state
fs::path filename;
+ fs::path filename_relative; // for the __FILENAME__ macro.
+ // (relative to the original file
+ // or include path).
fs::path xinclude_base;
std::size_t macro_change_depth;
string_symbols macro;
Added: trunk/tools/quickbook/test/include/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/Jamfile.v2 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2011 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)
+#
+
+project test/includes
+ : requirements
+ <toolset>msvc:<debug-symbols>off
+ ;
+
+import quickbook-testing : quickbook-test quickbook-error-test ;
+
+test-suite quickbook.test :
+ [ quickbook-test filename ]
+ [ quickbook-test filename-path : : : <quickbook-test-include>sub ]
+ ;
\ No newline at end of file
Added: trunk/tools/quickbook/test/include/filename-path.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/filename-path.gold 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="filename_test_with_include_path" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Filename test with include path</title>
+ <para>
+ filename-path.quickbook
+ </para>
+ <para>
+ filename_include1.quickbook
+ </para>
+ <para>
+ ../filename_include2.quickbook
+ </para>
+ <para>
+ filename_include2.quickbook
+ </para>
+</article>
Added: trunk/tools/quickbook/test/include/filename-path.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/filename-path.quickbook 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,9 @@
+[article Filename test with include path
+[quickbook 1.5]
+]
+
+__FILENAME__
+
+[include filename_include1.quickbook]
+
+[include filename_include2.quickbook]
\ No newline at end of file
Added: trunk/tools/quickbook/test/include/filename.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/filename.gold 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="filename_test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Filename Test</title>
+ <para>
+ filename.quickbook
+ </para>
+ <para>
+ sub/filename_include1.quickbook
+ </para>
+ <para>
+ sub/../filename_include2.quickbook
+ </para>
+ <para>
+ filename_include2.quickbook
+ </para>
+</article>
Added: trunk/tools/quickbook/test/include/filename.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/filename.quickbook 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,9 @@
+[article Filename Test
+[quickbook 1.5]
+]
+
+__FILENAME__
+
+[include sub/filename_include1.quickbook]
+
+[include filename_include2.quickbook]
Added: trunk/tools/quickbook/test/include/filename_include2.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/filename_include2.quickbook 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1 @@
+__FILENAME__
\ No newline at end of file
Added: trunk/tools/quickbook/test/include/sub/filename_include1.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/include/sub/filename_include1.quickbook 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,3 @@
+__FILENAME__
+
+[include ../filename_include2.quickbook]
\ No newline at end of file
Modified: trunk/tools/quickbook/test/quickbook-testing.jam
==============================================================================
--- trunk/tools/quickbook/test/quickbook-testing.jam (original)
+++ trunk/tools/quickbook/test/quickbook-testing.jam 2011-03-20 17:41:18 EDT (Sun, 20 Mar 2011)
@@ -17,6 +17,7 @@
feature.feature quickbook-testing.quickbook-command : : free dependency ;
feature.feature <quickbook-test-define> : : free ;
+feature.feature <quickbook-test-include> : : free path ;
feature.feature <quickbook-xinclude-base> : : free ;
type.register QUICKBOOK_INPUT : quickbook ;
@@ -126,6 +127,7 @@
toolset.flags quickbook-testing.process-quickbook quickbook-command <quickbook-testing.quickbook-command> ;
toolset.flags quickbook-testing.process-quickbook QB-DEFINES <quickbook-test-define> ;
toolset.flags quickbook-testing.process-quickbook XINCLUDE <quickbook-xinclude-base> ;
+toolset.flags quickbook-testing.process-quickbook INCLUDES <quickbook-test-include> ;
rule process-quickbook ( target : source : properties * )
{
@@ -134,6 +136,6 @@
actions process-quickbook bind quickbook-command
{
- $(quickbook-command) $(>) --output-file=$(<) --debug -D"$(QB-DEFINES)" --xinclude-base=$(XINCLUDE)
+ $(quickbook-command) $(>) --output-file=$(<) --debug -D"$(QB-DEFINES)" -I"$(INCLUDES)" --xinclude-base="$(XINCLUDE)"
}
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