2 // Automated Testing Framework (atf)
4 // Copyright (c) 2007 The NetBSD Foundation, Inc.
5 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 static std::map
< std::string
, std::string
> m_variables
;
41 const char *default_value
;
44 { "ATF_ARCH", ATF_ARCH
, false, },
45 { "ATF_BUILD_CC", ATF_BUILD_CC
, false, },
46 { "ATF_BUILD_CFLAGS", ATF_BUILD_CFLAGS
, true, },
47 { "ATF_BUILD_CPP", ATF_BUILD_CPP
, false, },
48 { "ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS
, true, },
49 { "ATF_BUILD_CXX", ATF_BUILD_CXX
, false, },
50 { "ATF_BUILD_CXXFLAGS", ATF_BUILD_CXXFLAGS
, true, },
51 { "ATF_CONFDIR", ATF_CONFDIR
, false, },
52 { "ATF_INCLUDEDIR", ATF_INCLUDEDIR
, false, },
53 { "ATF_LIBDIR", ATF_LIBDIR
, false, },
54 { "ATF_LIBEXECDIR", ATF_LIBEXECDIR
, false, },
55 { "ATF_MACHINE", ATF_MACHINE
, false, },
56 { "ATF_PKGDATADIR", ATF_PKGDATADIR
, false, },
57 { "ATF_SHELL", ATF_SHELL
, false, },
58 { "ATF_WORKDIR", ATF_WORKDIR
, false, },
59 { NULL
, NULL
, false, },
63 // Adds all predefined standard build-time variables to the m_variables
64 // map, considering the values a user may have provided in the environment.
66 // Can only be called once during the program's lifetime.
72 assert(m_variables
.empty());
74 for (struct var
* v
= vars
; v
->name
!= NULL
; v
++) {
75 const std::string varname
= tools::text::to_lower(v
->name
);
77 if (tools::env::has(v
->name
)) {
78 const std::string envval
= tools::env::get(v
->name
);
79 if (envval
.empty() && !v
->can_be_empty
)
80 m_variables
[varname
] = v
->default_value
;
82 m_variables
[varname
] = envval
;
84 m_variables
[varname
] = v
->default_value
;
88 assert(!m_variables
.empty());
92 tools::config::get(const std::string
& varname
)
94 if (m_variables
.empty())
98 return m_variables
[varname
];
101 const std::map
< std::string
, std::string
>&
102 tools::config::get_all(void)
104 if (m_variables
.empty())
111 tools::config::has(const std::string
& varname
)
113 if (m_variables
.empty())
116 return m_variables
.find(varname
) != m_variables
.end();
122 // Auxiliary function for the t_config test program so that it can
123 // revert the configuration's global status to an empty state and
124 // do new tests from there on.
126 // Ideally this shouldn't be part of the production library... but
127 // this is so small that it does not matter.
134 } // namespace config