aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-17 22:41:32 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-17 22:41:32 +0000
commit6b72690a54a282a925cdc92ce235c5079dcdc19e (patch)
tree14287046a614c72351e1036b893ed2e2e15b1db4
parent806dbcfcb24d626167283ca36c4df065491ba6dd (diff)
downloadpaludis-6b72690a54a282a925cdc92ce235c5079dcdc19e.tar.gz
paludis-6b72690a54a282a925cdc92ce235c5079dcdc19e.tar.xz
Restore variable_assigns check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am2
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc7
-rw-r--r--paludis/repositories/e/qa/variable_assigns.cc104
-rw-r--r--paludis/repositories/e/qa/variable_assigns.hh44
4 files changed, 157 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 4fc9dce..e5df07b 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -45,6 +45,7 @@ paludis_repositories_e_include_HEADERS = \
visibility.hh \
whitespace.hh \
header.hh \
+ variable_assigns.hh \
gpg.hh \
misc_files.hh \
files_dir_size.hh \
@@ -71,6 +72,7 @@ libpaludiserepositoryqa_la_SOURCES = \
visibility.cc \
whitespace.cc \
header.cc \
+ variable_assigns.cc \
gpg.cc \
misc_files.cc \
files_dir_size.cc \
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index e51fbdf..d592b1a 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -35,6 +35,7 @@
#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/variable_assigns.hh>
#include <paludis/repositories/e/qa/kv_variables.hh>
#include <paludis/repositories/e/qa/whitespace.hh>
#include <paludis/repositories/e/qa/header.hh>
@@ -80,6 +81,9 @@ 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("variable_assigns",
+ tr1::bind(variable_assigns_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "variable_assigns"));
+
_imp->eclass_file_contents_checks_group->add_check("header",
tr1::bind(header_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "header"));
@@ -136,6 +140,9 @@ QAChecks::QAChecks() :
_imp->package_id_file_contents_checks_group->add_check("default_functions",
tr1::bind(default_functions_check, _1, _2, _5, _6, "default_functions"));
+ _imp->package_id_file_contents_checks_group->add_check("variable_assigns",
+ tr1::bind(variable_assigns_check, _1, _2, _5, _6, "variable_assigns"));
+
_imp->package_id_file_contents_checks_group->add_check("kv_variables",
tr1::bind(kv_variables_check, _1, _2, _5, _6, "kv_variables"));
diff --git a/paludis/repositories/e/qa/variable_assigns.cc b/paludis/repositories/e/qa/variable_assigns.cc
new file mode 100644
index 0000000..5bf49cb
--- /dev/null
+++ b/paludis/repositories/e/qa/variable_assigns.cc
@@ -0,0 +1,104 @@
+/* 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 "variable_assigns.hh"
+#include <paludis/qa.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/tokeniser.hh>
+#include <pcre++.h>
+#include <list>
+
+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::variable_assigns_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 variable_assigns_check on '" + (id ? stringify(*id) : stringify(entry)) + "':");
+
+ pcrepp::Pcre::Pcre r_comment("^\\s*#");
+ pcrepp::Pcre::Pcre r_make_line("^\\s*e?make\\b");
+ pcrepp::Pcre::Pcre r_make_continuation_line("\\\\\\s*$");
+ pcrepp::Pcre::Pcre r_strip_quotes("(\"(\\\\.|[^\"])+\"|'(\\\\.|[^'])+')", "g");
+
+ std::map<std::string, pcrepp::Pcre::Pcre> r_vars;
+ r_vars.insert(std::make_pair("CFLAGS", pcrepp::Pcre::Pcre("\\bCFLAGS=")));
+ r_vars.insert(std::make_pair("CXXFLAGS", pcrepp::Pcre::Pcre("\\bCXXFLAGS=")));
+ r_vars.insert(std::make_pair("CPPFLAGS", pcrepp::Pcre::Pcre("\\bCPPFLAGS=")));
+ r_vars.insert(std::make_pair("LDFLAGS", pcrepp::Pcre::Pcre("\\bLDFLAGS=")));
+ r_vars.insert(std::make_pair("ASFLAGS", pcrepp::Pcre::Pcre("\\bASFLAGS=")));
+
+ if (id)
+ Log::get_instance()->message(ll_debug, lc_context) << "variable_assigns '"
+ << entry << "', '" << *id << "', '" << name << "'";
+ else
+ Log::get_instance()->message(ll_debug, lc_context) << "variable_assigns '"
+ << entry << "', '" << name << "'";
+
+ std::list<std::string> lines;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+
+ unsigned line_number(0);
+ bool in_make_continuation(false);
+
+ for (std::list<std::string>::iterator it(lines.begin()),
+ it_end(lines.end()); it_end != it; ++it)
+ {
+ ++line_number;
+ if (it->empty() || r_comment.search(*it))
+ continue;
+
+ *it = r_strip_quotes.replace(*it, "");
+
+ if (r_make_line.search(*it))
+ {
+ if (r_make_continuation_line.search(*it))
+ in_make_continuation = true;
+ continue;
+ }
+
+ if (in_make_continuation)
+ {
+ in_make_continuation = r_make_continuation_line.search(*it);
+ continue;
+ }
+
+ for (std::map<std::string, pcrepp::Pcre::Pcre>::iterator r(r_vars.begin()),
+ r_end(r_vars.end()) ; r != r_end ; ++r)
+ if (r->second.search(*it))
+ reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Attempting to assign to " +
+ r->first + " on line " + stringify(line_number)), id));
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/variable_assigns.hh b/paludis/repositories/e/qa/variable_assigns.hh
new file mode 100644
index 0000000..70c7b27
--- /dev/null
+++ b/paludis/repositories/e/qa/variable_assigns.hh
@@ -0,0 +1,44 @@
+/* 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_VARIABLE_ASSIGNS_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_VARIABLE_ASSIGNS_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>
+#include <paludis/repositories/e/e_repository.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool variable_assigns_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &,
+ const std::string &);
+ }
+}
+
+
+#endif