build.cpp revision 275988
1266423Sjfv// Copyright (c) 2009 The NetBSD Foundation, Inc. 2266423Sjfv// All rights reserved. 3349163Serj// 4266423Sjfv// Redistribution and use in source and binary forms, with or without 5349163Serj// modification, are permitted provided that the following conditions 6266423Sjfv// are met: 7266423Sjfv// 1. Redistributions of source code must retain the above copyright 8266423Sjfv// notice, this list of conditions and the following disclaimer. 9266423Sjfv// 2. Redistributions in binary form must reproduce the above copyright 10266423Sjfv// notice, this list of conditions and the following disclaimer in the 11266423Sjfv// documentation and/or other materials provided with the distribution. 12266423Sjfv// 13266423Sjfv// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14266423Sjfv// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15266423Sjfv// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16266423Sjfv// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17266423Sjfv// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18266423Sjfv// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19266423Sjfv// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20266423Sjfv// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21266423Sjfv// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22266423Sjfv// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23266423Sjfv// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24266423Sjfv// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25266423Sjfv 26266423Sjfv#include "atf-c++/build.hpp" 27266423Sjfv 28266423Sjfvextern "C" { 29266423Sjfv#include "atf-c/build.h" 30266423Sjfv#include "atf-c/error.h" 31266423Sjfv#include "atf-c/utils.h" 32266423Sjfv} 33266423Sjfv 34266423Sjfv#include "atf-c++/detail/exceptions.hpp" 35266423Sjfv#include "atf-c++/detail/process.hpp" 36266423Sjfv 37266423Sjfvnamespace impl = atf::build; 38266423Sjfv#define IMPL_NAME "atf::build" 39266423Sjfv 40333343Serj// ------------------------------------------------------------------------ 41266423Sjfv// Auxiliary functions. 42266423Sjfv// ------------------------------------------------------------------------ 43266423Sjfv 44266423Sjfvinline 45266423Sjfvatf::process::argv_array 46266423Sjfvcargv_to_argv(const atf_list_t* l) 47266423Sjfv{ 48266423Sjfv std::vector< const char* > aux; 49266423Sjfv 50266423Sjfv atf_list_citer_t iter; 51266423Sjfv atf_list_for_each_c(iter, l) 52266423Sjfv aux.push_back(static_cast< const char* >(atf_list_citer_data(iter))); 53266423Sjfv 54266423Sjfv return atf::process::argv_array(aux); 55266423Sjfv} 56266423Sjfv 57266423Sjfvinline 58266423Sjfvatf::process::argv_array 59266423Sjfvcargv_to_argv_and_free(char** l) 60266423Sjfv{ 61277082Sjfv try { 62266423Sjfv atf::process::argv_array argv((const char* const*)l); 63266423Sjfv atf_utils_free_charpp(l); 64266423Sjfv return argv; 65266423Sjfv } catch (...) { 66266423Sjfv atf_utils_free_charpp(l); 67266423Sjfv throw; 68266423Sjfv } 69266423Sjfv} 70266423Sjfv 71266423Sjfv// ------------------------------------------------------------------------ 72266423Sjfv// Free functions. 73266423Sjfv// ------------------------------------------------------------------------ 74269198Sjfv 75269198Sjfvatf::process::argv_array 76266423Sjfvimpl::c_o(const std::string& sfile, const std::string& ofile, 77266423Sjfv const atf::process::argv_array& optargs) 78266423Sjfv{ 79266423Sjfv char** l; 80303967Ssbruno 81303967Ssbruno atf_error_t err = atf_build_c_o(sfile.c_str(), ofile.c_str(), 82303967Ssbruno optargs.exec_argv(), &l); 83303967Ssbruno if (atf_is_error(err)) 84303967Ssbruno throw_atf_error(err); 85303967Ssbruno 86303967Ssbruno return cargv_to_argv_and_free(l); 87303967Ssbruno} 88303967Ssbruno 89303967Ssbrunoatf::process::argv_array 90303967Ssbrunoimpl::cpp(const std::string& sfile, const std::string& ofile, 91299545Serj const atf::process::argv_array& optargs) 92299545Serj{ 93266423Sjfv char** l; 94266423Sjfv 95266423Sjfv atf_error_t err = atf_build_cpp(sfile.c_str(), ofile.c_str(), 96266423Sjfv optargs.exec_argv(), &l); 97299553Serj if (atf_is_error(err)) 98299553Serj throw_atf_error(err); 99299553Serj 100299553Serj return cargv_to_argv_and_free(l); 101299553Serj} 102299553Serj 103266423Sjfvatf::process::argv_array 104349163Serjimpl::cxx_o(const std::string& sfile, const std::string& ofile, 105349163Serj const atf::process::argv_array& optargs) 106349163Serj{ 107349163Serj char** l; 108349163Serj 109349163Serj atf_error_t err = atf_build_cxx_o(sfile.c_str(), ofile.c_str(), 110349163Serj optargs.exec_argv(), &l); 111349163Serj if (atf_is_error(err)) 112266423Sjfv throw_atf_error(err); 113266423Sjfv 114266423Sjfv return cargv_to_argv_and_free(l); 115266423Sjfv} 116277082Sjfv