1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// file : build2/config/utility -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#ifndef BUILD2_CONFIG_UTILITY
#define BUILD2_CONFIG_UTILITY
#include <build2/types>
#include <build2/utility>
#include <build2/variable>
#include <build2/diagnostics>
namespace build2
{
class scope;
namespace config
{
// Set, if necessary, a required config.* variable.
//
// If override is true and the variable doesn't come from this root scope
// or from the command line (i.e., it is inherited from the amalgamtion),
// then its value is "overridden" to the default value on this root scope.
//
// Return the reference to the value as well as the indication of whether
// the value is "new", that is, it was set to the default value (inherited
// or not, including overrides). We also treat command line overrides
// (inherited or not) as new. This flag is usually used to test that the
// new value is valid, etc.
//
template <typename T>
pair<reference_wrapper<const value>, bool>
required (scope& root,
const variable&,
const T& default_value,
bool override = false);
template <typename T>
inline pair<reference_wrapper<const value>, bool>
required (scope& root,
const string& name,
const T& default_value,
bool override = false)
{
return required (root, var_pool.find (name), default_value, override);
}
inline pair<reference_wrapper<const value>, bool>
required (scope& root,
const string& name,
const char* default_value,
bool override = false)
{
return required (root, name, string (default_value), override);
}
// As above, but leave the unspecified value as undefined (and return
// NULL pointer) rather than setting it to the default value.
//
// This can be useful when we don't have a default value but may figure
// out some fallback. See config.bin.target for an example.
//
pair<const value*, bool>
required (scope& root, const variable&);
inline pair<const value*, bool>
required (scope& root, const string& name)
{
return required (root, var_pool.find (name));
}
// Set, if necessary, an optional config.* variable. In particular,
// an unspecified variable is set to NULL which is used to distinguish
// between the "configured as unspecified" and "not yet configured"
// cases.
//
// Return the value, which can be NULL.
//
const value&
optional (scope& root, const variable&);
inline const value&
optional (scope& root, const string& var)
{
return optional (root, var_pool.find (var));
}
// Check whether there are any variables specified from the config
// namespace. The idea is that we can check if there are any, say,
// config.install.* values. If there are none, then we can assume
// this functionality is not (yet) used and omit writing a whole
// bunch of NULL config.install.* values to the config.build file.
// We call it omitted/delayed configuration.
//
// Note that this function detects and ignores the special
// config.*.configured variable which may be used by a module to
// "remember" that it is unconfigured (e.g., in order to avoid re-
// running the tests, etc).
//
bool
specified (scope& root, const string& ns);
// Check if there is a false config.*.configured value. This mechanism can
// be used to "remember" that the module is left unconfigured in order to
// avoid re-running the tests, etc.
//
bool
unconfigured (scope& root, const string& ns);
// Set the config.*.configured value. Note that you only need to set it to
// false. It will be automatically ignored if there are any other config.*
// values for this module.
//
void
unconfigured (scope& root, const string& ns, bool);
// Enter the variable so that it is saved during configuration. See
// config::module.
//
void
save_variable (scope& root, const variable&, uint64_t flags = 0);
}
}
#include <build2/config/utility.txx>
#endif // BUILD2_CONFIG_UTILITY
|