summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-13 18:24:16 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-13 18:24:16 +0200
commit19195e2bbdcd7a0db8f84732ce54b1c9d07c006c (patch)
treeb974b648ebacd645fbee000575268326f3b7bfbc /libcppbuild.cc
parentf6f5f31067cdee2d7003d8209361ac9e5b6975c5 (diff)
Make task an abstract class and make CC and LD versions of it.
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc72
1 files changed, 22 insertions, 50 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index 2167173..c75f43e 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -6,9 +6,11 @@
#include <list>
#include <chrono>
#include <thread>
+#include <memory>
#include "libcppbuild.h"
-#include "task.h"
+#include "task_cc.h"
+#include "task_ld.h"
#include "settings.h"
#include <unistd.h>
@@ -29,31 +31,33 @@ int main(int argc, const char* argv[])
std::filesystem::create_directories(builddir);
auto config = configs();
- std::string output = builddir / config.target;
- const auto& files = config.sources;
- std::vector<std::string> objects;
-
- std::vector<Task> tasks;
- for(const auto& file : files)
+ std::vector<std::string> objects;
+ std::vector<std::unique_ptr<Task>> tasks;
+ for(const auto& file : config.sources)
{
- tasks.emplace_back(config, settings, file);
- objects.push_back(tasks.back().target());
+ tasks.emplace_back(std::make_unique<TaskCC>(config, settings, file));
+ objects.push_back(tasks.back()->target());
}
+ TaskLD task_ld(config, settings, config.target, objects);
+
if(argc == 2 && std::string(argv[1]) == "clean")
{
std::cout << "Cleaning\n";
//std::filesystem::remove_all(builddir);
for(auto& task : tasks)
{
- if(task.clean() != 0)
+ if(task->clean() != 0)
{
return 1;
}
}
- std::filesystem::remove(output);
+ if(task_ld.clean() != 0)
+ {
+ return 1;
+ }
return 0;
}
@@ -69,7 +73,7 @@ int main(int argc, const char* argv[])
while(processes.size() < settings.parallel_processes &&
task != tasks.end())
{
- if(!task->dirty())
+ if(!(*task)->dirty())
{
++task;
continue;
@@ -77,9 +81,9 @@ int main(int argc, const char* argv[])
processes.emplace_back(
std::async(std::launch::async,
- [task]()
+ [&t = *task]()
{
- return task->run();
+ return t->run();
}));
++task;
std::this_thread::sleep_for(2ms);
@@ -108,49 +112,17 @@ int main(int argc, const char* argv[])
++process)
{
process->wait();
- if(process->get() != 0)
+ auto ret = process->get();
+ if(ret != 0)
{
return 1;
}
}
std::cout << "Linking\n";
- bool dolink{false};
- if(!std::filesystem::exists(output))
- {
- dolink = true;
- }
- else
- {
- for(const auto& object : objects)
- {
- if(std::filesystem::last_write_time(output) <=
- std::filesystem::last_write_time(object))
- {
- dolink = true;
- break;
- }
- }
- }
-
- if(!dolink)
- {
- std::cout << "No linking needed\n";
- return 0;
- }
-
- std::string objectlist;
- for(const auto& object : objects)
- {
- objectlist += object + " ";
- }
- std::string compiler = "g++ " + objectlist + " " +
- config.ldflags + " " +
- "-o " + output;
- std::cout << compiler << "\n";
- if(system(compiler.data()))
+ if(task_ld.dirty())
{
- return 1;
+ return task_ld.run();
}
return 0;