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-builtin.cxx | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 libbuild2/functions-builtin.cxx (limited to 'libbuild2/functions-builtin.cxx') diff --git a/libbuild2/functions-builtin.cxx b/libbuild2/functions-builtin.cxx new file mode 100644 index 0000000..44ae534 --- /dev/null +++ b/libbuild2/functions-builtin.cxx @@ -0,0 +1,56 @@ +// file : libbuild2/functions-builtin.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +namespace build2 +{ + // Return NULL value if an environment variable is not set, untyped value + // otherwise. + // + static inline value + getenvvar (const string& name) + { + optional v (getenv (name)); + + if (!v) + return value (); + + names r; + r.emplace_back (to_name (move (*v))); + return value (move (r)); + } + + void + builtin_functions () + { + function_family f ("builtin"); + + f["type"] = [](value* v) {return v->type != nullptr ? v->type->name : "";}; + + f["null"] = [](value* v) {return v->null;}; + f["empty"] = [](value* v) {return v->null || v->empty ();}; + + f["identity"] = [](value* v) {return move (*v);}; + + // string + // + f["string"] = [](bool b) {return b ? "true" : "false";}; + f["string"] = [](uint64_t i) {return to_string (i);}; + f["string"] = [](name n) {return to_string (n);}; + + // getenv + // + f["getenv"] = [](string name) + { + return getenvvar (name); + }; + + f["getenv"] = [](names name) + { + return getenvvar (convert (move (name))); + }; + } +} -- cgit v1.1