aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-08 18:48:25 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-08 18:48:25 +0000
commit377e5a6c458e7100b69fc5ad2e79a08495458599 (patch)
tree200dcfe26ec4f79132d7750620c4b0a889693b4f
parent71e8f4eb13e6c8fa588f35f778ac2c20488fd722 (diff)
downloadpaludis-377e5a6c458e7100b69fc5ad2e79a08495458599.tar.gz
paludis-377e5a6c458e7100b69fc5ad2e79a08495458599.tar.xz
Re-add ebuild header check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am2
-rw-r--r--paludis/repositories/e/qa/header.cc83
-rw-r--r--paludis/repositories/e/qa/header.hh43
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc4
4 files changed, 132 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index b7ab8ae..d5e250a 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -41,6 +41,7 @@ paludis_repositories_e_include_HEADERS = \
kv_variables.hh \
visibility.hh \
whitespace.hh \
+ header.hh \
repo_name.hh
lib_LTLIBRARIES = libpaludiserepositoryqa.la
@@ -61,6 +62,7 @@ libpaludiserepositoryqa_la_SOURCES = \
kv_variables.cc \
visibility.cc \
whitespace.cc \
+ header.cc \
repo_name.cc \
$(paludis_repositories_e_include_HEADERS)
diff --git a/paludis/repositories/e/qa/header.cc b/paludis/repositories/e/qa/header.cc
new file mode 100644
index 0000000..6c6c1ca
--- /dev/null
+++ b/paludis/repositories/e/qa/header.cc
@@ -0,0 +1,83 @@
+/* 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 "header.hh"
+#include <paludis/qa.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/tokeniser.hh>
+#include <pcre++.h>
+#include <time.h>
+#include <vector>
+
+using namespace paludis;
+
+bool
+paludis::erepository::header_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 default_functions on '" + stringify(*id) + "':");
+
+ 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.*\\$$");
+ static pcrepp::Pcre::Pcre r_cvs_empty_header("^#\\s*\\$Header:\\s*\\$$");
+
+ std::vector<std::string> lines;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+
+ do
+ {
+ if (! r_licence.search(lines[1]))
+ reporter.message(QAMessage(entry, qaml_normal, name, "Wrong licence statement in line 2")
+ .with_associated_id(id));
+
+ std::string year;
+
+ // Check line 3 before line 1 to extract date of last commit
+ if (r_cvs_empty_header.search(lines[2]))
+ {
+ time_t now(time(NULL));
+ struct tm now_struct;
+ year = stringify(localtime_r(&now, &now_struct)->tm_year + 1900);
+ }
+ else if (r_cvs_header.search(lines[2]))
+ year = r_cvs_header[0];
+ else
+ {
+ reporter.message(QAMessage(entry, qaml_minor, name, "Unknown CVS tag in line 3")
+ .with_associated_id(id));
+ break;
+ }
+
+ Log::get_instance()->message(ll_debug, lc_context, "Expected copyright year is " + year);
+ pcrepp::Pcre::Pcre r_copyright("^# Copyright ((1999|200\\d)-)?" + year + " Gentoo Foundation$");
+
+ if (! r_copyright.search(lines[0]))
+ reporter.message(QAMessage(entry, qaml_normal, name, "Wrong copyright assignment in line 1, possibly date related")
+ .with_associated_id(id));
+
+ } while (false);
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/header.hh b/paludis/repositories/e/qa/header.hh
new file mode 100644
index 0000000..c530a9a
--- /dev/null
+++ b/paludis/repositories/e/qa/header.hh
@@ -0,0 +1,43 @@
+/* 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_HEADER_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_HEADER_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 header_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &,
+ const std::string &) PALUDIS_VISIBLE;
+ }
+}
+
+#endif
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index bd2d4c0..d47efaf 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -32,6 +32,7 @@
#include <paludis/repositories/e/qa/default_functions.hh>
#include <paludis/repositories/e/qa/kv_variables.hh>
#include <paludis/repositories/e/qa/whitespace.hh>
+#include <paludis/repositories/e/qa/header.hh>
#include <paludis/repositories/e/qa/repo_name.hh>
using namespace paludis;
@@ -108,6 +109,9 @@ QAChecks::QAChecks() :
_imp->package_id_file_contents_checks_group->add_check("whitespace",
tr1::bind(whitespace_check, _1, _2, _5, _6, "whitespace"));
+
+ _imp->package_id_file_contents_checks_group->add_check("header",
+ tr1::bind(header_check, _1, _2, _5, _6, "header"));
}
QAChecks::~QAChecks()