]> git.tdb.fi Git - builder.git/blobdiff - source/buildinfo.cpp
Make warnings configurable through build_info and command line
[builder.git] / source / buildinfo.cpp
index f96820baee83f3886e33189d5900a1a17d346daa..36be492ac0724f1757fb56b6b2b5b9a825ff2981 100644 (file)
@@ -1,8 +1,19 @@
-#include <msp/algo.h>
+/* $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)
 {
        cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
@@ -11,8 +22,12 @@ void BuildInfo::add(const BuildInfo &bi)
        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());
+       warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
 }
 
+/**
+Makes sure there are no duplicate entries in the lists.
+*/
 void BuildInfo::unique()
 {
        unique(cflags);
@@ -21,15 +36,43 @@ void BuildInfo::unique()
        unique(ldflags);
        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);
+       }
 }
 
+/**
+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)
 {
-       StringList l2;
        for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
-               if(!contains(l2, *i))
-                       l2.push_back(*i);
-       swap(l, l2);
+               for(StringList::iterator j=i; j!=l.end();)
+               {
+                       if(j!=i && *j==*i)
+                               j=l.erase(j);
+                       else
+                               ++j;
+               }
 }
 
 BuildInfo::Loader::Loader(BuildInfo &bi):
@@ -41,6 +84,7 @@ BuildInfo::Loader::Loader(BuildInfo &bi):
        add("ldflag",  &Loader::ldflag);
        add("libpath", &Loader::libpath);
        add("library", &Loader::library);
+       add("warning", &Loader::warning);
 }