aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-13 22:20:45 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-13 22:20:45 +0000
commit204660b4ce24c236f92e911c61e7ff557af29852 (patch)
treeb8229f5d41dc718ffbbd6e33b99ce31b294e75e3
parent06b60937b02e4c817b035656ab81d4254cde8dba (diff)
downloadpaludis-204660b4ce24c236f92e911c61e7ff557af29852.tar.gz
paludis-204660b4ce24c236f92e911c61e7ff557af29852.tar.xz
More checks. Start using them in qualudis.
-rw-r--r--paludis/args/Makefile.am2
-rw-r--r--paludis/qa/check_result.cc8
-rw-r--r--paludis/qa/check_result.hh2
-rw-r--r--paludis/qa/check_result_TEST.cc7
-rw-r--r--paludis/qa/package_name_check_TEST.cc104
-rw-r--r--src/qualudis/Makefile.am9
-rw-r--r--src/qualudis/check_deps_exist.cc149
-rw-r--r--src/qualudis/check_deps_exist.hh28
-rw-r--r--src/qualudis/check_metadata.cc131
-rw-r--r--src/qualudis/check_metadata.hh28
-rw-r--r--src/qualudis/check_self_deps.cc136
-rw-r--r--src/qualudis/check_self_deps.hh28
-rw-r--r--src/qualudis/check_visibility.cc155
-rw-r--r--src/qualudis/check_visibility.hh28
-rw-r--r--src/qualudis/qa_notice.cc74
-rw-r--r--src/qualudis/qa_notice.hh91
-rw-r--r--src/qualudis/qualudis.cc141
17 files changed, 187 insertions, 934 deletions
diff --git a/paludis/args/Makefile.am b/paludis/args/Makefile.am
index 1c3ca64..e6c8e75 100644
--- a/paludis/args/Makefile.am
+++ b/paludis/args/Makefile.am
@@ -21,8 +21,8 @@ noinst_LIBRARIES = libpaludisargs.a
check_PROGRAMS = $(TESTS)
test_ldadd = \
- libpaludisargs.a \
$(top_builddir)/test/libtest.a \
+ libpaludisargs.a \
$(top_builddir)/paludis/libpaludis.a
args_TEST_SOURCES = args_TEST.cc
diff --git a/paludis/qa/check_result.cc b/paludis/qa/check_result.cc
index 13763a8..a216cc4 100644
--- a/paludis/qa/check_result.cc
+++ b/paludis/qa/check_result.cc
@@ -28,3 +28,11 @@ CheckResult::CheckResult(const FSEntry & f, const std::string & r) :
{
}
+QALevel
+CheckResult::most_severe_level() const
+{
+ QALevel result(static_cast<QALevel>(0));
+ for (Iterator i(begin()), i_end(end()) ; i != i_end ; ++i)
+ result = std::max(result, i->get<mk_level>());
+ return result;
+}
diff --git a/paludis/qa/check_result.hh b/paludis/qa/check_result.hh
index d5a02a3..96cbf95 100644
--- a/paludis/qa/check_result.hh
+++ b/paludis/qa/check_result.hh
@@ -82,6 +82,8 @@ namespace paludis
{
return _rule;
}
+
+ QALevel most_severe_level() const;
};
}
}
diff --git a/paludis/qa/check_result_TEST.cc b/paludis/qa/check_result_TEST.cc
index e023f48..68a408a 100644
--- a/paludis/qa/check_result_TEST.cc
+++ b/paludis/qa/check_result_TEST.cc
@@ -37,8 +37,15 @@ namespace test_cases
TEST_CHECK_EQUAL(r.item(), "/");
TEST_CHECK_EQUAL(r.rule(), "blah");
TEST_CHECK(r.empty());
+ TEST_CHECK_EQUAL(r.most_severe_level(), qal_info);
r << Message(qal_info, "moo");
TEST_CHECK(! r.empty());
+ TEST_CHECK_EQUAL(r.most_severe_level(), qal_info);
+ r << Message(qal_minor, "moo");
+ TEST_CHECK_EQUAL(r.most_severe_level(), qal_minor);
+ r << Message(qal_major, "moo");
+ TEST_CHECK_EQUAL(r.most_severe_level(), qal_major);
+ TEST_CHECK_EQUAL(std::distance(r.begin(), r.end()), 3);
}
} test_check_result;
}
diff --git a/paludis/qa/package_name_check_TEST.cc b/paludis/qa/package_name_check_TEST.cc
new file mode 100644
index 0000000..65799e5
--- /dev/null
+++ b/paludis/qa/package_name_check_TEST.cc
@@ -0,0 +1,104 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "package_name_check.hh"
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace test;
+
+namespace test_cases
+{
+ struct PackageNameCheckBothValidTest : TestCase
+ {
+ PackageNameCheckBothValidTest() : TestCase("package name both valid") { }
+
+ void run()
+ {
+ FSEntry e("package_name_check_TEST_dir");
+ TEST_CHECK(e.exists());
+ TEST_CHECK(e.is_directory());
+
+ FSEntry f1(e / "valid-cat" / "valid-pkg");
+ TEST_CHECK(f1.exists());
+ CheckResult r1((*(*PackageDirCheckMaker::get_instance()->find_maker(
+ PackageNameCheck::identifier()))())(f1));
+ TEST_CHECK(r1.empty());
+ }
+ } test_package_name_check_both_valid;
+
+ struct PackageNameCheckCatInvalidTest : TestCase
+ {
+ PackageNameCheckCatInvalidTest() : TestCase("package name cat invalid") { }
+
+ void run()
+ {
+ FSEntry e("package_name_check_TEST_dir");
+ TEST_CHECK(e.exists());
+ TEST_CHECK(e.is_directory());
+
+ FSEntry f1(e / "invalid-cat..." / "valid-pkg");
+ TEST_CHECK(f1.exists());
+ CheckResult r1((*(*PackageDirCheckMaker::get_instance()->find_maker(
+ PackageNameCheck::identifier()))())(f1));
+ TEST_CHECK(! r1.empty());
+ TEST_CHECK_EQUAL(std::distance(r1.begin(), r1.end()), 1);
+ }
+ } test_package_name_check_cat_invalid;
+
+ struct PackageNameCheckPkgInvalidTest : TestCase
+ {
+ PackageNameCheckPkgInvalidTest() : TestCase("package name pkg invalid") { }
+
+ void run()
+ {
+ FSEntry e("package_name_check_TEST_dir");
+ TEST_CHECK(e.exists());
+ TEST_CHECK(e.is_directory());
+
+ FSEntry f1(e / "valid-cat" / "invalid-pkg...");
+ TEST_CHECK(f1.exists());
+ CheckResult r1((*(*PackageDirCheckMaker::get_instance()->find_maker(
+ PackageNameCheck::identifier()))())(f1));
+ TEST_CHECK(! r1.empty());
+ TEST_CHECK_EQUAL(std::distance(r1.begin(), r1.end()), 1);
+ }
+ } test_package_name_check_pkg_invalid;
+
+ struct PackageNameCheckBothInvalidTest : TestCase
+ {
+ PackageNameCheckBothInvalidTest() : TestCase("package name both invalid") { }
+
+ void run()
+ {
+ FSEntry e("package_name_check_TEST_dir");
+ TEST_CHECK(e.exists());
+ TEST_CHECK(e.is_directory());
+
+ FSEntry f1(e / "invalid-cat..." / "invalid-pkg...");
+ TEST_CHECK(f1.exists());
+ CheckResult r1((*(*PackageDirCheckMaker::get_instance()->find_maker(
+ PackageNameCheck::identifier()))())(f1));
+ TEST_CHECK(! r1.empty());
+ TEST_CHECK_EQUAL(std::distance(r1.begin(), r1.end()), 2);
+ }
+ } test_package_name_check_both_invalid;
+}
diff --git a/src/qualudis/Makefile.am b/src/qualudis/Makefile.am
index 9c17585..0a53dca 100644
--- a/src/qualudis/Makefile.am
+++ b/src/qualudis/Makefile.am
@@ -7,18 +7,13 @@ SUBDIRS = .
bin_PROGRAMS = qualudis
qualudis_SOURCES = \
- check_deps_exist.hh check_deps_exist.cc \
- check_metadata.hh check_metadata.cc \
- check_self_deps.hh check_self_deps.cc \
- check_visibility.hh check_visibility.cc \
- qa_notice.hh qa_notice.cc \
qualudis_command_line.hh qualudis_command_line.cc \
qualudis.cc
qualudis_LDADD = \
- $(top_builddir)/paludis/libpaludis.a \
$(top_builddir)/paludis/args/libpaludisargs.a \
- $(top_builddir)/paludis/qa/libpaludisqa.a
+ $(top_builddir)/paludis/qa/libpaludisqa.a \
+ $(top_builddir)/paludis/libpaludis.a
TESTS_ENVIRONMENT = env TEST_SCRIPT_DIR="$(srcdir)/" $(SHELL) $(top_srcdir)/test/run_test.sh bash
TESTS = version_TEST
diff --git a/src/qualudis/check_deps_exist.cc b/src/qualudis/check_deps_exist.cc
deleted file mode 100644
index bd7f4ec..0000000
--- a/src/qualudis/check_deps_exist.cc
+++ /dev/null
@@ -1,149 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <paludis/paludis.hh>
-#include <algorithm>
-#include <list>
-
-#include "check_deps_exist.hh"
-#include "qa_notice.hh"
-
-using namespace paludis;
-
-class DepExistsChecker :
- public DepAtomVisitorTypes::ConstVisitor
-{
- private:
- const Environment * const _env;
- std::list<std::string> _bad_deps;
- bool _in_block;
- bool _in_any_of;
- bool _at_least_one_ok;
- QANoticeLevel _level;
-
- public:
- const std::list<std::string> & bad_deps;
- const QANoticeLevel & level;
-
- DepExistsChecker(const Environment * const e) :
- _env(e),
- _in_block(false),
- _level(qal_info),
- bad_deps(_bad_deps),
- level(_level)
- {
- }
-
- void visit(const AllDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * a)
- {
- Save<bool> save_in_any_of(&_in_any_of, true);
- Save<bool> save_at_least_one_ok(&_at_least_one_ok, false);
- std::for_each(a->begin(), a->end(), accept_visitor(this));
-
- if (a->begin() != a->end() && ! _at_least_one_ok)
- _level = std::max(level, qal_major);
- }
-
- void visit(const UseDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom * a)
- {
- Save<bool> save_in_block(&_in_block, true);
- a->blocked_atom()->accept(this);
- }
-
- void visit(const PackageDepAtom * a)
- {
- if (_env->package_database()->query(a)->empty())
- {
- if (_in_block)
- {
- _bad_deps.push_back("!" + stringify(*a));
- _level = std::max(_level, qal_maybe);
- }
- else if (_in_any_of)
- {
- _bad_deps.push_back(stringify(*a));
- _level = std::max(_level, qal_maybe);
- }
- else
- {
- _bad_deps.push_back(stringify(*a));
- _level = std::max(_level, qal_major);
- }
- }
- else
- _at_least_one_ok = true;
- }
-
- void clear()
- {
- _bad_deps.clear();
- _level = qal_info;
- }
-};
-
-bool
-check_deps_exist(const Environment * const env, const PackageDatabaseEntry & e)
-{
- bool ok(true);
- VersionMetadata::ConstPointer metadata(env->package_database()->fetch_metadata(e));
- DepExistsChecker checker(env);
-
- DepParser::parse(metadata->get(vmk_depend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(checker.level, stringify(e),
- "Nonexistent DEPEND entries: " + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- DepParser::parse(metadata->get(vmk_rdepend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(checker.level, stringify(e),
- "Nonexistent RDEPEND entries: " + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- DepParser::parse(metadata->get(vmk_pdepend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(checker.level, stringify(e),
- "Nonexistent PDEPEND entries: " + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- return ok;
-}
-
diff --git a/src/qualudis/check_deps_exist.hh b/src/qualudis/check_deps_exist.hh
deleted file mode 100644
index 9c2fd70..0000000
--- a/src/qualudis/check_deps_exist.hh
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_SRC_QUALUDIS_CHECK_DEPS_EXIST_HH
-#define PALUDIS_GUARD_SRC_QUALUDIS_CHECK_DEPS_EXIST_HH 1
-
-#include <paludis/paludis.hh>
-
-bool
-check_deps_exist(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & e);
-
-#endif
diff --git a/src/qualudis/check_metadata.cc b/src/qualudis/check_metadata.cc
deleted file mode 100644
index 0de2764..0000000
--- a/src/qualudis/check_metadata.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "check_metadata.hh"
-#include "qa_notice.hh"
-
-using namespace paludis;
-
-bool
-check_metadata(const Environment * const env, const PackageDatabaseEntry & e)
-{
- bool ok(true);
- VersionMetadata::ConstPointer metadata(0);
-
- do
- {
- try
- {
- metadata = env->package_database()->fetch_metadata(e);
- if ("UNKNOWN" == metadata->get(vmk_eapi))
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Couldn't generate metadata");
- ok = false;
- break;
- }
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error generating metadata: " + x.message());
- ok = false;
- break;
- }
-
- try
- {
- DepParser::parse(metadata->get(vmk_depend));
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error parsing DEPEND: " + x.message());
- ok = false;
- }
-
- try
- {
- DepParser::parse(metadata->get(vmk_rdepend));
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error parsing RDEPEND: " + x.message());
- ok = false;
- }
-
- try
- {
- DepParser::parse(metadata->get(vmk_pdepend));
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error parsing PDEPEND: " + x.message());
- ok = false;
- }
-
- if (! ok)
- break;
-
- try
- {
- DepParserOptions opts;
- opts.set(dpo_qualified_package_names);
- DepParser::parse(metadata->get(vmk_provide), opts);
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error parsing PROVIDE: " + x.message());
- ok = false;
- }
-
- try
- {
- std::set<UseFlagName> iuse(metadata->begin_iuse(), metadata->end_iuse());
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error parsing IUSE: " + x.message());
- ok = false;
- }
-
- try
- {
- std::set<KeywordName> keywords(metadata->begin_keywords(), metadata->end_keywords());
-
- if (keywords.empty())
- *QANotices::get_instance() << QANotice(qal_minor, stringify(e),
- "KEYWORDS is empty");
- }
- catch (const paludis::Exception & x)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(e),
- "Error parsing KEYWORDS: " + x.message());
- ok = false;
- }
-
- } while (false);
-
- return ok;
-}
-
diff --git a/src/qualudis/check_metadata.hh b/src/qualudis/check_metadata.hh
deleted file mode 100644
index b2e73fc..0000000
--- a/src/qualudis/check_metadata.hh
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_SRC_QUALUDIS_CHECK_METADATA_HH
-#define PALUDIS_GUARD_SRC_QUALUDIS_CHECK_METADATA_HH 1
-
-#include <paludis/paludis.hh>
-
-bool
-check_metadata(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & e);
-
-#endif
diff --git a/src/qualudis/check_self_deps.cc b/src/qualudis/check_self_deps.cc
deleted file mode 100644
index 0ac1e6d..0000000
--- a/src/qualudis/check_self_deps.cc
+++ /dev/null
@@ -1,136 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <paludis/paludis.hh>
-#include <algorithm>
-#include <list>
-
-#include "check_self_deps.hh"
-#include "qa_notice.hh"
-
-using namespace paludis;
-
-class SelfDepsChecker :
- public DepAtomVisitorTypes::ConstVisitor
-{
- private:
- const Environment * const _env;
- const QualifiedPackageName _p;
- std::list<std::string> _bad_deps;
- bool _in_block;
- QANoticeLevel _level;
-
- public:
- const std::list<std::string> & bad_deps;
- const QANoticeLevel & level;
-
- SelfDepsChecker(const Environment * const e, const QualifiedPackageName & pp) :
- _env(e),
- _p(pp),
- _in_block(false),
- _level(qal_info),
- bad_deps(_bad_deps),
- level(_level)
- {
- }
-
- void visit(const AllDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const UseDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom * a)
- {
- Save<bool> save_in_block(&_in_block, true);
- a->blocked_atom()->accept(this);
- }
-
- void visit(const PackageDepAtom * a)
- {
- if (a->package() == _p)
- {
- if (_in_block)
- _bad_deps.push_back("!" + stringify(*a));
- else
- _bad_deps.push_back(stringify(*a));
-
- if (a->version_spec_ptr() || a->slot_ptr())
- _level = std::max(_level, qal_maybe);
- else
- _level = std::max(_level, qal_major);
- }
- }
-
- void clear()
- {
- _bad_deps.clear();
- _level = qal_info;
- }
-};
-
-bool
-check_self_deps(const Environment * const env, const PackageDatabaseEntry & e)
-{
- bool ok(true);
- VersionMetadata::ConstPointer metadata(env->package_database()->fetch_metadata(e));
- SelfDepsChecker checker(env, e.get<pde_name>());
-
- DepParser::parse(metadata->get(vmk_depend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(checker.level, stringify(e),
- "DEPEND self circular: '" + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- DepParser::parse(metadata->get(vmk_rdepend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(checker.level, stringify(e),
- "RDEPEND self circular: '" + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- DepParser::parse(metadata->get(vmk_pdepend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(checker.level, stringify(e),
- "PDEPEND self circular: '" + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- return ok;
-}
-
diff --git a/src/qualudis/check_self_deps.hh b/src/qualudis/check_self_deps.hh
deleted file mode 100644
index ff4d32d..0000000
--- a/src/qualudis/check_self_deps.hh
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_SRC_QUALUDIS_CHECK_SELF_DEPS_HH
-#define PALUDIS_GUARD_SRC_QUALUDIS_CHECK_SELF_DEPS_HH 1
-
-#include <paludis/paludis.hh>
-
-bool
-check_self_deps(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & e);
-
-#endif
diff --git a/src/qualudis/check_visibility.cc b/src/qualudis/check_visibility.cc
deleted file mode 100644
index 518acf5..0000000
--- a/src/qualudis/check_visibility.cc
+++ /dev/null
@@ -1,155 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "check_visibility.hh"
-#include "qa_notice.hh"
-
-using namespace paludis;
-
-class VisibilityChecker :
- public DepAtomVisitorTypes::ConstVisitor
-{
- private:
- const Environment * const _env;
- bool _ok;
- std::list<std::string> _bad_deps;
-
- public:
- const bool & ok;
- const std::list<std::string> & bad_deps;
-
- VisibilityChecker(const Environment * const e) :
- _env(e),
- _ok(true),
- ok(_ok),
- bad_deps(_bad_deps)
- {
- }
-
- void visit(const AllDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * a)
- {
- bool at_least_one_match(false), local_ok(false);
-
- for (CompositeDepAtom::Iterator i(a->begin()), i_end(a->end()) ;
- i != i_end ; ++i)
- {
- const UseDepAtom * p;
- if (((p = (*i)->as_use_dep_atom())))
- {
- Save<bool> save_ok(&_ok, true);
- accept_visitor(this)(i->raw_pointer());
- local_ok |= ok;
- at_least_one_match = true;
- }
- else
- {
- Save<bool> save_ok(&_ok, true);
- accept_visitor(this)(i->raw_pointer());
- local_ok |= ok;
- at_least_one_match = true;
- }
- }
-
- if (! ((! at_least_one_match) || local_ok))
- _ok = false;
- }
-
- void visit(const UseDepAtom * a)
- {
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom *)
- {
- }
-
- void visit(const PackageDepAtom * a)
- {
- PackageDatabaseEntryCollection::ConstPointer m(0);
- if (((m = _env->package_database()->query(a)))->empty())
- _ok = false;
- else
- {
- _ok = false;
- for (PackageDatabaseEntryCollection::Iterator mm(m->begin()), mm_end(m->end()) ;
- mm != mm_end ; ++mm)
- if (! _env->mask_reasons(*mm).any())
- {
- _ok = true;
- break;
- }
- }
-
- if (! _ok)
- _bad_deps.push_back(stringify(*a));
- }
-
- void clear()
- {
- _ok = true;
- _bad_deps.clear();
- }
-};
-
-bool
-check_visibility(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & e)
-{
- bool ok = true;
-
- VersionMetadata::ConstPointer metadata(env->package_database()->fetch_metadata(e));
- VisibilityChecker checker(env);
-
- DepParser::parse(metadata->get(vmk_depend))->accept(&checker);
- if (! checker.ok)
- {
- *QANotices::get_instance() << QANotice(qal_major, stringify(e),
- "Invisible DEPEND entries: " + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- DepParser::parse(metadata->get(vmk_rdepend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(qal_major, stringify(e),
- "Invisible RDEPEND entries: " + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- DepParser::parse(metadata->get(vmk_pdepend))->accept(&checker);
- if (! checker.bad_deps.empty())
- {
- *QANotices::get_instance() << QANotice(qal_major, stringify(e),
- "Invisible PDEPEND entries: " + join(checker.bad_deps.begin(),
- checker.bad_deps.end(), "', '") + "'");
- checker.clear();
- ok = false;
- }
-
- return ok;
-}
-
diff --git a/src/qualudis/check_visibility.hh b/src/qualudis/check_visibility.hh
deleted file mode 100644
index 0661dac..0000000
--- a/src/qualudis/check_visibility.hh
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_SRC_QUALUDIS_CHECK_VISIBILITY_HH
-#define PALUDIS_GUARD_SRC_QUALUDIS_CHECK_VISIBILITY_HH 1
-
-#include <paludis/paludis.hh>
-
-bool
-check_visibility(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & e);
-
-#endif
diff --git a/src/qualudis/qa_notice.cc b/src/qualudis/qa_notice.cc
deleted file mode 100644
index f70aa8e..0000000
--- a/src/qualudis/qa_notice.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-#include "qa_notice.hh"
-#include <ostream>
-#include <algorithm>
-#include <iterator>
-
-QANotices::QANotices()
-{
-}
-
-QANotices::~QANotices()
-{
-}
-
-std::ostream &
-operator<< (std::ostream & s, const QANotice & n)
-{
- do
- {
- switch (n._level)
- {
- case qal_info:
- s << "info: ";
- continue;
-
- case qal_maybe:
- s << "maybe: ";
- continue;
-
- case qal_minor:
- s << "minor: ";
- continue;
-
- case qal_major:
- s << "major: ";
- continue;
-
- case qal_fatal:
- s << "fatal: ";
- continue;
- }
- throw paludis::InternalError(PALUDIS_HERE, "Bad n.level");
-
- } while (false);
-
- s << n._affected << ":\n " << n._message;
- return s;
-}
-
-bool
-QANotice::operator< (const QANotice & other) const
-{
- if (_level < other._level)
- return true;
- if (_level > other._level)
- return false;
-
- if (_affected < other._affected)
- return true;
- if (_affected > other._affected)
- return false;
-
- return _message < other._message;
-}
-
-std::ostream &
-operator<< (std::ostream & s, const QANotices & n)
-{
- std::copy(n._notices.begin(), n._notices.end(),
- std::ostream_iterator<QANotice>(s, "\n"));
- return s;
-}
-
diff --git a/src/qualudis/qa_notice.hh b/src/qualudis/qa_notice.hh
deleted file mode 100644
index 5595d27..0000000
--- a/src/qualudis/qa_notice.hh
+++ /dev/null
@@ -1,91 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_SRC_QUALUDIS_QA_NOTICE_HH
-#define PALUDIS_GUARD_SRC_QUALUDIS_QA_NOTICE_HH 1
-
-#include <paludis/paludis.hh>
-#include <string>
-#include <deque>
-#include <iosfwd>
-
-/**
- * Different levels for QANotice messages.
- *
- * Keep these in order, least severe first. Several methods rely upon
- * std::max() to determine which message is more severe.
- */
-enum QANoticeLevel
-{
- qal_info, ///< Information messages
- qal_maybe, ///< May or may not be a problem
- qal_minor, ///< Minor (usually syntax) issues
- qal_major, ///< Serious issues
- qal_fatal ///< Error preventing further QA checks
-};
-
-class QANotice
-{
- friend std::ostream & operator<< (std::ostream &, const QANotice &);
-
- private:
- const QANoticeLevel _level;
- const std::string _affected;
- const std::string _message;
-
- public:
- QANotice(const QANoticeLevel l, const std::string & affected, const std::string & m) :
- _level(l),
- _affected(affected),
- _message(m)
- {
- }
-
- bool operator< (const QANotice &) const;
-};
-
-class QANotices :
- public paludis::InstantiationPolicy<QANotices, paludis::instantiation_method::SingletonAsNeededTag>
-{
- friend class paludis::InstantiationPolicy<QANotices, paludis::instantiation_method::SingletonAsNeededTag>;
- friend std::ostream & operator<< (std::ostream &, const QANotices &);
-
- private:
- std::multiset<QANotice> _notices;
-
- QANotices();
-
- ~QANotices();
-
- public:
- QANotices &
- operator<< (const QANotice & n)
- {
- _notices.insert(n);
- return *this;
- }
-};
-
-std::ostream &
-operator<< (std::ostream &, const QANotice &);
-
-std::ostream &
-operator<< (std::ostream &, const QANotices &);
-
-#endif
diff --git a/src/qualudis/qualudis.cc b/src/qualudis/qualudis.cc
index 798cdd2..87fa708 100644
--- a/src/qualudis/qualudis.cc
+++ b/src/qualudis/qualudis.cc
@@ -26,11 +26,6 @@
#include <algorithm>
#include "qualudis_command_line.hh"
-#include "check_metadata.hh"
-#include "check_deps_exist.hh"
-#include "check_self_deps.hh"
-#include "check_visibility.hh"
-#include "qa_notice.hh"
#include "config.h"
using namespace paludis;
@@ -52,96 +47,86 @@ struct DoVersion
{
};
-bool
-do_check()
+void
+display_errors(const qa::CheckResult & r)
{
- bool ok(true);
- FSEntry cwd(FSEntry::cwd());
- QualifiedPackageName qpn("x/x");
+ cout << r.item() << ": " << r.rule() << ":" << endl;
- do
+ for (qa::CheckResult::Iterator i(r.begin()), i_end(r.end()) ; i != i_end ; ++i)
{
- try
+ do
{
- PackageNamePart package(cwd.basename());
- CategoryNamePart category(FSEntry(cwd.dirname()).basename());
+ switch (i->get<qa::mk_level>())
+ {
+ case qa::qal_info:
+ cout << " info: ";
+ continue;
- qpn = category + package;
- }
- catch (const NameError & e)
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(cwd),
- "Bad category or package name: '" +
- stringify(e.message()) + "' (" + stringify(e.what()) + ")");
- ok = false;
- break;
- }
+ case qa::qal_minor:
+ cout << " minor: ";
+ continue;
- std::cout << "QA checks for " << qpn << ":" << std::endl;
+ case qa::qal_major:
+ cout << " major: ";
+ continue;
- if (! std::count_if(DirIterator(cwd), DirIterator(), IsFileWithExtension(".ebuild")))
- {
- *QANotices::get_instance() << QANotice(qal_fatal, stringify(cwd), "No ebuilds found");
- ok = false;
- break;
+ case qa::qal_fatal:
+ cout << " fatal: ";
+ continue;
+
+ case qa::qal_maybe:
+ cout << " maybe: ";
+ continue;
+ }
+
+ throw InternalError(PALUDIS_HERE, "Bad mk_level");
}
+ while (false);
- qa::QAEnvironment env(cwd.dirname().dirname());
+ cout << i->get<qa::mk_msg>() << endl;
+ }
+}
- for (DirIterator d(cwd), d_end ; d != d_end ; ++d)
- {
- if (IsFileWithExtension(stringify(qpn.get<qpn_package>()) + "-", ".ebuild")(d->basename()))
- {
- PackageDatabaseEntry e(qpn, VersionSpec(strip_leading_string(
- strip_trailing_string(d->basename(), ".ebuild"),
- stringify(qpn.get<qpn_package>()) + "-")),
- env.package_database()->favourite_repository());
+bool
+do_check()
+{
+ bool ok(true);
+ FSEntry cwd(FSEntry::cwd());
- if (! ((ok &= check_metadata(&env, e))))
- break;
+ std::list<std::string> package_dir_checks;
+ qa::PackageDirCheckMaker::get_instance()->copy_keys(std::back_inserter(package_dir_checks));
+ for (std::list<std::string>::const_iterator i(package_dir_checks.begin()),
+ i_end(package_dir_checks.end()) ; i != i_end ; ++i)
+ {
+ qa::CheckResult r((*qa::PackageDirCheckMaker::get_instance()->find_maker(*i)())(cwd));
- ok &= check_deps_exist(&env, e);
- ok &= check_self_deps(&env, e);
- ok &= check_visibility(&env, e);
- }
- else if (d->basename() == "ChangeLog" || d->basename() == "Manifest")
- {
- if (! d->is_regular_file())
- {
- *QANotices::get_instance() << QANotice(qal_major, stringify(*d),
- "Not a regular file");
- ok = false;
- }
- }
- else if (d->basename() == "metadata.xml")
+ if (r.empty())
+ continue;
+
+ display_errors(r);
+
+ do
+ {
+ switch (r.most_severe_level())
{
- if (! d->is_regular_file())
- {
- *QANotices::get_instance() << QANotice(qal_major, stringify(*d),
- "Not a regular file");
+ case qa::qal_info:
+ case qa::qal_maybe:
+ continue;
+
+ case qa::qal_minor:
+ case qa::qal_major:
ok = false;
- }
- }
- else if (d->basename() == "files" || d->basename() == "CVS")
- {
- if (! d->is_directory())
- {
- *QANotices::get_instance() << QANotice(qal_major, stringify(*d),
- "Not a directory");
+ continue;
+
+ case qa::qal_fatal:
ok = false;
- }
+ return ok;
}
- else
- {
- *QANotices::get_instance() << QANotice(qal_minor, stringify(*d),
- "Not a recognised name");
- ok = false;
- }
- }
+ throw InternalError(PALUDIS_HERE, "Bad most_severe_level");
+ } while (0);
- } while (false);
-
- cout << *QANotices::get_instance() << endl;
+ ok = false;
+ }
return ok;
}