From: Mikko Rasa Date: Wed, 28 Dec 2022 12:19:19 +0000 (+0200) Subject: Refactor VsSolutionFile::find_dependencies as recursive X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c22188be255cebc35998406df4072629283b8ba5;p=builder.git Refactor VsSolutionFile::find_dependencies as recursive This avoids an issue with inserting elements into a vector while iterating over it. --- diff --git a/plugins/builtin/vssolutionfile.cpp b/plugins/builtin/vssolutionfile.cpp index 691e1c6..38908df 100644 --- a/plugins/builtin/vssolutionfile.cpp +++ b/plugins/builtin/vssolutionfile.cpp @@ -14,18 +14,18 @@ VsSolutionFile::VsSolutionFile(Builder &b, const SourcePackage &p): void VsSolutionFile::find_dependencies() { - if(FileTarget *project = builder.get_vfs().get_target(package->get_source_directory()/(package->get_name()+".vcxproj"))) - add_dependency(*project); + find_dependencies(*package); +} - Package::Requirements reqs = package->get_required_packages(); - for(auto i=reqs.begin(); i!=reqs.end(); ++i) - if(const SourcePackage *spkg = dynamic_cast(*i)) +void VsSolutionFile::find_dependencies(const SourcePackage &spkg) +{ + if(FileTarget *project = builder.get_vfs().get_target(spkg.get_source_directory()/(spkg.get_name()+".vcxproj"))) + if(!any_equals(depends, static_cast(project))) { - if(FileTarget *project = builder.get_vfs().get_target(spkg->get_source_directory()/(spkg->get_name()+".vcxproj"))) - add_dependency(*project); + add_dependency(*project); - for(Package *r: spkg->get_required_packages()) - if(!any_equals(reqs, r)) - reqs.push_back(r); + for(const Package *r: spkg.get_required_packages()) + if(const SourcePackage *s = dynamic_cast(r)) + find_dependencies(*s); } } diff --git a/plugins/builtin/vssolutionfile.h b/plugins/builtin/vssolutionfile.h index 402caa7..2c1e602 100644 --- a/plugins/builtin/vssolutionfile.h +++ b/plugins/builtin/vssolutionfile.h @@ -11,6 +11,7 @@ public: const char *get_type() const override { return "VsSolutionFile"; } protected: void find_dependencies() override; + void find_dependencies(const SourcePackage &); }; #endif