diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bootstrap.cc | 6 | ||||
-rw-r--r-- | src/deps.cc | 120 | ||||
-rw-r--r-- | src/deps.h | 12 | ||||
-rw-r--r-- | src/task_cc.cc | 9 | ||||
-rw-r--r-- | src/util.cc | 60 | ||||
-rw-r--r-- | src/util.h | 1 |
6 files changed, 144 insertions, 64 deletions
diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 471c844..aa50561 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -81,6 +81,12 @@ const std::string& ctor::configuration::get(const std::string& key, const std::s return default_value; } +std::vector<std::string> readDeps(const std::string& depFile, + ctor::toolchain toolchain) +{ + return {}; +} + int main(int argc, char* argv[]) { auto args = std::span(argv, static_cast<std::size_t>(argc)); diff --git a/src/deps.cc b/src/deps.cc new file mode 100644 index 0000000..9400b35 --- /dev/null +++ b/src/deps.cc @@ -0,0 +1,120 @@ +// -*- c++ -*- +// Distributed under the BSD 2-Clause License. +// See accompanying file LICENSE for details. +#include "deps.h" + +#include "util.h" + +#include <fstream> + +namespace { +/* Format example: +build/src/libctor_a-libctor_cc.o: src/libctor.cc \ + src/getoptpp/getoptpp.hpp src/ctor.h src/configure.h src/rebuild.h \ + src/A\ B\ C.h src/task.h src/build.h src/unittest.h + */ +std::vector<std::string> readDepsMake(const std::string& dep_file) +{ + auto str = readFile(dep_file); + + std::vector<std::string> output; + std::string tmp; + + enum class State + { + pre_colon, + post_colon, + in_escape, + } state{State::pre_colon}; + + auto old_state{state}; + for(const auto& c : str) + { + if(c == '\r') + { + // just always ignore windows extra newline char + continue; + } + + switch(state) + { + case State::pre_colon: + if(c == ':') // ignore everything until the colon + { + state = State::post_colon; + continue; + } + continue; + + case State::post_colon: + if(c == '\n') + { + // done + if(!tmp.empty()) + { + output.emplace_back(tmp); + } + return output; + } + if(c == '\\') + { + old_state = state; + state = State::in_escape; + continue; + } + if(c == '\t' || c == ' ') // new token + { + if(!tmp.empty()) + { + output.emplace_back(tmp); + } + tmp.clear(); + continue; + } + break; + + case State::in_escape: + if(c == '\n') + { + // linewrap + state = old_state; + continue; + } + state = old_state; + break; + } + + tmp += c; + } + + if(!tmp.empty()) + { + output.emplace_back(tmp); + } + + return output; +} +} + +std::vector<std::string> readDeps(const std::string& dep_file, + ctor::toolchain toolchain) +{ + if(!std::filesystem::exists(dep_file)) + { + return {}; + } + + switch(toolchain) + { + case ctor::toolchain::any: + case ctor::toolchain::none: + return {}; + + // makefile .d file based: + case ctor::toolchain::gcc: + case ctor::toolchain::clang: + return readDepsMake(dep_file); + } + + return {}; +} diff --git a/src/deps.h b/src/deps.h new file mode 100644 index 0000000..be0dfb2 --- /dev/null +++ b/src/deps.h @@ -0,0 +1,12 @@ +// -*- c++ -*- +// Distributed under the BSD 2-Clause License. +// See accompanying file LICENSE for details. +#pragma once + +#include "ctor.h" + +#include <vector> +#include <string> + +std::vector<std::string> readDeps(const std::string& dep_file, + ctor::toolchain toolchain); diff --git a/src/task_cc.cc b/src/task_cc.cc index 9a801b5..9de2657 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -12,6 +12,7 @@ #include "execute.h" #include "util.h" #include "tools.h" +#include "deps.h" TaskCC::TaskCC(const ctor::build_configuration& config_, const ctor::settings& settings_, const std::string& sourceDir_, const ctor::source& source) @@ -136,7 +137,8 @@ bool TaskCC::dirtyInner() } } - auto depList = readDeps(depsFile.string()); + auto toolchain = getToolChain(config.system); + auto depList = readDeps(depsFile.string(), toolchain); for(const auto& dep : depList) { if(!std::filesystem::exists(dep) || @@ -288,6 +290,7 @@ std::vector<std::string> TaskCC::flags() const exit(1); break; } + } std::string TaskCC::flagsString() const @@ -311,7 +314,7 @@ std::vector<std::string> TaskCC::getCompilerArgs() const { case ctor::language::c: { - append(args, c_option(toolchain, ctor::c_opt::generate_dep_tree)); + append(args, c_option(toolchain, ctor::c_opt::generate_dep_tree, depsFile.string())); if(std::filesystem::path(config.target).extension() == ".so") { @@ -353,7 +356,7 @@ std::vector<std::string> TaskCC::getCompilerArgs() const case ctor::language::cpp: { - append(args, cxx_option(toolchain, ctor::cxx_opt::generate_dep_tree)); + append(args, cxx_option(toolchain, ctor::cxx_opt::generate_dep_tree, depsFile.string())); if(std::filesystem::path(config.target).extension() == ".so") { diff --git a/src/util.cc b/src/util.cc index 73b158d..dbd4c3c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -28,66 +28,6 @@ std::string readFile(const std::string& fileName) return {bytes.data(), static_cast<std::size_t>(fileSize)}; } -std::vector<std::string> readDeps(const std::string& depFile) -{ - if(!std::filesystem::exists(depFile)) - { - return {}; - } - - auto str = readFile(depFile); - - std::vector<std::string> output; - std::string tmp; - bool start{false}; - bool in_whitespace{false}; - for(const auto& c : str) - { - if(c == '\\' || c == '\n') - { - continue; - } - - if(c == ':') - { - start = true; - continue; - } - - if(!start) - { - continue; - } - - if(c == ' ' || c == '\t') - { - if(in_whitespace) - { - continue; - } - - if(!tmp.empty()) - { - output.push_back(tmp); - } - tmp.clear(); - in_whitespace = true; - } - else - { - in_whitespace = false; - tmp += c; - } - } - - if(!tmp.empty()) - { - output.push_back(tmp); - } - - return output; -} - ctor::language languageFromExtension(const std::filesystem::path& file) { auto ext = file.extension().string(); @@ -12,7 +12,6 @@ std::string to_lower(const std::string& str); std::string readFile(const std::string& fileName); -std::vector<std::string> readDeps(const std::string& depFile); ctor::language languageFromExtension(const std::filesystem::path& file); std::string cleanUp(const std::string& path); |