aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-22 01:26:32 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-22 01:26:32 +0000
commit9b6b3d98cf6b7927ff6642c21187d1d6fa3884cf (patch)
treec86c56bed3338d496d888382034d9324d7b519eb
parent54cfde465957adde802fbd788acd99203ef6d665 (diff)
downloadpaludis-9b6b3d98cf6b7927ff6642c21187d1d6fa3884cf.tar.gz
paludis-9b6b3d98cf6b7927ff6642c21187d1d6fa3884cf.tar.xz
Restore ${ROOT} abuse check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am2
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc4
-rw-r--r--paludis/repositories/e/qa/root_variable.cc99
-rw-r--r--paludis/repositories/e/qa/root_variable.hh42
4 files changed, 147 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 4b0a190..d3b4887 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -41,6 +41,7 @@ paludis_repositories_e_include_HEADERS = \
stray_files.hh \
default_functions.hh \
kv_variables.hh \
+ root_variable.hh \
restrict_key.hh \
visibility.hh \
whitespace.hh \
@@ -71,6 +72,7 @@ libpaludiserepositoryqa_la_SOURCES = \
stray_files.cc \
default_functions.cc \
kv_variables.cc \
+ root_variable.cc \
restrict_key.cc \
visibility.cc \
whitespace.cc \
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index 8b027b3..f0a878b 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -39,6 +39,7 @@
#include <paludis/repositories/e/qa/default_functions.hh>
#include <paludis/repositories/e/qa/variable_assigns.hh>
#include <paludis/repositories/e/qa/kv_variables.hh>
+#include <paludis/repositories/e/qa/root_variable.hh>
#include <paludis/repositories/e/qa/whitespace.hh>
#include <paludis/repositories/e/qa/header.hh>
#include <paludis/repositories/e/qa/repo_name.hh>
@@ -158,6 +159,9 @@ QAChecks::QAChecks() :
_imp->package_id_file_contents_checks_group->add_check("kv_variables",
tr1::bind(kv_variables_check, _1, _2, _5, _6, "kv_variables"));
+ _imp->package_id_file_contents_checks_group->add_check("root_variable",
+ tr1::bind(root_variable_check, _1, _2, _5, _6, "root_variable"));
+
_imp->package_id_file_contents_checks_group->add_check("whitespace",
tr1::bind(whitespace_check, _1, _2, _5, _6, "whitespace"));
diff --git a/paludis/repositories/e/qa/root_variable.cc b/paludis/repositories/e/qa/root_variable.cc
new file mode 100644
index 0000000..fc28731
--- /dev/null
+++ b/paludis/repositories/e/qa/root_variable.cc
@@ -0,0 +1,99 @@
+/* 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
+ */
+
+#include "root_variable.hh"
+#include <paludis/qa.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/tokeniser.hh>
+#include <pcre++.h>
+#include <list>
+
+using namespace paludis;
+
+namespace
+{
+ enum State
+ {
+ st_default,
+ st_in_src
+ };
+}
+
+bool
+paludis::erepository::root_variable_check(
+ const FSEntry & entry,
+ QAReporter & reporter,
+ const tr1::shared_ptr<const PackageID> & id,
+ const std::string & content,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "' using root_variable_check on '" + stringify(*id) + "':");
+
+ pcrepp::Pcre::Pcre r_root("\\$[{]?ROOT[}]?([^=a-zA-Z0-9]|$)");
+ pcrepp::Pcre::Pcre r_start("^src_");
+ pcrepp::Pcre::Pcre r_end("^}");
+
+ Log::get_instance()->message(ll_debug, lc_context) << "root_variable '"
+ << entry << "', '" << *id << "', '" << name << "'";
+
+ std::list<std::string> lines;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+
+ State state(st_default);
+ std::string func;
+ unsigned line_number(0);
+
+ for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
+ l != l_end ; ++l)
+ {
+ ++line_number;
+
+ switch (state)
+ {
+ case st_default:
+ {
+ if (r_start.search(*l))
+ {
+ state = st_in_src;
+ func = *l;
+ if (std::string::npos != func.find('('))
+ func = func.substr(0, func.find('('));
+ }
+ }
+ continue;
+
+ case st_in_src:
+ {
+ if (r_end.search(*l))
+ state = st_default;
+ else if (r_root.search(*l))
+ reporter.message(QAMessage(entry, qaml_maybe, name, "ROOT abuse in " + func + " on line "
+ + stringify(line_number) + ": " + strip_leading(*l, " \t"))
+ .with_associated_id(id));
+ }
+ continue;
+ }
+
+ throw InternalError(PALUDIS_HERE, "bad state");
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/root_variable.hh b/paludis/repositories/e/qa/root_variable.hh
new file mode 100644
index 0000000..532f304
--- /dev/null
+++ b/paludis/repositories/e/qa/root_variable.hh
@@ -0,0 +1,42 @@
+/* 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_ROOT_VARIABLE_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_ROOT_VARIABLE_HH 1
+
+#include <paludis/qa-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool root_variable_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &,
+ const std::string &);
+ }
+}
+
+#endif