From 977d07a3ae47ef204665d1eda2d642e5064724f3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Jun 2019 12:01:19 +0200 Subject: Split build system into library and driver --- libbuild2/functions-name.cxx | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 libbuild2/functions-name.cxx (limited to 'libbuild2/functions-name.cxx') diff --git a/libbuild2/functions-name.cxx b/libbuild2/functions-name.cxx new file mode 100644 index 0000000..a8e08b6 --- /dev/null +++ b/libbuild2/functions-name.cxx @@ -0,0 +1,109 @@ +// file : libbuild2/functions-name.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include +#include + +using namespace std; + +namespace build2 +{ + // Convert name to target'ish name (see below for the 'ish part). Return + // raw/unprocessed data in case this is an unknown target type (or called + // out of scope). See scope::find_target_type() for details. + // + static pair> + to_target (const scope* s, name&& n) + { + optional e; + + if (s != nullptr) + { + auto rp (s->find_target_type (n, location ())); + + if (rp.first != nullptr) + n.type = rp.first->name; + + e = move (rp.second); + } + + return make_pair (move (n), move (e)); + } + + void + name_functions () + { + function_family f ("name"); + + // These functions treat a name as a target/prerequisite name. + // + // While on one hand it feels like calling them target.name(), etc., would + // have been more appropriate, on the other hand they can also be called + // on prerequisite names. They also won't always return the same result as + // if we were interrogating an actual target (e.g., the directory may be + // relative). + // + f["name"] = [](const scope* s, name n) + { + return to_target (s, move (n)).first.value; + }; + f["name"] = [](const scope* s, names ns) + { + return to_target (s, convert (move (ns))).first.value; + }; + + // Note: returns NULL if extension is unspecified (default) and empty if + // specified as no extension. + // + f["extension"] = [](const scope* s, name n) + { + return to_target (s, move (n)).second; + }; + f["extension"] = [](const scope* s, names ns) + { + return to_target (s, convert (move (ns))).second; + }; + + f["directory"] = [](const scope* s, name n) + { + return to_target (s, move (n)).first.dir; + }; + f["directory"] = [](const scope* s, names ns) + { + return to_target (s, convert (move (ns))).first.dir; + }; + + f["target_type"] = [](const scope* s, name n) + { + return to_target (s, move (n)).first.type; + }; + f["target_type"] = [](const scope* s, names ns) + { + return to_target (s, convert (move (ns))).first.type; + }; + + // Note: returns NULL if no project specified. + // + f["project"] = [](const scope* s, name n) + { + return to_target (s, move (n)).first.proj; + }; + f["project"] = [](const scope* s, names ns) + { + return to_target (s, convert (move (ns))).first.proj; + }; + + // Name-specific overloads from builtins. + // + function_family b ("builtin"); + + b[".concat"] = [](dir_path d, name n) + { + d /= n.dir; + n.dir = move (d); + return n; + }; + } +} -- cgit v1.1