summaryrefslogtreecommitdiff
path: root/src/task_cc.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2022-06-07 18:06:57 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2022-06-09 22:20:31 +0200
commitdafd592cf44c184f9d24e2216bbed5c23e4b23c2 (patch)
treee94ab4c49ec4486e3a8e91c04cbba73a221d54c7 /src/task_cc.cc
parent80db51ae3f7d5fbfb52eee4505f615ea4edba62d (diff)
Refactor the way task names are looked up.
Diffstat (limited to 'src/task_cc.cc')
-rw-r--r--src/task_cc.cc67
1 files changed, 23 insertions, 44 deletions
diff --git a/src/task_cc.cc b/src/task_cc.cc
index 1db9767..41a97f3 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -12,34 +12,9 @@
#include "execute.h"
#include "util.h"
-namespace
-{
-bool isClean(char c)
-{
- return c != '.' && c != '/';
-}
-
-std::string cleanUp(const std::string& path)
-{
- std::string cleaned;
- for(const auto& c : path)
- {
- if(isClean(c))
- {
- cleaned += c;
- }
- else
- {
- cleaned += '_';
- }
- }
- return cleaned;
-}
-}
-
TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
const std::string& sourceDir, const Source& source)
- : Task(config)
+ : Task(config, settings, sourceDir)
, config(config)
, settings(settings)
, sourceDir(sourceDir)
@@ -47,9 +22,8 @@ TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
sourceFile = sourceDir;
sourceFile /= source.file;
- std::filesystem::path base = settings.builddir;
- base /= sourceFile.parent_path();
- std::filesystem::create_directories(base);
+ std::filesystem::path base = sourceFile.parent_path();
+ std::filesystem::create_directories(std::filesystem::path(settings.builddir) / base);
base /= cleanUp(config.target);
base += "-";
@@ -78,17 +52,17 @@ TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
break;
}
- targetFile = base;
- targetFile += ".o";
- depsFile = base;
+ _targetFile = base;
+ _targetFile += ".o";
+ depsFile = targetFile().parent_path() / targetFile().stem();
depsFile += ".d";
- flagsFile = base;
+ flagsFile = targetFile().parent_path() / targetFile().stem();
flagsFile += ".flags";
}
std::string TaskCC::name() const
{
- return target();
+ return {};
}
bool TaskCC::dirtyInner()
@@ -99,7 +73,7 @@ bool TaskCC::dirtyInner()
return true;
}
- if(!std::filesystem::exists(targetFile))
+ if(!std::filesystem::exists(targetFile()))
{
//std::cout << "Missing targetFile\n";
return true;
@@ -137,7 +111,7 @@ bool TaskCC::dirtyInner()
for(const auto& dep : depList)
{
if(!std::filesystem::exists(dep) ||
- std::filesystem::last_write_time(targetFile) <
+ std::filesystem::last_write_time(targetFile()) <
std::filesystem::last_write_time(dep))
{
//std::cout << "The targetFile older than " << std::string(dep) << "\n";
@@ -146,7 +120,7 @@ bool TaskCC::dirtyInner()
}
if(std::filesystem::last_write_time(sourceFile) >
- std::filesystem::last_write_time(targetFile))
+ std::filesystem::last_write_time(targetFile()))
{
//std::cout << "The targetFile older than sourceFile\n";
return true;
@@ -174,7 +148,7 @@ int TaskCC::runInner()
{
std::cout << compiler() << " " <<
sourceFile.lexically_normal().string() << " => " <<
- targetFile.lexically_normal().string() << "\n";
+ targetFile().lexically_normal().string() << "\n";
}
return execute(compiler(), args, settings.verbose > 0);
@@ -182,10 +156,10 @@ int TaskCC::runInner()
int TaskCC::clean()
{
- if(std::filesystem::exists(targetFile))
+ if(std::filesystem::exists(targetFile()))
{
- std::cout << "Removing " << targetFile.string() << "\n";
- std::filesystem::remove(targetFile);
+ std::cout << "Removing " << targetFile().string() << "\n";
+ std::filesystem::remove(targetFile());
}
if(std::filesystem::exists(depsFile))
@@ -210,7 +184,12 @@ std::vector<std::string> TaskCC::depends() const
std::string TaskCC::target() const
{
- return targetFile.string();
+ return _targetFile.string();
+}
+
+std::filesystem::path TaskCC::targetFile() const
+{
+ return std::filesystem::path(settings.builddir) / _targetFile;
}
bool TaskCC::derived() const
@@ -224,7 +203,7 @@ std::string TaskCC::toJSON() const
json += "\t{\n";
json += "\t\t\"directory\": \"" + sourceDir.string() + "\",\n";
json += "\t\t\"file\": \"" + sourceFile.lexically_normal().string() + "\",\n";
- json += "\t\t\"output\": \"" + targetFile.string() + "\",\n";
+ json += "\t\t\"output\": \"" + targetFile().string() + "\",\n";
json += "\t\t\"arguments\": [ \"" + compiler() + "\"";
auto args = getCompilerArgs();
for(const auto& arg : args)
@@ -282,7 +261,7 @@ std::vector<std::string> TaskCC::getCompilerArgs() const
args.push_back("-c");
args.push_back(sourceFile.string());
args.push_back("-o");
- args.push_back(targetFile.string());
+ args.push_back(targetFile().string());
for(const auto& flag : compiler_flags)
{