]> git.tdb.fi Git - builder.git/commitdiff
Move to a more abstract way of defining warnings
authorMikko Rasa <tdb@tdb.fi>
Mon, 16 Jul 2012 23:27:15 +0000 (02:27 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 16 Jul 2012 23:30:04 +0000 (02:30 +0300)
builderrc
source/builder.cpp
source/builder.h
source/buildinfo.cpp
source/buildinfo.h
source/gnucompiler.cpp
source/sourcepackage.cpp

index 311be8d21a8fe586071d744dd5d15d9e66cc7a9d..f8f87888a0058e6492bd503fa0baecbc8a93bffa 100644 (file)
--- a/builderrc
+++ b/builderrc
@@ -91,6 +91,8 @@ build_type "debug"
        {
                debug true;
                define "DEBUG" "1";
+               warning_level 3;
+               fatal_warnings true;
        };
 };
 
@@ -99,7 +101,10 @@ build_type "optimized_debug"
        build_info
        {
                debug true;
+               define "DEBUG" "1";
                optimize 2;
+               warning_level 3;
+               fatal_warnings true;
        };
 };
 
@@ -109,6 +114,7 @@ build_type "release"
        {
                optimize 3;
                strip true;
+               warning_level 1;
        };
 };
 
@@ -119,5 +125,6 @@ build_type "static_release"
                optimize 3;
                strip true;
                libmode STATIC;
+               warning_level 1;
        };
 };
index 2f71f1a74c2b3e8ccbd93bf235618a07cdd1ce99..7b222df4997c1f05e31febfef670a10d46fc80dd 100644 (file)
@@ -90,7 +90,6 @@ Builder::Builder(int argc, char **argv):
        getopt.add_option(     "max-depth",  max_depth,     GetOpt::REQUIRED_ARG).set_help("Show up to NUM levels in analysis..", "NUM");
        getopt.add_option(     "prefix",     prfx,          GetOpt::REQUIRED_ARG).set_help("Install things to DIR.", "DIR");
        getopt.add_option(     "tempdir",    temp_str,      GetOpt::REQUIRED_ARG).set_help("Store temporary files in DIR.", "DIR");
-       getopt.add_option(     "warnings",   cmdline_warn,  GetOpt::REQUIRED_ARG).set_help("Compiler warnings to use.", "LIST");
        usagemsg = getopt.generate_usage(argv[0])+" [<target> ...]";
        helpmsg = getopt.generate_help();
        getopt(argc, argv);
@@ -200,17 +199,6 @@ Builder::Builder(int argc, char **argv):
                build_type = &i->second;
        }
 
-       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());
-       }
-
        toolchain.add_tool(new GnuCCompiler(*this, *current_arch));
        toolchain.add_tool(new GnuCxxCompiler(*this, *current_arch));
        toolchain.add_tool(new GnuLinker(*this, *current_arch));
index eecbb984304225e1768f683c4ee154e80a33b74d..933fbb05599dd66a01de8d8a147411a9a3c94e0f 100644 (file)
@@ -84,7 +84,6 @@ private:
        bool create_makefile;
        Msp::FS::Path prefix;
        Msp::FS::Path tempdir;
-       StringList warnings;
 
        static std::string usagemsg;
        static std::string helpmsg;
@@ -109,7 +108,6 @@ public:
        const Architecture &get_native_arch() const { return native_arch; }
        const Msp::FS::Path &get_prefix() const { return prefix; }
        const Msp::FS::Path &get_temp_directory() const { return tempdir; }
-       const StringList &get_warnings() const { return warnings; }
 
        const Toolchain &get_toolchain() const { return toolchain; }
        VirtualFileSystem &get_vfs() { return vfs; }
index 4c4029ea24f757d97ccc897c4ee73dc124f9349b..12fcac5286558e0963b97032842076c3f5feb012 100644 (file)
@@ -31,7 +31,9 @@ BuildInfo::BuildInfo():
        threads(false),
        debug(false),
        optimize(0),
-       strip(false)
+       strip(false),
+       warning_level(0),
+       fatal_warnings(false)
 { }
 
 void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
