summaryrefslogtreecommitdiff
path: root/src/task_ld.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_ld.cc
parent80db51ae3f7d5fbfb52eee4505f615ea4edba62d (diff)
Refactor the way task names are looked up.
Diffstat (limited to 'src/task_ld.cc')
-rw-r--r--src/task_ld.cc55
1 files changed, 21 insertions, 34 deletions
diff --git a/src/task_ld.cc b/src/task_ld.cc
index 600de8e..e78a1e6 100644
--- a/src/task_ld.cc
+++ b/src/task_ld.cc
@@ -9,31 +9,17 @@
#include "libctor.h"
#include "settings.h"
#include "execute.h"
-
-namespace
-{
-std::string readFile(const std::string &fileName)
-{
- std::ifstream ifs(fileName.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
-
- std::ifstream::pos_type fileSize = ifs.tellg();
- ifs.seekg(0, std::ios::beg);
-
- std::vector<char> bytes(fileSize);
- ifs.read(bytes.data(), fileSize);
-
- return std::string(bytes.data(), fileSize);
-}
-} // namespace ::
+#include "util.h"
TaskLD::TaskLD(const BuildConfiguration& config,
const Settings& settings,
const std::string& target,
const std::vector<std::string>& objects,
- const std::string& sourcePath)
- : Task(config)
+ const std::string& sourceDir)
+ : Task(config, settings, sourceDir)
, config(config)
, settings(settings)
+ , sourceDir(sourceDir)
{
target_type = config.type;
if(target_type == TargetType::Auto)
@@ -41,11 +27,9 @@ TaskLD::TaskLD(const BuildConfiguration& config,
target_type = TargetType::Executable;
}
- std::filesystem::path base = settings.builddir;
- base /= sourcePath;
- std::filesystem::create_directories(base);
+ std::filesystem::create_directories(std::filesystem::path(settings.builddir) / sourceDir);
- targetFile = base / target;
+ _targetFile = target;
for(const auto& object : objects)
{
std::filesystem::path objectFile = object;
@@ -55,12 +39,10 @@ TaskLD::TaskLD(const BuildConfiguration& config,
for(const auto& dep : config.depends)
{
- std::filesystem::path depFile = settings.builddir;
- depFile /= dep;
- depFiles.push_back(depFile);
+ depFiles.push_back(dep);
}
- flagsFile = base / targetFile.stem();
+ flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem();
flagsFile += ".flags";
source_language = Language::C;
@@ -76,7 +58,7 @@ TaskLD::TaskLD(const BuildConfiguration& config,
bool TaskLD::dirtyInner()
{
- if(!std::filesystem::exists(targetFile))
+ if(!std::filesystem::exists(targetFile()))
{
return true;
}
@@ -103,7 +85,7 @@ int TaskLD::runInner()
std::vector<std::string> args;
for(const auto& dep : getDependsTasks())
{
- std::filesystem::path depFile = dep->target();
+ auto depFile = dep->targetFile();
if(depFile.extension() == ".so")
{
args.push_back(std::string("-L") + settings.builddir);
@@ -121,7 +103,7 @@ int TaskLD::runInner()
args.push_back(flag);
}
args.push_back("-o");
- args.push_back(targetFile.string());
+ args.push_back(targetFile().string());
{ // Write flags to file.
std::ofstream flagsStream(flagsFile);
@@ -130,7 +112,7 @@ int TaskLD::runInner()
if(settings.verbose == 0)
{
- std::cout << "LD => " << targetFile.string() << "\n";
+ std::cout << "LD => " << targetFile().string() << "\n";
}
auto tool = compiler();
@@ -139,10 +121,10 @@ int TaskLD::runInner()
int TaskLD::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(flagsFile))
@@ -172,7 +154,12 @@ std::vector<std::string> TaskLD::depends() const
std::string TaskLD::target() const
{
- return targetFile.string();
+ return _targetFile.string();
+}
+
+std::filesystem::path TaskLD::targetFile() const
+{
+ return std::filesystem::path(settings.builddir) / sourceDir / _targetFile;
}
bool TaskLD::derived() const