aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-01-05 15:50:14 +0000
committerAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-01-05 15:50:14 +0000
commitc623a4a4f30ba3b339ebd54014bf35eb5191cf14 (patch)
treef5b4e681e807290eb0c15ec040b1db88a076e6da
parent2aa3c6d31c91666b571df41b1fbde2eb0d25a655 (diff)
downloadpaludis-c623a4a4f30ba3b339ebd54014bf35eb5191cf14.tar.gz
paludis-c623a4a4f30ba3b339ebd54014bf35eb5191cf14.tar.xz
Add file check for broken eclass/ebuild headers.
-rw-r--r--paludis/qa/file_check.cc2
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/header_check.cc94
-rw-r--r--paludis/qa/header_check.hh54
4 files changed, 151 insertions, 0 deletions
diff --git a/paludis/qa/file_check.cc b/paludis/qa/file_check.cc
index a8ce7d7..4b22f53 100644
--- a/paludis/qa/file_check.cc
+++ b/paludis/qa/file_check.cc
@@ -24,6 +24,7 @@
#include <paludis/qa/filename_check.hh>
#include <paludis/qa/file_permissions_check.hh>
#include <paludis/qa/glep_31_check.hh>
+#include <paludis/qa/header_check.hh>
#include <paludis/qa/metadata_check.hh>
#include <paludis/qa/subshell_die_check.hh>
#include <paludis/qa/variable_assigns_check.hh>
@@ -49,6 +50,7 @@ FileCheckMaker::FileCheckMaker()
register_maker(FileNameCheck::identifier(), &MakeFileCheck<FileNameCheck>::make_file_check);
register_maker(FilePermissionsCheck::identifier(), &MakeFileCheck<FilePermissionsCheck>::make_file_check);
register_maker(Glep31Check::identifier(), &MakeFileCheck<Glep31Check>::make_file_check);
+ register_maker(HeaderCheck::identifier(), &MakeFileCheck<HeaderCheck>::make_file_check);
register_maker(MetadataCheck::identifier(), &MakeFileCheck<MetadataCheck>::make_file_check);
register_maker(SubshellDieCheck::identifier(), &MakeFileCheck<SubshellDieCheck>::make_file_check);
register_maker(VariableAssignsCheck::identifier(), &MakeFileCheck<VariableAssignsCheck>::make_file_check);
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 3d46927..e917dbc 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -33,6 +33,7 @@ add(`glep_31_check', `hh', `cc', `test')
add(`gpg_check', `hh', `cc', `test', `testscript')
add(`has_ebuilds_check', `hh', `cc', `test', `testscript')
add(`has_misc_files_check', `hh', `cc', `test', `testscript')
+add(`header_check', `hh', `cc')
add(`homepage_check', `hh', `cc')
add(`inherits_blacklist', `txt')
add(`inherits_check', `hh', `cc')
diff --git a/paludis/qa/header_check.cc b/paludis/qa/header_check.cc
new file mode 100644
index 0000000..02638dd
--- /dev/null
+++ b/paludis/qa/header_check.cc
@@ -0,0 +1,94 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@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 <fstream>
+#include <sstream>
+#include <paludis/qa/header_check.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <pcre++.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+HeaderCheck::HeaderCheck()
+{
+}
+
+CheckResult
+HeaderCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ static pcrepp::Pcre::Pcre r_licence("^# Distributed under the terms of the GNU General Public License v2$");
+ // Match both CVS tag and extract year.[0]
+ static pcrepp::Pcre::Pcre r_cvs_header("^#\\s*\\$Header.*\\s(\\d{4})/\\d{2}/\\d{2}\\s.*\\$$");
+
+
+ if (! f.is_regular_file())
+ result << Message(qal_skip, "Not a regular file");
+ else if (! IsFileWithExtension(".ebuild")(f) &&
+ ! IsFileWithExtension(".eclass")(f))
+ result << Message(qal_skip, "Not an ebuild or eclass file");
+ else
+ {
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ result << Message(qal_major, "Can't read file");
+ else
+ {
+ std::string s;
+ std::vector<std::string> lines;
+
+ for (unsigned line_number(0) ; line_number < 3 ; ++line_number)
+ {
+ std::getline(ff, s);
+ lines.push_back(s);
+ }
+
+ do
+ {
+ if (! r_licence.search(lines[1]))
+ result << Message(qal_major, "Wrong licence statement in line 2");
+
+ // Check line 3 before line 1 to extract date of last commit
+ if (! r_cvs_header.search(lines[2]))
+ {
+ result << Message(qal_minor, "Unknown CVS tag in line 3");
+ break;
+ }
+
+ pcrepp::Pcre::Pcre r_copyright("^# Copyright ((1999|200\\d)-)?" + r_cvs_header[0] + " Gentoo Foundation$");
+
+ if (! r_copyright.search(lines[0]))
+ result << Message(qal_major, "Wrong copyright assignment in line 1, possibly date related");
+
+ } while (false);
+ }
+ }
+
+ return result;
+}
+
+const std::string &
+HeaderCheck::identifier()
+{
+ static const std::string id("header");
+ return id;
+}
+
diff --git a/paludis/qa/header_check.hh b/paludis/qa/header_check.hh
new file mode 100644
index 0000000..b99ba66
--- /dev/null
+++ b/paludis/qa/header_check.hh
@@ -0,0 +1,54 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@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_PALUDIS_QA_HEADER_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_HEADER_CHECK_HH 1
+
+#include <istream>
+#include <paludis/qa/file_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ /**
+ * QA check: Ebuild Headers.
+ *
+ * \ingroup grpqacheck
+ */
+ class HeaderCheck :
+ public FileCheck
+ {
+ public:
+ HeaderCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks that ebuild headers are well-formed.";
+ }
+ };
+ }
+}
+
+#endif