X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=inline;f=source%2Flib%2Fbuilder.cpp;h=f979d28f38ce35c6f01976cc5109886f83b50ab7;hb=ba5078a4334ef419aeb1949190a743a05037750c;hp=738361bce2d3553db15844bc19b7e6e5a7353924;hpb=b7ecf9d6203492a43bf98e7c611b81c5594cbd00;p=builder.git diff --git a/source/lib/builder.cpp b/source/lib/builder.cpp index 738361b..f979d28 100644 --- a/source/lib/builder.cpp +++ b/source/lib/builder.cpp @@ -5,11 +5,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include "binarypackage.h" @@ -46,7 +48,11 @@ void Builder::load_plugins() using CreateFunc = Plugin *(Builder &); FS::Path plugins_dir = FS::get_sys_lib_dir(); + if(!FS::exists(plugins_dir)) + return; + logger->log("files", "Traversing %s", plugins_dir); + vector unordered_plugins; for(const string &f: list_filtered(plugins_dir, "\\.dlm$")) { LoadedPlugin plugin; @@ -69,7 +75,7 @@ void Builder::load_plugins() if(plugin.plugin) { logger->log("plugins", "Loaded plugin %s", f); - plugins.emplace_back(move(plugin)); + unordered_plugins.emplace_back(move(plugin)); continue; } else @@ -80,6 +86,45 @@ void Builder::load_plugins() logger->log("plugins", "Failed to initialize plugin %s: %s", f, exc.what()); } } + + add_plugins(unordered_plugins); +} + +void Builder::add_plugins(vector &unordered_plugins) +{ + auto have_plugin = [this](const string &r){ + return any_of(plugins.begin(), plugins.end(), [&r](const LoadedPlugin &p){ return FS::basepart(FS::basename(p.path))==r; }); + }; + + while(!unordered_plugins.empty()) + { + bool any_added = false; + for(auto i=unordered_plugins.begin(); i!=unordered_plugins.end(); ) + { + const vector &required = i->plugin->get_required_plugins(); + if(all_of(required.begin(), required.end(), have_plugin)) + { + plugins.push_back(move(*i)); + i = unordered_plugins.erase(i); + any_added = true; + } + else + ++i; + } + + if(!any_added) + break; + } + + for(const LoadedPlugin &p: unordered_plugins) + { + vector missing; + for(const string &r: p.plugin->get_required_plugins()) + if(!have_plugin(r)) + missing.push_back(r); + logger->log("plugins", "Missing required plugins for plugin %s: %s", + FS::basename(p.path), join(missing.begin(), missing.end())); + } } void Builder::set_architecture(const string &name) @@ -242,6 +287,7 @@ void Builder::save_caches() int Builder::build(unsigned jobs, bool dry_run, bool show_progress) { unsigned total = build_graph.count_rebuild_targets(); + Time::TimeStamp start_time = Time::now(); if(!total) { @@ -253,6 +299,7 @@ int Builder::build(unsigned jobs, bool dry_run, bool show_progress) vector tasks; unsigned count = 0; + Time::TimeDelta sum_time; bool fail = false; bool finish = false; @@ -310,6 +357,13 @@ int Builder::build(unsigned jobs, bool dry_run, bool show_progress) { ++count; + const vector &targets = tasks[i]->get_targets(); + if(!targets.empty()) + { + sum_time += tasks[i]->get_duration(); + get_logger().log("timings", "%s built in %s", targets.front()->get_name(), tasks[i]->get_duration()); + } + delete tasks[i]; tasks.erase(tasks.begin()+i); if(status==Task::ERROR) @@ -330,6 +384,9 @@ int Builder::build(unsigned jobs, bool dry_run, bool show_progress) else if(show_progress) get_logger().log("summary", "Build complete"); + Time::TimeStamp end_time = Time::now(); + get_logger().log("timings", "Build took %s, with a total %s spent on tasks", end_time-start_time, sum_time); + return fail; } @@ -374,6 +431,18 @@ Builder::LoadedPlugin::LoadedPlugin(LoadedPlugin &&other): other.plugin = 0; } +Builder::LoadedPlugin &Builder::LoadedPlugin::operator=(LoadedPlugin &&other) +{ + delete plugin; + delete module; + path = move(other.path); + module = other.module; + plugin = other.plugin; + other.module = 0; + other.plugin = 0; + return *this; +} + Builder::LoadedPlugin::~LoadedPlugin() { delete plugin;