]> git.tdb.fi Git - builder.git/commitdiff
Better algorithm for ordering static libraries
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 04:36:01 +0000 (07:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 04:36:01 +0000 (07:36 +0300)
Put each static library dependency immediately after the library that
required it.  This way, if a tool includes a static library in its own
build_info (such as gnustl_static for AndroidCxxCompiler), it will be
placed last and be available for all other static libraries.

source/binary.cpp

index f3654f42f906767d2a41464117f3e2a52ceccb9b..e5968c0de411d8c548b0365e69099adfc276aa8a 100644 (file)
@@ -49,16 +49,17 @@ void Binary::find_dependencies()
        list<Target *> dep_libs;
        set<string> missing_libs;
        queue.push_back(this);
-       while(!queue.empty())
+       for(list<Target *>::iterator j=queue.begin(); j!=queue.end(); ++j)
        {
-               Target *tgt = queue.front();
-               queue.pop_front();
+               Target *tgt = *j;
 
                BuildInfo binfo;
                tgt->collect_build_info(binfo);
                if(tgt!=this)
                        static_binfo.libpath.insert(static_binfo.libpath.end(), binfo.libpath.begin(), binfo.libpath.end());
 
+               list<Target *>::iterator insert_pos = j;
+               ++insert_pos;
                for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
                {
                        if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
@@ -70,10 +71,7 @@ void Binary::find_dependencies()
                        {
                                Target *real = lib->get_real_target();
                                if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
-                               {
-                                       dep_libs.push_back(stlib);
-                                       queue.push_back(stlib);
-                               }
+                                       queue.insert(insert_pos, stlib);
                                else
                                        dep_libs.push_back(lib);
                        }
@@ -82,6 +80,9 @@ void Binary::find_dependencies()
                }
        }
 
+       queue.pop_front();
+       dep_libs.splice(dep_libs.begin(), queue);
+
        /* Add only the last occurrence of each library to the actual dependencies.
        This ensures that static library ordering is correct. */
        for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)