aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbutl/default-options.ixx16
-rw-r--r--libbutl/default-options.mxx13
-rw-r--r--libbutl/default-options.txx39
-rw-r--r--tests/default-options/driver.cxx8
4 files changed, 52 insertions, 24 deletions
diff --git a/libbutl/default-options.ixx b/libbutl/default-options.ixx
new file mode 100644
index 0000000..e1a3dcf
--- /dev/null
+++ b/libbutl/default-options.ixx
@@ -0,0 +1,16 @@
+// file : libbutl/default-options.ixx -*- C++ -*-
+// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
+{
+ template <typename O>
+ inline O
+ merge_default_options (const default_options<O>& def_ops, const O& cmd_ops)
+ {
+ return merge_default_options (
+ def_ops,
+ cmd_ops,
+ [] (const default_options_entry<O>&, const O&) {});
+ }
+}
diff --git a/libbutl/default-options.mxx b/libbutl/default-options.mxx
index 01d32c1..d7aa70b 100644
--- a/libbutl/default-options.mxx
+++ b/libbutl/default-options.mxx
@@ -7,7 +7,7 @@
#endif
#ifndef __cpp_lib_modules_ts
-#include <utility> // move()
+#include <utility> // move(), forward()
#endif
// Other includes.
@@ -58,6 +58,11 @@ LIBBUTL_MODEXPORT namespace butl
// Search for and load (using scanner S and parsing in the U::fail mode for
// both options and arguments) the specified list of options files in the
// specified directories returning a vector of option class instances (O).
+ // Pass each default options file path to the specified function prior to
+ // load (can be used for tracing, etc). The function signature is:
+ //
+ // void (const path&, bool remote)
+ //
// Throw std::system_error on the underlying OS error and pass through
// exceptions thrown by the options scanner/parser.
//
@@ -80,11 +85,12 @@ LIBBUTL_MODEXPORT namespace butl
// sufficient ground to definititevly conclude that the file is not remote;
// to be sure we would need to query the VCS or some such).
//
- template <typename O, typename S, typename U>
+ template <typename O, typename S, typename U, typename F>
default_options<O>
load_default_options (const optional<dir_path>& sys_dir,
const optional<dir_path>& home_dir,
- const default_options_files&);
+ const default_options_files&,
+ F&&);
// Merge the default options and the command line options.
//
@@ -112,4 +118,5 @@ LIBBUTL_MODEXPORT namespace butl
merge_default_options (const default_options<O>&, const O&, F&&);
}
+#include <libbutl/default-options.ixx>
#include <libbutl/default-options.txx>
diff --git a/libbutl/default-options.txx b/libbutl/default-options.txx
index 42dd585..2ed12e4 100644
--- a/libbutl/default-options.txx
+++ b/libbutl/default-options.txx
@@ -17,14 +17,15 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
// in both the directory itself and its local/ subdirectory are considered
// remote (see load_default_options() for details).
//
- template <typename O, typename S, typename U>
+ template <typename O, typename S, typename U, typename F>
void
load_default_options_files (const dir_path& d,
bool remote,
const small_vector<path, 2>& fs,
+ F&& fn,
default_options<O>& r)
{
- auto load = [&fs, &r] (const dir_path& d, bool remote)
+ auto load = [&fs, &fn, &r] (const dir_path& d, bool remote)
{
using namespace std;
@@ -34,6 +35,8 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
if (file_exists (p)) // Follows symlinks.
{
+ fn (p, remote);
+
S s (p.string ());
// @@ Note that the potentially thrown exceptions (unknown option,
@@ -63,11 +66,12 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
// to the resulting list. Return true if the directory is "remote" (i.e.,
// belongs to a VCS repository).
//
- template <typename O, typename S, typename U>
+ template <typename O, typename S, typename U, typename F>
bool
load_default_options_files (const dir_path& start_dir,
const optional<dir_path>& home_dir,
const small_vector<path, 2>& fs,
+ F&& fn,
default_options<O>& r)
{
if (start_dir.root () || (home_dir && start_dir == *home_dir))
@@ -76,22 +80,28 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
bool remote (load_default_options_files<O, S, U> (start_dir.directory (),
home_dir,
fs,
+ std::forward<F> (fn),
r) ||
git_repository (start_dir));
dir_path d (start_dir / dir_path (".build2"));
if (dir_exists (d))
- load_default_options_files<O, S, U> (d, remote, fs, r);
+ load_default_options_files<O, S, U> (d,
+ remote,
+ fs,
+ std::forward<F> (fn),
+ r);
return remote;
}
- template <typename O, typename S, typename U>
+ template <typename O, typename S, typename U, typename F>
default_options<O>
load_default_options (const optional<dir_path>& sys_dir,
const optional<dir_path>& home_dir,
- const default_options_files& ofs)
+ const default_options_files& ofs,
+ F&& fn)
{
default_options<O> r;
@@ -103,6 +113,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
load_default_options_files<O, S, U> (*sys_dir,
false /* remote */,
ofs.files,
+ std::forward<F> (fn),
r);
}
@@ -116,6 +127,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
load_default_options_files<O, S, U> (d,
false /* remote */,
ofs.files,
+ std::forward<F> (fn),
r);
}
@@ -126,6 +138,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
load_default_options_files<O, S, U> (*ofs.start_dir,
home_dir,
ofs.files,
+ std::forward<F> (fn),
r);
}
@@ -136,7 +149,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
O
merge_default_options (const default_options<O>& def_ops,
const O& cmd_ops,
- F&& f)
+ F&& fn)
{
// Optimize for the common case.
//
@@ -146,21 +159,11 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
O r;
for (const default_options_entry<O>& e: def_ops)
{
- f (e, cmd_ops);
+ fn (e, cmd_ops);
r.merge (e.options);
}
r.merge (cmd_ops);
return r;
}
-
- template <typename O>
- inline O
- merge_default_options (const default_options<O>& def_ops, const O& cmd_ops)
- {
- return merge_default_options (
- def_ops,
- cmd_ops,
- [] (const default_options_entry<O>&, const O&) {});
- }
}
diff --git a/tests/default-options/driver.cxx b/tests/default-options/driver.cxx
index a2ed43d..535df31 100644
--- a/tests/default-options/driver.cxx
+++ b/tests/default-options/driver.cxx
@@ -150,9 +150,11 @@ main (int argc, const char* argv[])
// Load and print the default options.
//
default_options<options> def_ops (
- load_default_options<options, scanner, unknow_mode> (sys_dir,
- home_dir,
- fs));
+ load_default_options<options, scanner, unknow_mode> (
+ sys_dir,
+ home_dir,
+ fs,
+ [] (const path&, bool) {}));
if (print_entries)
{