summaryrefslogtreecommitdiff
path: root/src/task_cc.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-10-10 18:57:13 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-10-10 18:57:13 +0200
commit922412f5dc975b423757c1e248eac2813e48acb2 (patch)
treea3b15d185627d3c8b845beadee603c44b263e1d0 /src/task_cc.cc
parente73ee708292aac55070701ff0157db4eab6c06f4 (diff)
Move some common functions to util.cc
Diffstat (limited to 'src/task_cc.cc')
-rw-r--r--src/task_cc.cc108
1 files changed, 1 insertions, 107 deletions
diff --git a/src/task_cc.cc b/src/task_cc.cc
index dfda75d..73297f2 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -10,113 +10,7 @@
#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);
-}
-
-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;
-}
-
-Language languageFromExtension(const std::filesystem::path& file)
-{
- auto ext = file.extension().string();
- if(ext == ".c")
- {
- return Language::C;
- }
-
- if(ext == ".C" ||
- ext == ".cc" ||
- ext == ".cpp" ||
- ext == ".CPP" ||
- ext == ".c++" ||
- ext == ".cp" ||
- ext == ".cxx")
- {
- return Language::Cpp;
- }
-
- if(ext == ".s" ||
- ext == ".S" ||
- ext == ".asm")
- {
- return Language::Asm;
- }
-
- std::cerr << "Could not deduce language from " << file.string() << "\n";
- exit(1);
- return {};
-}
-} // namespace ::
+#include "util.h"
TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
const std::string& sourceDir, const Source& source)