diff options
Diffstat (limited to 'Builder.cpp')
-rw-r--r-- | Builder.cpp | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/Builder.cpp b/Builder.cpp index cc756f2..4850be3 100644 --- a/Builder.cpp +++ b/Builder.cpp @@ -55,7 +55,13 @@ namespace { // iterate over all <build> elements for (const auto& element: ptree.get_child(topelement)) { if (is_match(element, target)) { - result.push_back(element.second.get<std::string>("name")); + fs::path target_name{element.second.get<std::string>("name")}; + result.push_back(target_name); + + // special case dynamic lib: add links automatically + if (is_dynamic_lib(target_name)) { + result.push_back(soname_short(target_name)); + } } } @@ -285,22 +291,33 @@ std::vector<fs::path> Builder::make_depfile_from(const fs::path& p) const return deps_from_depfile(depfile); } -std::unordered_map<fs::path, std::vector<fs::path>> Builder::get_dependencies(const pt::ptree& ptree) const +std::unordered_map<fs::path, std::vector<fs::path>> Builder::get_dependencies(const pt::ptree& ptree, bool include_sources) const { std::unordered_map<fs::path, std::vector<fs::path>> dependencies; for (const auto& element: ptree.get_child(topelement)) { if (is_match(element, _target)) { - dependencies.emplace(get_target(element.second), get_objects(element.second)); - - std::vector<fs::path> sources{get_sources(element.second)}; - for (const auto& p: sources) { - fs::path p_obj{p}; - p_obj.replace_extension("o"); - std::vector<fs::path> deps {make_depfile_from(p)}; - // keep .d files for now to speed dependencies detection on following runs - //fs::remove(depfile_name_from(p)); - dependencies.emplace(p_obj, deps); + // add target + fs::path target{get_target(element.second)}; + dependencies.emplace(target, get_objects(element.second)); + + // add dynamic lib links + if (is_dynamic_lib(target)) { + dependencies.emplace(soname_shorter(target), std::vector<fs::path>{{target}}); + dependencies.emplace(soname_short(target), std::vector<fs::path>{{soname_shorter(target)}}); + } + + if (include_sources) { + // add source dependencies of *.o + std::vector<fs::path> sources{get_sources(element.second)}; + for (const auto& p: sources) { + fs::path p_obj{p}; + p_obj.replace_extension("o"); + std::vector<fs::path> deps {make_depfile_from(p)}; + // keep .d files for now to speed dependencies detection on following runs + //fs::remove(depfile_name_from(p)); + dependencies.emplace(p_obj, deps); + } } } } @@ -397,9 +414,8 @@ void Builder::build_filelist() { } } -// build everything according to specified configuration -void Builder::build() { - _dependencies = get_dependencies(_ptree); +std::unordered_set<fs::path> Builder::get_buildlist(std::function<bool(const fs::path&)> outdated_pred) { + std::unordered_set<fs::path> result; // create build list by depth-first search //std::cout << "Calculating build list..." << std::endl; @@ -418,11 +434,20 @@ void Builder::build() { container.push(i); } - if (is_outdated(current) && is_buildable_by_extension(current)) { - _buildlist.insert(current); + if (outdated_pred(current) && is_buildable_by_extension(current)) { + result.insert(current); } } + return result; +} + +// build everything according to specified configuration +void Builder::build() { + _dependencies = get_dependencies(_ptree); + + _buildlist = get_buildlist([&](const fs::path& i)->bool{return is_outdated(i);}); + //std::cout << "Build list:" << std::endl; //for (auto &i: _buildlist) { // std::cout << " " << i << std::endl; @@ -431,9 +456,16 @@ void Builder::build() { build_filelist(); } -void Builder::clean() const { - std::vector<fs::path> cleanlist{_all_objects}; - std::copy(_all_targets.cbegin(), _all_targets.cend(), std::back_inserter(cleanlist)); +void Builder::clean() { + _dependencies = get_dependencies(_ptree, false); + std::unordered_set<fs::path> cleanlist{get_buildlist([](const fs::path& i)->bool{ return true;})}; + + std::unordered_set<fs::path> add; + for (const auto& i: cleanlist) { + std::vector<fs::path> deps{dependencies_of(i)}; + std::copy(deps.begin(), deps.end(), std::inserter(add, add.begin())); + } + std::copy(add.begin(), add.end(), std::inserter(cleanlist, cleanlist.begin())); std::vector<std::string> commands; for (auto &i: cleanlist) { |