diff options
Diffstat (limited to 'src/task_ar.cc')
-rw-r--r-- | src/task_ar.cc | 105 |
1 files changed, 42 insertions, 63 deletions
diff --git a/src/task_ar.cc b/src/task_ar.cc index e920571..3e1746c 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -7,36 +7,22 @@ #include <fstream> #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" TaskAR::TaskAR(const BuildConfiguration& config, const Settings& settings, const std::string& target, - const std::vector<std::string>& objects) - : Task(config) + const std::vector<std::string>& objects, + const std::string& sourceDir) + : Task(config, settings, sourceDir) , config(config) , settings(settings) + , sourceDir(sourceDir) { - targetFile = settings.builddir; - targetFile /= target; + std::filesystem::create_directories(std::filesystem::path(settings.builddir) / sourceDir); + + _targetFile = target; for(const auto& object : objects) { std::filesystem::path objectFile = object; @@ -46,19 +32,18 @@ TaskAR::TaskAR(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 = settings.builddir / targetFile.stem(); + flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem(); flagsFile += ".flags"; target_type = TargetType::StaticLibrary; source_language = Language::C; for(const auto& source : config.sources) { - std::filesystem::path sourceFile(source); + std::filesystem::path sourceFile(source.file); + // TODO: Use task languages instead if(sourceFile.extension().string() != ".c") { source_language = Language::Cpp; @@ -68,7 +53,7 @@ TaskAR::TaskAR(const BuildConfiguration& config, bool TaskAR::dirtyInner() { - if(!std::filesystem::exists(targetFile)) + if(!std::filesystem::exists(targetFile())) { return true; } @@ -78,15 +63,6 @@ bool TaskAR::dirtyInner() return true; } - for(const auto& objectFile : objectFiles) - { - if(std::filesystem::last_write_time(targetFile) <= - std::filesystem::last_write_time(objectFile)) - { - return true; - } - } - { auto lastFlags = readFile(flagsFile.string()); if(flagsString() != lastFlags) @@ -101,26 +77,12 @@ bool TaskAR::dirtyInner() int TaskAR::runInner() { - std::string objectlist; - for(const auto& objectFile : objectFiles) - { - if(!objectlist.empty()) - { - objectlist += " "; - } - objectlist += objectFile.string(); - } - std::vector<std::string> args; args.push_back("rcs"); - args.push_back(targetFile.string()); - for(const auto& objectFile : objectFiles) + args.push_back(targetFile().string()); + for(const auto& task : getDependsTasks()) { - args.push_back(objectFile.string()); - } - for(const auto& flag : config.ldflags) - { - args.push_back(flag); + args.push_back(task->targetFile().string()); } { // Write flags to file. @@ -130,7 +92,7 @@ int TaskAR::runInner() if(settings.verbose == 0) { - std::cout << "AR => " << targetFile.string() << "\n"; + std::cout << "AR => " << targetFile().string() << "\n"; } std::string tool; @@ -149,10 +111,10 @@ int TaskAR::runInner() int TaskAR::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,9 +134,9 @@ std::vector<std::string> TaskAR::depends() const deps.push_back(objectFile.string()); } - for(const auto& depFile : depFiles) + for(const auto& dep : config.depends) { - deps.push_back(depFile.string()); + deps.push_back(dep); } return deps; @@ -182,15 +144,25 @@ std::vector<std::string> TaskAR::depends() const std::string TaskAR::target() const { - return targetFile.string(); + return _targetFile.string(); +} + +std::filesystem::path TaskAR::targetFile() const +{ + return std::filesystem::path(settings.builddir) / sourceDir / _targetFile; +} + +bool TaskAR::derived() const +{ + return false; } std::string TaskAR::flagsString() const { std::string flagsStr; - for(const auto& flag : config.ldflags) + for(const auto& flag : config.flags.ldflags) { - if(flag != config.ldflags[0]) + if(flag != config.flags.ldflags[0]) { flagsStr += " "; } @@ -207,5 +179,12 @@ std::string TaskAR::flagsString() const flagsStr += dep; } + auto deps = depends(); + for(const auto& dep : deps) + { + flagsStr += " "; + flagsStr += dep; + } + return flagsStr; } |