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/target.txx | |
parent | f159b1dac68c8714f7ba71ca168e3b695891aad9 (diff) |
Rename build directory/namespace to build2
Diffstat (limited to 'build2/target.txx')
-rw-r--r-- | build2/target.txx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/build2/target.txx b/build2/target.txx new file mode 100644 index 0000000..3209720 --- /dev/null +++ b/build2/target.txx @@ -0,0 +1,58 @@ +// file : build2/target.txx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <build2/scope> +#include <build2/context> // extension_pool +#include <build2/diagnostics> +#include <build2/prerequisite> + +namespace build2 +{ + template <const char* ext> + const string& + target_extension_fix (const target_key&, scope&) + { + return extension_pool.find (ext); + } + + template <const char* var, const char* def> + const string& + target_extension_var (const target_key& tk, scope& s) + { + // Include target type/pattern-specific variables. + // + if (auto l = s.lookup (tk, var)) + { + // Help the user here and strip leading '.' from the extension. + // + const string& e (as<string> (*l)); + return extension_pool.find ( + !e.empty () && e.front () == '.' ? string (e, 1) : e); + } + + if (def != nullptr) + return extension_pool.find (def); + + { + diag_record dr; + dr << error << "no default extension in variable '" << var << "'" + << info << "required to derive file name for "; + + // This is a bit hacky: we may be dealing with a target (see + // file::derive_path()) or prerequsite (see search_existing_file()). + // So we are going to check if dir is absolute. If it is, then + // we assume this is a target, otherwise -- prerequsite. + // + if (tk.dir->absolute ()) + dr << "target " << tk; + else + dr << "prerequisite " << prerequisite_key {nullptr, tk, &s}; + + dr << info << "perhaps you forgot to add " + << tk.type->name << "{*}: " << var << " = ..."; + } + + throw failed (); + } +} |