From: Mikko Rasa Date: Sat, 11 Oct 2014 04:36:01 +0000 (+0300) Subject: Better algorithm for ordering static libraries X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=91027467faed55accfc79bda525e10d1395cb2a9;p=builder.git Better algorithm for ordering static libraries 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. --- diff --git a/source/binary.cpp b/source/binary.cpp index f3654f4..e5968c0 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -49,16 +49,17 @@ void Binary::find_dependencies() list dep_libs; set missing_libs; queue.push_back(this); - while(!queue.empty()) + for(list::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::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(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::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)