summaryrefslogtreecommitdiff
path: root/task.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-12 16:16:41 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-12 16:16:41 +0200
commit6bcbf18a6a67707c13d66b96770c8b210a45b9f4 (patch)
treebbbc866f84df2985db6ca8719884e4fb09fd10cf /task.cc
parent889106af4d8381ac188a6532625e2c642150220f (diff)
Skip non-dirty tasks.
Diffstat (limited to 'task.cc')
-rw-r--r--task.cc95
1 files changed, 48 insertions, 47 deletions
diff --git a/task.cc b/task.cc
index 4728a1c..29e18cb 100644
--- a/task.cc
+++ b/task.cc
@@ -94,84 +94,80 @@ Task::Task(const BuildConfiguration& config, const Settings& settings,
depsFile += ".d";
}
-int Task::run()
+bool Task::dirty()
{
if(!std::filesystem::exists(sourceFile))
{
- std::cout << "Missing source file: " << std::string(sourceFile) << "\n";
- return 1;
+ //std::cout << "Missing source file: " << std::string(sourceFile) << "\n";
+ return true;
}
- bool recompile{false};
-
- if(!recompile &&
- !std::filesystem::exists(targetFile))
+ if(!std::filesystem::exists(targetFile))
{
- recompile = true;
//std::cout << "Missing targetFile\n";
+ return true;
}
- if(!recompile &&
- !std::filesystem::exists(depsFile))
+ if(!std::filesystem::exists(depsFile))
{
- recompile = true;
//std::cout << "Missing depsFile\n";
+ return true;
}
- if(!recompile &&
- std::filesystem::last_write_time(sourceFile) >
+ if(std::filesystem::last_write_time(sourceFile) >
std::filesystem::last_write_time(depsFile))
{
- recompile = true;
//std::cout << "The sourceFile newer than depsFile\n";
+ return true;
}
- if(!recompile)
+ auto depList = readDeps(depsFile);
+ for(const auto& dep : depList)
{
- 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))
{
- 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;
- }
+ //std::cout << "The targetFile older than " << std::string(dep) << "\n";
+ return true;
}
}
- if(!recompile &&
- std::filesystem::last_write_time(sourceFile) >
+ if(std::filesystem::last_write_time(sourceFile) >
std::filesystem::last_write_time(targetFile))
{
- recompile = true;
//std::cout << "The targetFile older than sourceFile\n";
+ return true;
}
- if(recompile)
+ return false;
+}
+
+int Task::run()
+{
+ if(!std::filesystem::exists(sourceFile))
{
- 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";
+ std::cout << "Missing source file: " << std::string(sourceFile) << "\n";
+ return 1;
+ }
- if(system(cmd.data()))
- {
- return 1;
- }
- return 0;
+ 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;
}
@@ -192,7 +188,12 @@ int Task::clean()
return 0;
}
-std::vector<std::string> Task::depends()
+std::vector<std::string> Task::depends() const
{
return {};
}
+
+std::string Task::target() const
+{
+ return targetFile;
+}