diff options
-rw-r--r-- | build2/buildfile | 2 | ||||
-rw-r--r-- | build2/context | 32 | ||||
-rw-r--r-- | build2/context.cxx | 53 | ||||
-rw-r--r-- | build2/context.txx | 44 | ||||
-rw-r--r-- | build2/scope.cxx | 3 | ||||
-rw-r--r-- | build2/utility | 30 | ||||
-rw-r--r-- | build2/utility.cxx | 55 | ||||
-rw-r--r-- | build2/utility.txx | 25 | ||||
-rw-r--r-- | build2/variable | 5 | ||||
-rw-r--r-- | build2/variable.cxx | 5 |
10 files changed, 122 insertions, 132 deletions
diff --git a/build2/buildfile b/build2/buildfile index 8dc6a14..9c15468 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -8,7 +8,7 @@ exe{b}: \ {hxx ixx cxx}{ algorithm } \ { cxx}{ b } \ {hxx ixx cxx}{ b-options } \ - {hxx txx cxx}{ context } \ + {hxx cxx}{ context } \ {hxx cxx}{ depdb } \ {hxx cxx}{ diagnostics } \ {hxx cxx}{ dump } \ diff --git a/build2/context b/build2/context index 257e96b..9b0af8a 100644 --- a/build2/context +++ b/build2/context @@ -17,8 +17,6 @@ namespace build2 { class file; - extern dir_path work; - extern dir_path home; extern options ops; extern string_pool extension_pool; @@ -75,6 +73,10 @@ namespace build2 using variable_overrides = vector<variable_override>; + // Variable override value cache. + // + extern variable_override_cache var_override_cache; + // Reset the build state. In particular, this removes all the targets, // scopes, and variables. // @@ -107,30 +109,6 @@ namespace build2 out_src (const dir_path& src, const dir_path& out_root, const dir_path& src_root); - // If possible and beneficial, translate an absolute, normalized path - // into relative to the relative_base directory, which is normally - // work. Note that if the passed path is the same as relative_base, - // then this function returns empty path. - // - template <typename K> - basic_path<char, K> - relative (const basic_path<char, K>&); - - // By default this points to work. Setting this to something else - // should only be done in tightly controlled, non-parallel - // situations (see dump). If base is empty, then relative() - // returns the original path. - // - extern const dir_path* relative_base; - - // In addition to calling relative(), this function also uses shorter - // notations such as '~/'. For directories the result includes the trailing - // slash. If the path is the same as base, returns "./" if current is true - // and empty string otherwise. - // - string - diag_relative (const path&, bool current = true); - // Action phrases, e.g., "configure update exe{foo}", "updating exe{foo}", // and "updating exe{foo} is configured". Use like this: // @@ -180,6 +158,4 @@ namespace build2 } } -#include <build2/context.txx> - #endif // BUILD2_CONTEXT diff --git a/build2/context.cxx b/build2/context.cxx index d1d9b54..1527cc8 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -25,8 +25,6 @@ using namespace butl; namespace build2 { - dir_path work; - dir_path home; options ops; string_pool extension_pool; @@ -43,6 +41,8 @@ namespace build2 uint64_t dependency_count; + variable_override_cache var_override_cache; + variable_overrides reset (const strings& cmd_vars) { @@ -55,7 +55,7 @@ namespace build2 variable_overrides vos; - variable_override_cache.clear (); + var_override_cache.clear (); targets.clear (); scopes.clear (); @@ -362,53 +362,6 @@ namespace build2 return out_root / s.leaf (src_root); } - // relative() - // - const dir_path* relative_base = &work; - - string - diag_relative (const path& p, bool cur) - { - if (p.string () == "-") - return "<stdin>"; - - const path& b (*relative_base); - - if (p.absolute ()) - { - if (p == b) - return cur ? "." + p.separator_string () : string (); - -#ifndef _WIN32 - if (p == home) - return "~" + p.separator_string (); -#endif - - path rb (relative (p)); - -#ifndef _WIN32 - if (rb.relative ()) - { - // See if the original path with the ~/ shortcut is better - // that the relative to base. - // - if (p.sub (home)) - { - path rh (p.leaf (home)); - if (rb.size () > rh.size () + 2) // 2 for '~/' - return "~/" + move (rh).representation (); - } - } - else if (rb.sub (home)) - return "~/" + rb.leaf (home).representation (); -#endif - - return move (rb).representation (); - } - - return p.representation (); - } - // diag_do(), etc. // void diff --git a/build2/context.txx b/build2/context.txx deleted file mode 100644 index f40ecdc..0000000 --- a/build2/context.txx +++ /dev/null @@ -1,44 +0,0 @@ -// file : build2/context.txx -*- C++ -*- -// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -namespace build2 -{ - template <typename K> - basic_path<char, K> - relative (const basic_path<char, K>& p) - { - typedef basic_path<char, K> path; - - const dir_path& b (*relative_base); - - if (p.simple () || b.empty ()) - return p; - - if (p.sub (b)) - return p.leaf (b); - - // If base is a sub-path of {src,out}_root and this path is also a - // sub-path of it, then use '..' to form a relative path. - // - // Don't think this is a good heuristic. For example, why shouldn't - // we display paths from imported projects as relative if they are - // more readable than absolute? - // - /* - if ((work.sub (src_root) && p.sub (src_root)) || - (work.sub (out_root) && p.sub (out_root))) - return p.relative (work); - */ - - if (p.root_directory () == b.root_directory ()) - { - path r (p.relative (b)); - - if (r.string ().size () < p.string ().size ()) - return r; - } - - return p; - } -} diff --git a/build2/scope.cxx b/build2/scope.cxx index 7a16715..2ca382b 100644 --- a/build2/scope.cxx +++ b/build2/scope.cxx @@ -5,6 +5,7 @@ #include <build2/scope> #include <build2/target> +#include <build2/context> using namespace std; @@ -331,7 +332,7 @@ namespace build2 // @@ MT // variable_override_value& cache ( - variable_override_cache[make_pair (inner_vars, &var)]); + var_override_cache[make_pair (inner_vars, &var)]); // Now find our "stem", that is the value to which we will be appending // suffixes and prepending prefixes. This is either the original or the diff --git a/build2/utility b/build2/utility index 396c79e..99e79cc 100644 --- a/build2/utility +++ b/build2/utility @@ -80,6 +80,36 @@ namespace build2 next_word (const string&, size_t n, size_t& b, size_t& e, char d1 = ' ', char d2 = '\0'); + // Work/home directories (must be initialized in main()) and relative path + // calculation. + // + extern dir_path work; + extern dir_path home; + + // By default this points to work. Setting this to something else should + // only be done in tightly controlled, non-concurrent situations (e.g., + // state dump). If it is empty, then relative() below returns the original + // path. + // + extern const dir_path* relative_base; + + // If possible and beneficial, translate an absolute, normalized path into + // relative to the relative_base directory, which is normally work. Note + // that if the passed path is the same as relative_base, then this function + // returns empty path. + // + template <typename K> + basic_path<char, K> + relative (const basic_path<char, K>&); + + // In addition to calling relative(), this function also uses shorter + // notations such as '~/'. For directories the result includes the trailing + // slash. If the path is the same as base, returns "./" if current is true + // and empty string otherwise. + // + string + diag_relative (const path&, bool current = true); + // Basic process utilities. // diff --git a/build2/utility.cxx b/build2/utility.cxx index 1383729..43a5370 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -8,7 +8,6 @@ #include <cstdlib> // strtol() #include <iostream> // cerr -#include <build2/context> #include <build2/variable> #include <build2/diagnostics> @@ -85,6 +84,60 @@ namespace build2 return l; } + dir_path work; + dir_path home; + const dir_path* relative_base = &work; + + string + diag_relative (const path& p, bool cur) + { + if (p.string () == "-") + return "<stdin>"; + + const path& b (*relative_base); + + if (p.absolute ()) + { + if (p == b) + return cur ? "." + p.separator_string () : string (); + +#ifndef _WIN32 + if (!home.empty ()) + { + if (p == home) + return "~" + p.separator_string (); + } +#endif + + path rb (relative (p)); + +#ifndef _WIN32 + if (!home.empty ()) + { + if (rb.relative ()) + { + // See if the original path with the ~/ shortcut is better that the + // relative to base. + // + if (p.sub (home)) + { + path rh (p.leaf (home)); + if (rb.size () > rh.size () + 2) // 2 for '~/' + return "~/" + move (rh).representation (); + } + } + else if (rb.sub (home)) + return "~/" + rb.leaf (home).representation (); + } + +#endif + + return move (rb).representation (); + } + + return p.representation (); + } + process_path run_search (const char*& args0) try diff --git a/build2/utility.txx b/build2/utility.txx index 1c710ee..bba66d6 100644 --- a/build2/utility.txx +++ b/build2/utility.txx @@ -4,6 +4,31 @@ namespace build2 { + template <typename K> + basic_path<char, K> + relative (const basic_path<char, K>& p) + { + typedef basic_path<char, K> path; + + const dir_path& b (*relative_base); + + if (p.simple () || b.empty ()) + return p; + + if (p.sub (b)) + return p.leaf (b); + + if (p.root_directory () == b.root_directory ()) + { + path r (p.relative (b)); + + if (r.string ().size () < p.string ().size ()) + return r; + } + + return p; + } + template <typename T> T run (const process_path& pp, diff --git a/build2/variable b/build2/variable index 326c290..6bdc728 100644 --- a/build2/variable +++ b/build2/variable @@ -930,8 +930,9 @@ namespace build2 const variable_map* stem_vars = nullptr; // NULL means there is no stem. }; - extern std::map<pair<const variable_map*, const variable*>, - variable_override_value> variable_override_cache; + using variable_override_cache = std::map<pair<const variable_map*, + const variable*>, + variable_override_value>; } #include <build2/variable.ixx> diff --git a/build2/variable.cxx b/build2/variable.cxx index cf274be..3fc9835 100644 --- a/build2/variable.cxx +++ b/build2/variable.cxx @@ -935,9 +935,4 @@ namespace build2 return lookup (); } - - // variable_override - // - map<pair<const variable_map*, const variable*>, variable_override_value> - variable_override_cache; } |