summaryrefslogtreecommitdiff
path: root/task.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-12 15:53:20 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-12 15:57:07 +0200
commit889106af4d8381ac188a6532625e2c642150220f (patch)
treef8c72a302cfd06b2f63a86fbd633fbdf9848caba /task.cc
parent4fad20f754c754b6bd1cacadc3016babb3188bcf (diff)
Limit number of threads
Diffstat (limited to 'task.cc')
-rw-r--r--task.cc165
1 files changed, 77 insertions, 88 deletions
diff --git a/task.cc b/task.cc
index 4dcbbd8..4728a1c 100644
--- a/task.cc
+++ b/task.cc
@@ -94,96 +94,85 @@ Task::Task(const BuildConfiguration& config, const Settings& settings,
depsFile += ".d";
}
-void Task::start()
+int Task::run()
{
- future =
- std::async(std::launch::async,
- [&]()
- {
- if(!std::filesystem::exists(sourceFile))
- {
- std::cout << "Missing source file: " << std::string(sourceFile) << "\n";
- return 1;
- }
-
- bool recompile{false};
-
- if(!recompile &&
- !std::filesystem::exists(targetFile))
- {
- recompile = true;
- std::cout << "Missing targetFile\n";
- }
-
- if(!recompile &&
- !std::filesystem::exists(depsFile))
- {
- recompile = true;
- std::cout << "Missing depsFile\n";
- }
-
- if(!recompile &&
- std::filesystem::last_write_time(sourceFile) >
- std::filesystem::last_write_time(depsFile))
- {
- recompile = true;
- std::cout << "The sourceFile newer than depsFile\n";
- }
-
- if(!recompile)
- {
- auto depList = readDeps(depsFile);
- for(const auto& dep : depList)
- {
- if(!std::filesystem::exists(dep) ||
- std::filesystem::last_write_time(targetFile) <
- std::filesystem::last_write_time(dep))
- {
- recompile = true;
- std::cout << "The targetFile older than dep\n";
- break;
- }
- }
- }
-
- if(!recompile &&
- std::filesystem::last_write_time(sourceFile) >
- std::filesystem::last_write_time(targetFile))
- {
- recompile = true;
- std::cout << "The targetFile older than sourceFile\n";
- }
-
- if(recompile)
- {
- std::string comp = "g++";
- std::string flags = config.cxxflags;
- if(std::string(sourceFile.extension()) == ".c")
- {
- comp = "gcc";
- flags = config.cflags;
- }
- std::string cmd = comp +
- " -MMD -c " + std::string(sourceFile) + " " +
- flags + " " +
- "-o " + std::string(targetFile);
- std::cout << cmd << "\n";
-
- if(system(cmd.data()))
- {
- return 1;
- }
- return 0;
- }
-
- return 0;
- });
-}
+ if(!std::filesystem::exists(sourceFile))
+ {
+ std::cout << "Missing source file: " << std::string(sourceFile) << "\n";
+ return 1;
+ }
-int Task::wait()
-{
- future.wait();
- return future.get();
+ bool recompile{false};
+
+ if(!recompile &&
+ !std::filesystem::exists(targetFile))
+ {
+ recompile = true;
+ //std::cout << "Missing targetFile\n";
+ }
+
+ if(!recompile &&
+ !std::filesystem::exists(depsFile))
+ {
+ recompile = true;
+ //std::cout << "Missing depsFile\n";
+ }
+
+ if(!recompile &&
+ std::filesystem::last_write_time(sourceFile) >
+ std::filesystem::last_write_time(depsFile))
+ {
+ recompile = true;
+ //std::cout << "The sourceFile newer than depsFile\n";
+ }
+
+ if(!recompile)
+ {
+ auto depList = readDeps(depsFile);
+ for(const auto& dep : depList)
+ {
+ if(!std::filesystem::exists(dep) ||
+ std::filesystem::last_write_time(targetFile) <
+ std::filesystem::last_write_time(dep))
+ {
+ recompile = true;
+ //std::cout << "The targetFile older than dep\n";
+ break;
+ }
+ }
+ }
+
+ if(!recompile &&
+ std::filesystem::last_write_time(sourceFile) >
+ std::filesystem::last_write_time(targetFile))
+ {
+ recompile = true;
+ //std::cout << "The targetFile older than sourceFile\n";
+ }
+
+ if(recompile)
+ {
+ std::string comp = "g++";
+ std::string flags = config.cxxflags;
+ if(std::string(sourceFile.extension()) == ".c")
+ {
+ comp = "gcc";
+ flags = config.cflags;
+ }
+ std::string cmd = comp +
+ " -MMD -c " + std::string(sourceFile) + " " +
+ flags + " " +
+ "-o " + std::string(targetFile);
+ std::cout << cmd << "\n";
+
+ if(system(cmd.data()))
+ {
+ return 1;
+ }
+ return 0;
+ }
+
+ return 0;
}
int Task::clean()