aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-22 02:39:24 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-22 02:39:24 +0000
commitcc7cd342cfe60be23e691a09059124dd01d91a7b (patch)
treecff2487ca0cca5721b71ae467043707b80ca8640
parent0c5d05bade01a87dcecb4a138974c74df792a84a (diff)
downloadpaludis-cc7cd342cfe60be23e691a09059124dd01d91a7b.tar.gz
paludis-cc7cd342cfe60be23e691a09059124dd01d91a7b.tar.xz
Add QA check for suspicious global variables.
-rw-r--r--paludis/qa/broken_global_variables_check.cc74
-rw-r--r--paludis/qa/broken_global_variables_check.hh53
-rw-r--r--paludis/qa/file_check.cc2
-rw-r--r--paludis/qa/files.m41
4 files changed, 130 insertions, 0 deletions
diff --git a/paludis/qa/broken_global_variables_check.cc b/paludis/qa/broken_global_variables_check.cc
new file mode 100644
index 0000000..d6784ba
--- /dev/null
+++ b/paludis/qa/broken_global_variables_check.cc
@@ -0,0 +1,74 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.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 <fstream>
+#include <paludis/qa/broken_global_variables_check.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <paludis/util/strip.hh>
+#include <pcre++.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+BrokenGlobalVariablesCheck::BrokenGlobalVariablesCheck()
+{
+}
+
+CheckResult
+BrokenGlobalVariablesCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ static pcrepp::Pcre::Pcre r_global("^[a-zA-Z0-9\\_]+=.*\\$[{}]?KV");
+
+ if (! f.is_regular_file())
+ result << Message(qal_skip, "Not a regular file");
+ else if (! IsFileWithExtension(".ebuild")(f))
+ result << Message(qal_skip, "Not an ebuild file");
+ else
+ {
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ result << Message(qal_major, "Can't read file");
+ else
+ {
+ std::string line, func;
+ unsigned line_number(0);
+
+ while (std::getline(ff, line))
+ {
+ ++line_number;
+
+ if (r_global.search(line))
+ result << Message(qal_maybe, "Suspect global variable on line "
+ + stringify(line_number) + ": " + strip_leading(line, " \t"));
+ }
+ }
+ }
+
+ return result;
+}
+
+const std::string &
+BrokenGlobalVariablesCheck::identifier()
+{
+ static const std::string id("broken_global_variables");
+ return id;
+}
+
diff --git a/paludis/qa/broken_global_variables_check.hh b/paludis/qa/broken_global_variables_check.hh
new file mode 100644
index 0000000..81b2b1c
--- /dev/null
+++ b/paludis/qa/broken_global_variables_check.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.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_PALUDIS_QA_BROKEN_GLOBAL_VARIABLES_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_BROKEN_GLOBAL_VARIABLES_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+
+namespace paludis
+{
+ namespace qa
+ {
+ /**
+ * QA check: abuse of pkg_setup variables in globals.
+ *
+ * \ingroup grpqacheck
+ */
+ class BrokenGlobalVariablesCheck :
+ public FileCheck
+ {
+ public:
+ BrokenGlobalVariablesCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks for abuse of pkg_setup variables in globals";
+ }
+ };
+ }
+
+}
+
+#endif
diff --git a/paludis/qa/file_check.cc b/paludis/qa/file_check.cc
index 76cc729..8a62787 100644
--- a/paludis/qa/file_check.cc
+++ b/paludis/qa/file_check.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/qa/file_check.hh>
+#include <paludis/qa/broken_global_variables_check.hh>
#include <paludis/qa/changelog_check.hh>
#include <paludis/qa/defaults_check.hh>
#include <paludis/qa/deprecated_functions_check.hh>
@@ -46,6 +47,7 @@ NoSuchFileCheckTypeError::NoSuchFileCheckTypeError(const std::string & s) throw
FileCheckMaker::FileCheckMaker()
{
+ register_maker(BrokenGlobalVariablesCheck::identifier(), &MakeFileCheck<BrokenGlobalVariablesCheck>::make_file_check);
register_maker(ChangeLogCheck::identifier(), &MakeFileCheck<ChangeLogCheck>::make_file_check);
register_maker(DefaultsCheck::identifier(), &MakeFileCheck<DefaultsCheck>::make_file_check);
register_maker(DeprecatedFunctionsCheck::identifier(), &MakeFileCheck<DeprecatedFunctionsCheck>::make_file_check);
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 2ccfb74..37c2596 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -8,6 +8,7 @@ dnl the base filename with no extension; later parameters can be `hh', `cc',
dnl `test', `impl', `testscript'. Note that there isn't much error checking done
dnl on this file at present...
+add(`broken_global_variables_check', `hh', `cc')
add(`categories_check', `hh', `cc')
add(`changelog_check', `hh', `cc')
add(`check', `hh', `cc')