From 7567502e17be7704d58ced2f49703fcf71c7ef38 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 11 Jun 2008 14:46:05 +0000 Subject: [PATCH] Make warnings configurable through build_info and command line Some minor fixes --- source/builder.cpp | 20 ++++++++++++++++++-- source/builder.h | 2 ++ source/buildinfo.cpp | 35 +++++++++++++++++++++++++++++++---- source/buildinfo.h | 2 ++ source/compile.cpp | 2 ++ source/sourcepackage.cpp | 9 +++------ 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index e4f7e58..147371c 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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 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< ...]"; + cerr<<"Usage: "< ...]\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"; } } diff --git a/source/builder.h b/source/builder.h index d19511c..010b93f 100644 --- a/source/builder.h +++ b/source/builder.h @@ -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(); diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index 5164ab0..36be492 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -8,6 +8,7 @@ Distributed under the LGPL #include #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); } diff --git a/source/buildinfo.h b/source/buildinfo.h index d891439..9b208c1 100644 --- a/source/buildinfo.h +++ b/source/buildinfo.h @@ -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(); diff --git a/source/compile.cpp b/source/compile.cpp index efa20ef..c98353b 100644 --- a/source/compile.cpp +++ b/source/compile.cpp @@ -37,6 +37,8 @@ Compile::Compile(Builder &b, const ObjectFile &obj): argv.push_back("-c"); const BuildInfo &binfo=comp.get_build_info(); + for(list::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i) + argv.push_back("-W"+*i); for(list::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i) argv.push_back(*i); for(list::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i) diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 8cff0df..d814203 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -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(); -- 2.43.0