diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-17 20:35:59 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-21 18:53:32 +0300 |
commit | 375c7c9770c5407af33058170d13d9801a508b30 (patch) | |
tree | 375e54b5c740d32e8ab3f4008706b3681bddf5f4 /libbutl/default-options.cxx | |
parent | 44b929bb1611ce98e926b2f4846565338f344d48 (diff) |
Don't load default options from directories which subdirectory contains --no-default-options
Diffstat (limited to 'libbutl/default-options.cxx')
-rw-r--r-- | libbutl/default-options.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/libbutl/default-options.cxx b/libbutl/default-options.cxx new file mode 100644 index 0000000..69b9c42 --- /dev/null +++ b/libbutl/default-options.cxx @@ -0,0 +1,74 @@ +// file : libbutl/default-options.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef __cpp_modules_ts +#include <libbutl/default-options.mxx> +#endif + +#include <cassert> + +#ifndef __cpp_lib_modules_ts +#include <vector> +#endif + +// Other includes. + +#ifdef __cpp_modules_ts +module butl.default_options; + +// Only imports additional to interface. +#ifdef __clang__ +#ifdef __cpp_lib_modules_ts +import std.core; +#endif +import butl.path; +import butl.optional; +import butl.small_vector; +#endif + +#endif + +using namespace std; + +namespace butl +{ + optional<dir_path> + default_options_start (const optional<dir_path>& home, + const vector<dir_path>& dirs) + { + if (home) + assert (home->absolute () && home->normalized ()); + + if (dirs.empty ()) + return nullopt; + + // Use the first directory as a start. + // + auto i (dirs.begin ()); + dir_path d (*i); + + // Try to find a common prefix for each subsequent directory. + // + for (++i; i != dirs.end (); ++i) + { + bool p (false); + + for (; + !(d.root () || (home && d == *home)); + d = d.directory ()) + { + if (i->sub (d)) + { + p = true; + break; + } + } + + if (!p) + return nullopt; + } + + return d; + } +} |