]> git.tdb.fi Git - builder.git/blobdiff - source/buildinfo.cpp
Make BuildInfo uniquify things implicitly after update
[builder.git] / source / buildinfo.cpp
index 4a10872a7539cd3873e7b4afd4b6a5119603b6c6..ec8156798d70628d0597e6936ecd39622d9fff58 100644 (file)
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <algorithm>
 #include "buildinfo.h"
 
+using namespace std;
 using namespace Msp;
 
-/**
-Adds another BuildInfo to the end of this one.
-*/
-void BuildInfo::add(const BuildInfo &bi)
+namespace {
+
+/** Removes any duplicate entries from a list, leaving only the first one.  The
+order of other elements is preserved.  O(n²) efficiency. */
+void unique(StringList &l)
 {
-       cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
-       defines.insert(defines.end(), bi.defines.begin(), bi.defines.end());
+       for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
+               for(StringList::iterator j=i; j!=l.end();)
+               {
+                       if(j!=i && *j==*i)
+                               j = l.erase(j);
+                       else
+                               ++j;
+               }
+}
+
+}
+
+
+BuildInfo::BuildInfo():
+       threads(false),
+       debug(false),
+       optimize(0),
+       strip(false)
+{ }
+
+void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
+{
+       for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
+               defines[i->first] = i->second;
        incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end());
-       ldflags.insert(ldflags.end(), bi.ldflags.begin(), bi.ldflags.end());
-       libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
-       libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
+       if(level!=CHAINED)
+       {
+               libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
+               libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
+       }
+       warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
+       threads = bi.threads;
+       if(level==LOCAL)
+       {
+               debug = bi.debug;
+               optimize = bi.optimize;
+               strip = bi.strip;
+       }
+
+       unique();
 }
 
-/**
-Makes sure there are no duplicate entries in the lists.
-*/
 void BuildInfo::unique()
 {
-       unique(cflags);
-       unique(defines);
-       unique(incpath);
-       unique(ldflags);
-       unique(libpath);
-       unique(libs);
+       ::unique(incpath);
+       ::unique(libpath);
+       ::unique(libs);
+
+       for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
+       {
+               bool flag = i->compare(0, 3, "no-");
+
+               string warn = (flag ? *i : i->substr(3));
+               string no_warn = "no-"+warn;
+
+               for(StringList::iterator j=i; j!=warnings.end();)
+               {
+                       if(j!=i && (*j==warn || *j==no_warn))
+                       {
+                               flag = (*j==warn);
+                               j = warnings.erase(j);
+                       }
+                       else
+                               ++j;
+               }
+
+               *i = (flag ? warn : no_warn);
+       }
+}
+
+
+BuildInfo::Loader::Loader(BuildInfo &bi):
+       DataFile::ObjectLoader<BuildInfo>(bi)
+{
+       add("debug",    &BuildInfo::debug);
+       add("define",   &Loader::define);
+       add("incpath",  &Loader::incpath);
+       add("libpath",  &Loader::libpath);
+       add("library",  &Loader::library);
+       add("optimize", &BuildInfo::optimize);
+       add("strip",    &BuildInfo::strip);
+       add("threads",  &BuildInfo::threads);
+       add("warning",  &Loader::warning);
 }
 
-/**
-Removes any duplicate entries from a list, leaving only the first one.  The
-order of other elements is preserved.  O(n²) efficiency.
-*/
-void BuildInfo::unique(StringList &l)
+void BuildInfo::Loader::incpath(const std::string &s)
 {
-       StringList l2;
-       for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
-               if(find(l2.begin(), l2.end(), *i)==l2.end())
-                       l2.push_back(*i);
-       swap(l, l2);
+       obj.incpath.push_back(s);
 }
 
-BuildInfo::Loader::Loader(BuildInfo &bi):
-       binfo(bi)
+void BuildInfo::Loader::define(const std::string &d, const std::string &v)
 {
-       add("cflag",   &Loader::cflag);
-       add("incpath", &Loader::incpath);
-       add("define",  &Loader::define);
-       add("ldflag",  &Loader::ldflag);
-       add("libpath", &Loader::libpath);
-       add("library", &Loader::library);
+       obj.defines[d] = v;
 }
 
+void BuildInfo::Loader::libpath(const std::string &s)
+{
+       obj.libpath.push_back(s);
+}
 
+void BuildInfo::Loader::library(const std::string &s)
+{
+       obj.libs.push_back(s);
+}
+
+void BuildInfo::Loader::warning(const std::string &s)
+{
+       obj.warnings.push_back(s);
+}