From: Mikko Rasa Date: Mon, 16 Jul 2012 23:27:15 +0000 (+0300) Subject: Move to a more abstract way of defining warnings X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=95d5743c0f2a0dd8b56928525b8caa5f6ee8cc1d;p=builder.git Move to a more abstract way of defining warnings --- diff --git a/builderrc b/builderrc index 311be8d..f8f8788 100644 --- 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; }; }; diff --git a/source/builder.cpp b/source/builder.cpp index 2f71f1a..7b222df 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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])+" [ ...]"; 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 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)); diff --git a/source/builder.h b/source/builder.h index eecbb98..933fbb0 100644 --- a/source/builder.h +++ b/source/builder.h @@ -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; } diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index 4c4029e..12fcac5 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -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) { diff --git a/source/buildinfo.h b/source/buildinfo.h index 9805e0a..8bedcec 100644 --- a/source/buildinfo.h +++ b/source/buildinfo.h @@ -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(); diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index a6d2705..e2c5c0e 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -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) diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 3b0b296..4b45bb7 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -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());