]> git.tdb.fi Git - builder.git/commitdiff
Refactor VsSolutionFile::find_dependencies as recursive
authorMikko Rasa <tdb@tdb.fi>
Wed, 28 Dec 2022 12:19:19 +0000 (14:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 28 Dec 2022 14:11:06 +0000 (16:11 +0200)
This avoids an issue with inserting elements into a vector while
iterating over it.

plugins/builtin/vssolutionfile.cpp
plugins/builtin/vssolutionfile.h

index 691e1c60b8d82660c72644cd5b2aee021513aa18..38908df99ff7c842815db0363330992137328a11 100644 (file)
@@ -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<const SourcePackage *>(*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<Target *>(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<const SourcePackage *>(r))
+                                       find_dependencies(*s);
                }
 }
index 402caa758d5423d23840ebbb82469536cd94db09..2c1e602a333c646c02767db738cea163e6c301c3 100644 (file)
@@ -11,6 +11,7 @@ public:
        const char *get_type() const override { return "VsSolutionFile"; }
 protected:
        void find_dependencies() override;
+       void find_dependencies(const SourcePackage &);
 };
 
 #endif