]> git.tdb.fi Git - builder.git/commitdiff
Make warnings configurable through build_info and command line
authorMikko Rasa <tdb@tdb.fi>
Wed, 11 Jun 2008 14:46:05 +0000 (14:46 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 11 Jun 2008 14:46:05 +0000 (14:46 +0000)
Some minor fixes

source/builder.cpp
source/builder.h
source/buildinfo.cpp
source/buildinfo.h
source/compile.cpp
source/sourcepackage.cpp

index e4f7e580f9a1b15fdf2a52eba51d777884f54099..147371cd22519524683df31378fc0b6597d118f7 100644 (file)
@@ -59,6 +59,7 @@ Builder::Builder(int argc, char **argv):
        string   work_dir;
        bool     full_paths=false;
        unsigned max_depth=5;
+       StringList cmdline_warn;
 
        GetOpt getopt;
        getopt.add_option('a', "analyze",    analyze_mode, GetOpt::REQUIRED_ARG);
@@ -80,6 +81,7 @@ Builder::Builder(int argc, char **argv):
        //getopt.add_option(     "makefile",   create_makefile, GetOpt::NO_ARG);
        getopt.add_option(     "max-depth",  max_depth,    GetOpt::REQUIRED_ARG);
        getopt.add_option(     "prefix",     prefix,       GetOpt::REQUIRED_ARG);
+       getopt.add_option(     "warnings",   cmdline_warn, GetOpt::REQUIRED_ARG);
        getopt(argc, argv);
 
        if(!analyze_mode.empty())
@@ -137,6 +139,17 @@ Builder::Builder(int argc, char **argv):
                else
                        prefix=(get_home_dir()/"local"/current_arch).str();
        }
