1 // 2 // Automated Testing Framework (atf) 3 // 4 // Copyright (c) 2009 The NetBSD Foundation, Inc. 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions 9 // are met: 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. 15 // 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. 28 // 29 30 extern "C" { 31 #include "atf-c/build.h" 32 #include "atf-c/error.h" 33 } 34 35 #include "atf-c++/build.hpp" 36 #include "atf-c++/exceptions.hpp" 37 #include "atf-c++/process.hpp" 38 39 namespace impl = atf::build; 40 #define IMPL_NAME "atf::build" 41 42 // ------------------------------------------------------------------------ 43 // Auxiliary functions. 44 // ------------------------------------------------------------------------ 45 46 inline 47 atf::process::argv_array 48 clist_to_argv(const atf_list_t* l) 49 { 50 std::vector< const char* > aux; 51 52 atf_list_citer_t iter; 53 atf_list_for_each_c(iter, l) 54 aux.push_back(static_cast< const char* >(atf_list_citer_data(iter))); 55 56 return atf::process::argv_array(aux); 57 } 58 59 inline 60 atf::process::argv_array 61 clist_to_argv_and_free(atf_list_t* l) 62 { 63 try { 64 atf::process::argv_array argv = clist_to_argv(l); 65 atf_list_fini(l); 66 return argv; 67 } catch (...) { 68 atf_list_fini(l); 69 throw; 70 } 71 } 72 73 // ------------------------------------------------------------------------ 74 // Free functions. 75 // ------------------------------------------------------------------------ 76 77 atf::process::argv_array 78 impl::c_o(const std::string& sfile, const std::string& ofile, 79 const process::argv_array& optargs) 80 { 81 atf_list_t l; 82 83 atf_error_t err = atf_build_c_o(sfile.c_str(), ofile.c_str(), 84 optargs.exec_argv(), &l); 85 if (atf_is_error(err)) 86 throw_atf_error(err); 87 88 return clist_to_argv_and_free(&l); 89 } 90 91 atf::process::argv_array 92 impl::cpp(const std::string& sfile, const std::string& ofile, 93 const process::argv_array& optargs) 94 { 95 atf_list_t l; 96 97 atf_error_t err = atf_build_cpp(sfile.c_str(), ofile.c_str(), 98 optargs.exec_argv(), &l); 99 if (atf_is_error(err)) 100 throw_atf_error(err); 101 102 return clist_to_argv_and_free(&l); 103 } 104 105 atf::process::argv_array 106 impl::cxx_o(const std::string& sfile, const std::string& ofile, 107 const process::argv_array& optargs) 108 { 109 atf_list_t l; 110 111 atf_error_t err = atf_build_cxx_o(sfile.c_str(), ofile.c_str(), 112 optargs.exec_argv(), &l); 113 if (atf_is_error(err)) 114 throw_atf_error(err); 115 116 return clist_to_argv_and_free(&l); 117 } 118