aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-14 15:49:31 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-14 15:49:31 +0000
commitc8377c9f073e25c48b04774d1b7e7aa5396273c0 (patch)
treed07f2d6e3ff0332b5c6fda1a7d3e614f6aaf0937
parentb504413c9cb6f67e413af5aad6cb791d4b1873a6 (diff)
downloadpaludis-c8377c9f073e25c48b04774d1b7e7aa5396273c0.tar.gz
paludis-c8377c9f073e25c48b04774d1b7e7aa5396273c0.tar.xz
Add restrict_key check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am2
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc5
-rw-r--r--paludis/repositories/e/qa/restrict_key.cc114
-rw-r--r--paludis/repositories/e/qa/restrict_key.hh39
4 files changed, 160 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 52c993e..0f61f70 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -39,6 +39,7 @@ paludis_repositories_e_include_HEADERS = \
stray_files.hh \
default_functions.hh \
kv_variables.hh \
+ restrict_key.hh \
visibility.hh \
whitespace.hh \
header.hh \
@@ -61,6 +62,7 @@ libpaludiserepositoryqa_la_SOURCES = \
stray_files.cc \
default_functions.cc \
kv_variables.cc \
+ restrict_key.cc \
visibility.cc \
whitespace.cc \
header.cc \
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index fc24793..1c4cd14 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -29,6 +29,7 @@
#include <paludis/repositories/e/qa/homepage_key.hh>
#include <paludis/repositories/e/qa/spec_keys.hh>
#include <paludis/repositories/e/qa/extractors.hh>
+#include <paludis/repositories/e/qa/restrict_key.hh>
#include <paludis/repositories/e/qa/visibility.hh>
#include <paludis/repositories/e/qa/default_functions.hh>
#include <paludis/repositories/e/qa/kv_variables.hh>
@@ -103,6 +104,10 @@ QAChecks::QAChecks() :
tr1::bind(extractors_check, _1, _2, _5, "extractors"));
_imp->package_id_checks_group->add_prerequirement("extractors", "metadata_keys");
+ _imp->package_id_checks_group->add_check("restrict_key",
+ tr1::bind(restrict_key_check, _1, _2, _5, "restrict_key"));
+ _imp->package_id_checks_group->add_prerequirement("restrict_key", "metadata_keys");
+
_imp->package_id_checks_group->add_check("visibility",
tr1::bind(visibility_check, _1, _2, _3, _4, _5, "visibility"));
_imp->package_id_checks_group->add_prerequirement("visibility", "metadata_keys");
diff --git a/paludis/repositories/e/qa/restrict_key.cc b/paludis/repositories/e/qa/restrict_key.cc
new file mode 100644
index 0000000..9f8f54e
--- /dev/null
+++ b/paludis/repositories/e/qa/restrict_key.cc
@@ -0,0 +1,114 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006, 2007 Ciaran McCreesh
+ *
+ * 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 "restrict_key.hh"
+#include <paludis/qa.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/log.hh>
+#include <paludis/name.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/package_id.hh>
+#include <paludis/util/fs_entry.hh>
+#include <set>
+
+using namespace paludis;
+using namespace paludis::erepository;
+
+namespace
+{
+ struct RestrictChecker :
+ ConstVisitor<RestrictSpecTree>,
+ ConstVisitor<RestrictSpecTree>::VisitConstSequence<RestrictChecker, AllDepSpec>,
+ ConstVisitor<RestrictSpecTree>::VisitConstSequence<RestrictChecker, UseDepSpec>
+ {
+ using ConstVisitor<RestrictSpecTree>::VisitConstSequence<RestrictChecker, UseDepSpec>::visit_sequence;
+ using ConstVisitor<RestrictSpecTree>::VisitConstSequence<RestrictChecker, AllDepSpec>::visit_sequence;
+
+ const tr1::shared_ptr<const MetadataKey> & key;
+ const FSEntry entry;
+ QAReporter & reporter;
+ const tr1::shared_ptr<const PackageID> id;
+ const std::string name;
+
+ RestrictChecker(
+ const tr1::shared_ptr<const MetadataKey> & k,
+ const FSEntry & f,
+ QAReporter & r,
+ const tr1::shared_ptr<const PackageID> & i,
+ const std::string & n) :
+ key(k),
+ entry(f),
+ reporter(r),
+ id(i),
+ name(n)
+ {
+ }
+
+ void visit_leaf(const PlainTextDepSpec & t)
+ {
+ static std::set<std::string> allowed_restricts;
+ if (allowed_restricts.empty())
+ {
+ allowed_restricts.insert("fetch");
+ allowed_restricts.insert("mirror");
+ allowed_restricts.insert("nomirror");
+ allowed_restricts.insert("primaryuri");
+ allowed_restricts.insert("nostrip");
+ allowed_restricts.insert("strip");
+ allowed_restricts.insert("sandbox");
+ allowed_restricts.insert("userpriv");
+ allowed_restricts.insert("test");
+ }
+
+ if (allowed_restricts.end() == allowed_restricts.find(t.text()))
+ reporter.message(QAMessage(entry, qaml_normal, name,
+ "Unrecognised value '" + t.text() + "' in '" + key->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+
+ else if (0 == t.text().compare(0, 2, "no"))
+ reporter.message(QAMessage(entry, qaml_minor, name,
+ "Deprecated value '" + t.text() + "' in '" + key->raw_name() + "' (use '" + t.text().substr(2) + "' instead)")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+ }
+ };
+}
+
+bool
+paludis::erepository::restrict_key_check(
+ const FSEntry & entry,
+ QAReporter & reporter,
+ const tr1::shared_ptr<const ERepositoryID> & id,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "' using restrict_key_check on ID '" + stringify(*id) + "':");
+ Log::get_instance()->message(ll_debug, lc_context) << "restrict_key_check '"
+ << entry << "', " << *id << "', " << name << "'";
+
+ if (id->restrict_key())
+ {
+ RestrictChecker r(id->restrict_key(), entry, reporter, id, name);
+ id->restrict_key()->value()->accept(r);
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/restrict_key.hh b/paludis/repositories/e/qa/restrict_key.hh
new file mode 100644
index 0000000..6818600
--- /dev/null
+++ b/paludis/repositories/e/qa/restrict_key.hh
@@ -0,0 +1,39 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh
+ *
+ * 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_PALUDIS_REPOSITORIES_E_QA_RESTRICT_KEY_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_RESTRICT_KEY_HH 1
+
+#include <paludis/qa-fwd.hh>
+#include <paludis/repositories/e/e_repository_id.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool restrict_key_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const ERepositoryID> &,
+ const std::string &) PALUDIS_VISIBLE;
+ }
+}
+
+#endif