+
+       warnings.push_back("all");
+       warnings.push_back("extra");
+       warnings.push_back("shadow");
+       warnings.push_back("pointer-arith");
+       warnings.push_back("error");
+       for(StringList::iterator i=cmdline_warn.begin(); i!=cmdline_warn.end(); ++i)
+       {
+               vector<string> warns=split(*i, ',');
+               warnings.insert(warnings.end(), warns.begin(), warns.end());
+       }
 }
 
 /**
@@ -447,7 +460,7 @@ void Builder::usage(const char *reason, const char *argv0, bool brief)
                cerr<<reason<<'\n';
 
        if(brief)
-               cerr<<"Usage: "<<argv0<<" [-a|--analyze MODE] [-b|--build] [-c|--clean] [-f|--file FILE] [-h|--help] [-j|--jobs NUM] [-n||--dry-run] [-v|--verbose] [-A|--conf-all] [-B|--build-all] [-C|--chdir DIRECTORY] [-W|--what-if FILE] [--chrome] [--conf-only] [--full-paths] [--max-depth NUM] [<target> ...]";
+               cerr<<"Usage: "<<argv0<<" [-a|--analyze MODE] [-b|--build] [-c|--clean] [-f|--file FILE] [-h|--help] [-j|--jobs NUM] [-n||--dry-run] [-v|--verbose] [-A|--conf-all] [-B|--build-all] [-C|--chdir DIRECTORY] [-W|--what-if FILE] [--chrome] [--conf-only] [--full-paths] [--max-depth NUM] [<target> ...]\n";
        else
        {
                cerr<<
@@ -467,10 +480,13 @@ void Builder::usage(const char *reason, const char *argv0, bool brief)
                        "  -C, --chdir DIR     Change to DIR before doing anything else.\n"
                        "  -P, --progress      Display progress while building.\n"
                        "  -W, --what-if FILE  Pretend that FILE has changed.\n"
+                       "  --arch ARCH         Architecture to build for.\n"
                        "  --conf-only         Stop after configuring packages.\n"
                        "  --full-paths        Output full paths in analysis.\n"
                        //"  --makefile          Create a makefile for this package.\n"
-                       "  --max-depth NUM     Maximum depth to show in analysis.\n";
+                       "  --max-depth NUM     Maximum depth to show in analysis.\n"
+                       "  --prefix DIR        Directory to install things to.\n"
+                       "  --warnings LIST     Compiler warnings to use.\n";
        }
 }
 
index d19511c87e8932a736f3fc0105ff513c4916f429..010b93fcc5ddec56044e1e3f6d2cc2d111d77476 100644 (file)
@@ -45,6 +45,7 @@ public:
        const Architecture &get_architecture(const std::string &) const;
        const Architecture &get_current_arch() const;
        const std::string &get_prefix() const { return prefix; }
+       const StringList &get_warnings() const { return warnings; }
        void     apply_profile_template(Config &, const std::string &) const;
        void     add_target(Target *);
        void     problem(const std::string &, const std::string &);
@@ -113,6 +114,7 @@ private:
        bool            create_makefile;
        std::string     current_arch;
        std::string     prefix;
+       StringList      warnings;
 
        int    load_build_file(const Msp::Path &);
        int    create_targets();
index 5164ab08841c1ceed879f6fc5e4939770cd85cca..36be492ac0724f1757fb56b6b2b5b9a825ff2981 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the LGPL
 #include <algorithm>
 #include "buildinfo.h"
 
+using namespace std;
 using namespace Msp;
 
 /**
@@ -21,6 +22,7 @@ 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());
 }
 
 /**
@@ -34,6 +36,27 @@ 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);
+       }
 }
 
 /**
@@ -42,11 +65,14 @@ 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(find(l2.begin(), l2.end(), *i)==l2.end())
-                       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):
@@ -58,6 +84,7 @@ BuildInfo::Loader::Loader(BuildInfo &bi):
        add("ldflag",  &Loader::ldflag);
        add("libpath", &Loader::libpath);
        add("library", &Loader::library);
+       add("warning", &Loader::warning);
 }
 
 
index d891439377c9d0ba440a4e8568a981d5af82deb4..9b208c1709bcd88acc882d8744ef9b53f6c63d1b 100644 (file)
@@ -33,6 +33,7 @@ public:
                void ldflag(const std::string &s)  { binfo.ldflags.push_back(s); }
                void libpath(const std::string &s) { binfo.libpath.push_back(s); }
                void library(const std::string &s) { binfo.libs.push_back(s); }
+               void warning(const std::string &s) { binfo.warnings.push_back(s); }
        };
        
        StringList cflags;
@@ -41,6 +42,7 @@ public:
        StringList ldflags;
        StringList libpath;
        StringList libs;
+       StringList warnings;
 
        void add(const BuildInfo &);
        void unique();
index efa20efea3a6af31b9003a99396ac66be018f992..c98353ba04cc6726dc171c9a84bf30380a70aee0 100644 (file)
@@ -37,6 +37,8 @@ Compile::Compile(Builder &b, const ObjectFile &obj):
        argv.push_back("-c");
 
        const BuildInfo &binfo=comp.get_build_info();
+       for(list<string>::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i)
+               argv.push_back("-W"+*i);
        for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
                argv.push_back(*i);
        for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
index 8cff0dfe535b001fc8fa4f57289d87c0637798a6..d8142038d1e65756f5ad7ccae68f693dc86bf525 100644 (file)
@@ -172,12 +172,9 @@ void SourcePackage::create_build_info()
                export_binfo.defines.insert(export_binfo.defines.end(), ebi.defines.begin(), ebi.defines.end());
        }
 
-       build_info.cflags.push_back("-Wall");
-       build_info.cflags.push_back("-Wshadow");
-       build_info.cflags.push_back("-Wextra");
-       build_info.cflags.push_back("-Wpointer-arith");
-       //build_info.cflags.push_back("-Wconversion");
-       build_info.cflags.push_back("-Werror");
+       // XXX Currently, a package-specific settings will override cmdline.  This might or might not be desirable.
+       const StringList &warnings=builder.get_warnings();
+       build_info.warnings.insert(build_info.warnings.begin(), warnings.begin(), warnings.end());
 
        unsigned flags=get_install_flags();