diff --git a/src/loggger.h b/src/loggger.h index c32af4c..3dd0f27 100644 --- a/src/loggger.h +++ b/src/loggger.h @@ -31,7 +31,7 @@ private: void printMessage(const Message& message, bool colored = false) const; private: - bool accumulate; + const bool accumulate; const Severity currentSeverity; mutable std::list history; mutable std::mutex readMutex; diff --git a/src/main.cpp b/src/main.cpp index b478be1..6f80f35 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include -#include "project.h" +#include "collection.h" +#include "taskmanager.h" +#include "loggger.h" int main(int argc, char *argv[]) { std::string firstArg; @@ -15,20 +17,28 @@ int main(int argc, char *argv[]) { else secondArg = "./"; - Project root(firstArg, secondArg); - bool success = root.read(); - int result = -1; - if (success) { - root.info("successfully parsed project " + root.getName()); - root.info("dependencies count is " + std::to_string(root.dependenciesCount())); + std::shared_ptr logger = std::make_shared(Logger::Severity::debug); + std::shared_ptr taskManager = std::make_shared(); + std::shared_ptr collection = std::make_shared(secondArg, "", logger, taskManager); - root.discover(); - result = 0; - } + taskManager->start(); + collection->addSource(firstArg); - root.printLog(); + taskManager->wait(); + taskManager->stop(); + + // int result = -1; + // if (success) { + // root.info("successfully parsed project " + root.getName()); + // root.info("dependencies count is " + std::to_string(root.dependenciesCount())); + // + // root.discover(); + // result = 0; + // } + // + // root.printLog(); - return result; + return 0; } diff --git a/src2/collection.cpp b/src2/collection.cpp index 1e24878..1838a9c 100644 --- a/src2/collection.cpp +++ b/src2/collection.cpp @@ -19,7 +19,15 @@ Collection::Collection( downloadingSources(), readingSources(), buildingSources() -{} +{ + try { + std::filesystem::create_directories(destination); + } catch (const std::exception& e) { + fatal(e.what()); + + throw e; + } +} void Collection::addSource(const std::string& source) { if (hasSource(source)) { @@ -27,6 +35,7 @@ void Collection::addSource(const std::string& source) { return; } + debug("Adding source " + source); if (isRemote(source)) queueDownload(source); else @@ -95,7 +104,7 @@ void Collection::queueRead(const std::string& source, const std::filesystem::pat std::pair res = readingSources.emplace(std::piecewise_construct, std::forward_as_tuple(source), std::forward_as_tuple( - std::make_unique(location, std::shared_ptr(this), logger) + std::make_unique(location, shared_from_this(), logger) ) ); diff --git a/src2/collection.h b/src2/collection.h index b8c2f84..5c26fb9 100644 --- a/src2/collection.h +++ b/src2/collection.h @@ -13,7 +13,7 @@ #include "download.h" #include "taskmanager.h" -class Collection : protected Loggable { +class Collection : protected Loggable, public std::enable_shared_from_this { using Sources = std::set; using Downloads = std::map>; using Components = std::map>; diff --git a/src2/component.cpp b/src2/component.cpp index f89f203..bc337be 100644 --- a/src2/component.cpp +++ b/src2/component.cpp @@ -15,7 +15,7 @@ constexpr std::array stringStates { Component::Component( const std::filesystem::path& path, - const std::shared_ptr& collection, + const std::weak_ptr& collection, const std::shared_ptr& logger ): Loggable(logger), @@ -81,9 +81,10 @@ bool Component::readAsMason() { return errorScenario(masonScenarion.string() + " dependencies are not organized as an array"); for (const nlohmann::json& dep : deps) { + std::shared_ptr col = collection.lock(); switch (dep.type()) { case nlohmann::json::value_t::string: - collection->addSource(dep); + col->addSource(dep); break; case nlohmann::json::value_t::object: { nlohmann::json::const_iterator ditr = dep.find("path"); @@ -94,7 +95,7 @@ bool Component::readAsMason() { if (!path.is_string()) return errorScenario(masonScenarion.string() + " object of unexpected format in dependecies"); - collection->addSource(path); + col->addSource(path); } break; default: @@ -104,6 +105,7 @@ bool Component::readAsMason() { } type = mason; + info(location.string() + " seems to be a mason project"); return true; } @@ -122,6 +124,9 @@ void Component::build(const std::filesystem::path& destination, const std::strin throw WrongState(state, "build"); state = building; + + info("Building " + location.string() + " to " + destination.string()); + state = done; } Component::State Component::getState() const { diff --git a/src2/component.h b/src2/component.h index d24b034..2554e72 100644 --- a/src2/component.h +++ b/src2/component.h @@ -37,7 +37,7 @@ public: Component( const std::filesystem::path& path, - const std::shared_ptr& collection, + const std::weak_ptr& collection, const std::shared_ptr& logger ); @@ -55,7 +55,7 @@ private: private: State state; Type type; - std::shared_ptr collection; + std::weak_ptr collection; std::filesystem::path location; std::optional scenario; };