@@ -44,7 +46,6 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
                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)
        {
@@ -52,6 +53,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
                debug = bi.debug;
                optimize = bi.optimize;
                strip = bi.strip;
+               warning_level = bi.warning_level;
+               fatal_warnings = bi.fatal_warnings;
        }
 
        unique();
@@ -62,27 +65,6 @@ void BuildInfo::unique()
        ::unique(incpath);
        ::unique(libpath);
        ::unique(libs);
-
-       for(WordList::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(WordList::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);
-       }
 }
 
 
@@ -98,7 +80,8 @@ BuildInfo::Loader::Loader(BuildInfo &bi):
        add("optimize", &BuildInfo::optimize);
        add("strip",    &BuildInfo::strip);
        add("threads",  &BuildInfo::threads);
-       add("warning",  &Loader::warning);
+       add("warning_level", &BuildInfo::warning_level);
+       add("fatal_warnings", &BuildInfo::fatal_warnings);
 }
 
 void BuildInfo::Loader::incpath(const string &s)
@@ -121,11 +104,6 @@ void BuildInfo::Loader::library(const string &s)
        obj.libs.push_back(s);
 }
 
-void BuildInfo::Loader::warning(const string &s)
-{
-       obj.warnings.push_back(s);
-}
-
 
 void operator>>(LexicalConverter &conv, BuildInfo::LibraryMode &libmode)
 {
index 9805e0a2ec0aa5d1c6f140d775e1c68019758225..8bedcec4c7506d4a0209b92ef33f269948679ac0 100644 (file)
@@ -30,7 +30,6 @@ public:
                void define(const std::string &, const std::string &);
                void libpath(const std::string &);
                void library(const std::string &);
-               void warning(const std::string &);
        };
        
        enum UpdateLevel
@@ -49,11 +48,12 @@ public:
        PathList libpath;
        WordList libs;
        LibraryMode libmode;
-       WordList warnings;
        bool threads;
        bool debug;
        int optimize;
        bool strip;
+       unsigned warning_level;
+       bool fatal_warnings;
 
        BuildInfo();
 
index a6d27052e292e032123e4d5f1e7fbb94aa03c333..e2c5c0e71a494e7bb11079a5be0f76725f135b93 100644 (file)
@@ -47,8 +47,37 @@ Task *GnuCompiler::run(const Target &target) const
        argv.push_back("-c");
 
        const BuildInfo &binfo = comp.get_build_info();
-       for(BuildInfo::WordList::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i)
-               argv.push_back("-W"+*i);
+       if(binfo.warning_level>=1)
+       {
+               argv.push_back("-Wall");
+               if(binfo.warning_level>=2)
+               {
+                       argv.push_back("-Wextra");
+                       argv.push_back("-Wundef");
+               }
+               if(binfo.warning_level>=3)
+               {
+                       argv.push_back("-pedantic");
+                       argv.push_back("-Wno-long-long");
+                       argv.push_back("-Wshadow");
+                       argv.push_back("-Winline");
+                       if(tag=="CC")
+                       {
+                               argv.push_back("-Wc++-compat");
+                               argv.push_back("-Wstrict-prototypes");
+                       }
+               }
+               if(binfo.warning_level>=4)
+               {
+                       // Some truly paranoid warnings
+                       argv.push_back("-Wstrict-overflow=4");
+                       argv.push_back("-Wfloat-equal");
+                       argv.push_back("-Wconversion");
+                       argv.push_back("-Wwrite-strings");
+               }
+               if(binfo.fatal_warnings)
+                       argv.push_back("-Werror");
+       }
        for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
                argv.push_back("-I"+i->str());
        for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
index 3b0b296c2bdb1fb8f1955479f4f0929d15cc746e..4b45bb73b643a5f7b3934f51bed4a40b2a1ad036 100644 (file)
@@ -68,10 +68,6 @@ void SourcePackage::create_build_info()
        if(build_type)
                build_info.update_from(build_type->get_build_info());
 
-       // 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());
-
        build_info.incpath.push_back((builder.get_prefix()/"include").str());
        build_info.libpath.push_back((builder.get_prefix()/"lib").str());