2 // Automated Testing Framework (atf)
4 // Copyright (c) 2009 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.
31 #include "atf-c/build.h"
32 #include "atf-c/error.h"
33 #include "atf-c/utils.h"
38 #include "detail/exceptions.hpp"
39 #include "detail/process.hpp"
41 namespace impl
= atf::build
;
42 #define IMPL_NAME "atf::build"
44 // ------------------------------------------------------------------------
45 // Auxiliary functions.
46 // ------------------------------------------------------------------------
49 atf::process::argv_array
50 cargv_to_argv(const atf_list_t
* l
)
52 std::vector
< const char* > aux
;
54 atf_list_citer_t iter
;
55 atf_list_for_each_c(iter
, l
)
56 aux
.push_back(static_cast< const char* >(atf_list_citer_data(iter
)));
58 return atf::process::argv_array(aux
);
62 atf::process::argv_array
63 cargv_to_argv_and_free(char** l
)
66 atf::process::argv_array
argv((const char* const*)l
);
67 atf_utils_free_charpp(l
);
70 atf_utils_free_charpp(l
);
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
79 atf::process::argv_array
80 impl::c_o(const std::string
& sfile
, const std::string
& ofile
,
81 const atf::process::argv_array
& optargs
)
85 atf_error_t err
= atf_build_c_o(sfile
.c_str(), ofile
.c_str(),
86 optargs
.exec_argv(), &l
);
87 if (atf_is_error(err
))
90 return cargv_to_argv_and_free(l
);
93 atf::process::argv_array
94 impl::cpp(const std::string
& sfile
, const std::string
& ofile
,
95 const atf::process::argv_array
& optargs
)
99 atf_error_t err
= atf_build_cpp(sfile
.c_str(), ofile
.c_str(),
100 optargs
.exec_argv(), &l
);
101 if (atf_is_error(err
))
102 throw_atf_error(err
);
104 return cargv_to_argv_and_free(l
);
107 atf::process::argv_array
108 impl::cxx_o(const std::string
& sfile
, const std::string
& ofile
,
109 const atf::process::argv_array
& optargs
)
113 atf_error_t err
= atf_build_cxx_o(sfile
.c_str(), ofile
.c_str(),
114 optargs
.exec_argv(), &l
);
115 if (atf_is_error(err
))
116 throw_atf_error(err
);
118 return cargv_to_argv_and_free(l
);