aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-17 22:21:13 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-17 22:21:13 +0000
commit73b53c49f0f96fab2aac2923c427520819f553a2 (patch)
tree58d348df52ee2ef35ff258e6159661b0e4c6befa
parent7aeda2e22dece9bd57c7b7db85327f9ccfbce87c (diff)
downloadpaludis-73b53c49f0f96fab2aac2923c427520819f553a2.tar.gz
paludis-73b53c49f0f96fab2aac2923c427520819f553a2.tar.xz
Make header and whitespace checks support eclasses.
-rw-r--r--paludis/repositories/e/qa/header.cc27
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc6
-rw-r--r--paludis/repositories/e/qa/whitespace.cc47
3 files changed, 53 insertions, 27 deletions
diff --git a/paludis/repositories/e/qa/header.cc b/paludis/repositories/e/qa/header.cc
index e337770..adb23c4 100644
--- a/paludis/repositories/e/qa/header.cc
+++ b/paludis/repositories/e/qa/header.cc
@@ -27,6 +27,15 @@
using namespace paludis;
+namespace
+{
+ QAMessage
+ with_id(QAMessage m, const tr1::shared_ptr<const PackageID> & id)
+ {
+ return id ? m.with_associated_id(id) : m;
+ }
+}
+
bool
paludis::erepository::header_check(
const FSEntry & entry,
@@ -35,7 +44,14 @@ paludis::erepository::header_check(
const std::string & content,
const std::string & name)
{
- Context context("When performing check '" + name + "' using default_functions on '" + stringify(*id) + "':");
+ Context context("When performing check '" + name + "' using default_functions on '" + (id ? stringify(*id) : stringify(entry)) + "':");
+
+ if (id)
+ Log::get_instance()->message(ll_debug, lc_context) << "header '"
+ << entry << "', '" << *id << "', '" << name << "'";
+ else
+ Log::get_instance()->message(ll_debug, lc_context) << "header '"
+ << entry << "', '" << name << "'";
pcrepp::Pcre::Pcre r_licence("^# Distributed under the terms of the GNU General Public License v2$");
// Match both CVS tag and extract year.[0]
@@ -48,8 +64,7 @@ paludis::erepository::header_check(
do
{
if (! (lines.size() > 1 && r_licence.search(lines[1])))
- reporter.message(QAMessage(entry, qaml_normal, name, "Wrong licence statement in line 2")
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Wrong licence statement in line 2"), id));
std::string year;
@@ -64,8 +79,7 @@ paludis::erepository::header_check(
year = r_cvs_header[0];
else
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Unknown CVS tag in line 3")
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Unknown CVS tag in line 3"), id));
break;
}
@@ -73,8 +87,7 @@ paludis::erepository::header_check(
pcrepp::Pcre::Pcre r_copyright("^# Copyright ((1999|200\\d)-)?" + year + " Gentoo Foundation$");
if (! (lines.size() > 0 && r_copyright.search(lines[0])))
- reporter.message(QAMessage(entry, qaml_normal, name, "Wrong copyright assignment in line 1, possibly date related")
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Wrong copyright assignment in line 1, possibly date related"), id));
} while (false);
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index e86bceb..e51fbdf 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -80,6 +80,12 @@ QAChecks::QAChecks() :
_imp->tree_checks_group->add_check("repo_name",
tr1::bind(repo_name_check, _2, _1, "repo_name"));
+ _imp->eclass_file_contents_checks_group->add_check("header",
+ tr1::bind(header_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "header"));
+
+ _imp->eclass_file_contents_checks_group->add_check("whitespace",
+ tr1::bind(whitespace_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "whitespace"));
+
_imp->category_dir_checks_group->add_check("stray_category_dir_files",
tr1::bind(stray_files_check, _2, _4, _1, is_stray_at_category_dir, "stray_category_dir_files"));
diff --git a/paludis/repositories/e/qa/whitespace.cc b/paludis/repositories/e/qa/whitespace.cc
index 4688ee7..eec675d 100644
--- a/paludis/repositories/e/qa/whitespace.cc
+++ b/paludis/repositories/e/qa/whitespace.cc
@@ -26,6 +26,15 @@
using namespace paludis;
+namespace
+{
+ QAMessage
+ with_id(QAMessage m, const tr1::shared_ptr<const PackageID> & id)
+ {
+ return id ? m.with_associated_id(id) : m;
+ }
+}
+
bool
paludis::erepository::whitespace_check(
const FSEntry & entry,
@@ -34,10 +43,14 @@ paludis::erepository::whitespace_check(
const std::string & content,
const std::string & name)
{
- Context context("When performing check '" + name + "' using whitespace_check on '" + stringify(*id) + "':");
+ Context context("When performing check '" + name + "' using whitespace_check on '" + (id ? stringify(*id) : stringify(entry)) + "':");
- Log::get_instance()->message(ll_debug, lc_context) << "whitespace '"
- << entry << "', '" << *id << "', '" << name << "'";
+ if (id)
+ Log::get_instance()->message(ll_debug, lc_context) << "whitespace '"
+ << entry << "', '" << *id << "', '" << name << "'";
+ else
+ Log::get_instance()->message(ll_debug, lc_context) << "whitespace '"
+ << entry << "', '" << name << "'";
std::list<std::string> lines;
tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
@@ -53,16 +66,14 @@ paludis::erepository::whitespace_check(
if (err_count >= 3)
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Skipping further whitespace checks")
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Skipping further whitespace checks"), id));
break;
}
if (' ' == l->at(0))
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Spaces for indenting on line "
- + stringify(line) + ": " + strip_leading(*l, " \t"))
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Spaces for indenting on line "
+ + stringify(line) + ": " + strip_leading(*l, " \t")), id));
++err_count;
continue;
}
@@ -71,25 +82,22 @@ paludis::erepository::whitespace_check(
std::string::size_type p(l->find_first_of("\t"));
if (std::string::npos == p)
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Indent followed by no content on line "
- + stringify(line) + ": " + strip_leading(*l, " \t"))
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Indent followed by no content on line "
+ + stringify(line) + ": " + strip_leading(*l, " \t")), id));
++err_count;
continue;
}
else if (' ' == l->at(p))
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Mixed tabs and spaces for indenting on line "
- + stringify(line) + ": " + strip_leading(*l, " \t"))
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Mixed tabs and spaces for indenting on line "
+ + stringify(line) + ": " + strip_leading(*l, " \t")), id));
++err_count;
continue;
}
else if (std::string::npos != l->find(p, '\t'))
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Non-intent tab on line "
- + stringify(line) + ": " + strip_leading(*l, " \t"))
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Non-intent tab on line "
+ + stringify(line) + ": " + strip_leading(*l, " \t")), id));
++err_count;
continue;
}
@@ -97,9 +105,8 @@ paludis::erepository::whitespace_check(
if (' ' == l->at(l->length() - 1) || '\t' == l->at(l->length() - 1))
{
- reporter.message(QAMessage(entry, qaml_minor, name, "Trailing space on line "
- + stringify(line) + ": " + strip_leading(*l, " \t"))
- .with_associated_id(id));
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Trailing space on line "
+ + stringify(line) + ": " + strip_leading(*l, " \t")), id));
++err_count;
continue;
}