From 4f923fbdace27f27421bf18dfc9655b73bd68929 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 13 Jun 2021 19:00:13 +0200 Subject: Move execution code into its own function and use from all tasks. --- task_cc.cc | 83 +++++++------------------------------------------------------- 1 file changed, 9 insertions(+), 74 deletions(-) (limited to 'task_cc.cc') diff --git a/task_cc.cc b/task_cc.cc index 2a65698..34129a3 100644 --- a/task_cc.cc +++ b/task_cc.cc @@ -2,14 +2,10 @@ #include #include -#include -#include -#include -#include -#include #include "libcppbuild.h" #include "settings.h" +#include "execute.h" namespace { @@ -148,17 +144,6 @@ bool TaskCC::dirty() return false; } -int parent_waitpid(pid_t pid) -{ - int status; - - if(waitpid(pid, &status, 0) != pid) - { - return 1; - } - - return status; -} int TaskCC::run() { if(!std::filesystem::exists(sourceFile)) @@ -174,69 +159,19 @@ int TaskCC::run() comp = "/usr/bin/gcc"; flags = config.cflags; } - - char source[256]; - strcpy(source, std::string(sourceFile).data()); - char target[256]; - strcpy(target, std::string(targetFile).data()); - char pwd[256]; - strcpy(pwd, std::string(std::filesystem::current_path()).data()); - std::vector argv; - //args.push_back("/bin/echo"); - if(comp == "/usr/bin/gcc") - { - argv.push_back("/usr/bin/gcc"); - } - else - { - argv.push_back("/usr/bin/g++"); - } - - argv.push_back("-MMD"); - argv.push_back("-c"); - argv.push_back(source); - argv.push_back("-o"); - argv.push_back(target); + std::vector args; + args.push_back("-MMD"); + args.push_back("-c"); + args.push_back(std::string(sourceFile)); + args.push_back("-o"); + args.push_back(std::string(targetFile)); for(const auto& flag : flags) { - argv.push_back(flag.data()); - } - - std::string cmd; - for(const auto& arg : argv) - { - if(arg == nullptr) - { - break; - } - if(!cmd.empty()) - { - cmd += " "; - } - cmd += arg; - } - std::cout << cmd << "\n"; - -#if 0 - auto pid = vfork(); - if(pid == 0) - { - execv(comp.data(), (char**)argv.data()); - } - auto ret = parent_waitpid(pid); -#elif 0 - pid_t pid; - if(posix_spawn(&pid, comp.data(), nullptr, nullptr, (char**)argv.data(), nullptr)) - { - return 1;//exit(1); + args.push_back(flag); } - auto ret = parent_waitpid(pid); -#else - auto ret = system(cmd.data()); -#endif - return ret; + return execute(comp, args); } int TaskCC::clean() -- cgit v1.2.3