summaryrefslogtreecommitdiff
path: root/task_cc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'task_cc.cc')
-rw-r--r--task_cc.cc83
1 files changed, 9 insertions, 74 deletions
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 <iostream>
#include <fstream>
-#include <unistd.h>
-#include <cstring>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <spawn.h>
#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<const char*> 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<std::string> 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()