diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-05 11:55:15 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-05 11:55:15 +0200 |
commit | 9fb791e9fad6c63fc1dac49f4d05ae63b8a3db9b (patch) | |
tree | d60322d4382ca5f97b676c5abe2e39524f35eab4 /build2/prerequisite.cxx | |
parent | f159b1dac68c8714f7ba71ca168e3b695891aad9 (diff) |
Rename build directory/namespace to build2
Diffstat (limited to 'build2/prerequisite.cxx')
-rw-r--r-- | build2/prerequisite.cxx | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/build2/prerequisite.cxx b/build2/prerequisite.cxx new file mode 100644 index 0000000..6a31071 --- /dev/null +++ b/build2/prerequisite.cxx @@ -0,0 +1,82 @@ +// file : build2/prerequisite.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <build2/prerequisite> + +#include <ostream> + +#include <build2/scope> +#include <build2/target> // target_type +#include <build2/context> +#include <build2/diagnostics> + +using namespace std; + +namespace build2 +{ + // prerequisite_key + // + ostream& + operator<< (ostream& os, const prerequisite_key& pk) + { + if (pk.proj != nullptr) + os << *pk.proj << '%'; + + // Don't print scope if we are project-qualified or the + // prerequisite's directory is absolute. In both these + // cases the scope is not used to resolve it to target. + // + else if (!pk.tk.dir->absolute ()) + { + string s (diag_relative (pk.scope->out_path (), false)); + + if (!s.empty ()) + os << s << ':'; + } + + return os << pk.tk; + } + + // prerequisite_set + // + auto prerequisite_set:: + insert (const std::string* proj, + const target_type& tt, + dir_path dir, + std::string name, + const std::string* ext, + scope& s, + tracer& trace) -> pair<prerequisite&, bool> + { + //@@ OPT: would be nice to somehow first check if this prerequisite is + // already in the set before allocating a new instance. + + // Find or insert. + // + auto r (emplace (proj, tt, move (dir), move (name), ext, s)); + prerequisite& p (const_cast<prerequisite&> (*r.first)); + + // Update extension if the existing prerequisite has it unspecified. + // + if (p.ext != ext) + { + level5 ([&]{ + diag_record r (trace); + r << "assuming prerequisite " << p << " is the same as the " + << "one with "; + if (ext == nullptr) + r << "unspecified extension"; + else if (ext->empty ()) + r << "no extension"; + else + r << "extension " << *ext; + }); + + if (ext != nullptr) + p.ext = ext; + } + + return pair<prerequisite&, bool> (p, r.second); + } +} |