aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-08 15:34:18 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-08 15:34:18 +0000
commit91ac5c0f13acebb7ef2b99ce8496cc132f0db51e (patch)
tree77f05a7775dca55610711e8e2a443a83ce5a1a4e
parentebe9c29819ed3ca8ccc205c345b3e3faf6051383 (diff)
downloadpaludis-91ac5c0f13acebb7ef2b99ce8496cc132f0db51e.tar.gz
paludis-91ac5c0f13acebb7ef2b99ce8496cc132f0db51e.tar.xz
Re-add check for redundant phase functions.
-rw-r--r--paludis/repositories/e/qa/Makefile.am15
-rw-r--r--paludis/repositories/e/qa/default_functions.cc142
-rw-r--r--paludis/repositories/e/qa/default_functions.hh43
-rw-r--r--paludis/repositories/e/qa/default_functions_TEST.cc116
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc4
5 files changed, 320 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index ebf1807..b7ab8ae 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -37,6 +37,7 @@ paludis_repositories_e_include_HEADERS = \
qa_controller.hh \
short_description_key.hh \
stray_files.hh \
+ default_functions.hh \
kv_variables.hh \
visibility.hh \
whitespace.hh \
@@ -56,6 +57,7 @@ libpaludiserepositoryqa_la_SOURCES = \
short_description_key.cc \
spec_keys.cc \
stray_files.cc \
+ default_functions.cc \
kv_variables.cc \
visibility.cc \
whitespace.cc \
@@ -105,6 +107,7 @@ TESTS = \
homepage_key_TEST \
spec_keys_TEST \
stray_files_TEST \
+ default_functions_TEST \
kv_variables_TEST \
visibility_TEST
@@ -170,6 +173,18 @@ visibility_TEST_LDADD = \
$(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
$(top_builddir)/test/libtest.a
+default_functions_TEST_SOURCES = default_functions_TEST.cc
+default_functions_TEST_LDADD = \
+ libpaludiserepositoryqa.la \
+ test_extras.o \
+ $(top_builddir)/paludis/repositories/e/libpaludiserepository.la \
+ $(top_builddir)/paludis/repositories/fake/libpaludisfakerepository.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
+ $(top_builddir)/test/libtest.a
+
kv_variables_TEST_SOURCES = kv_variables_TEST.cc
kv_variables_TEST_LDADD = \
libpaludiserepositoryqa.la \
diff --git a/paludis/repositories/e/qa/default_functions.cc b/paludis/repositories/e/qa/default_functions.cc
new file mode 100644
index 0000000..d2a2332
--- /dev/null
+++ b/paludis/repositories/e/qa/default_functions.cc
@@ -0,0 +1,142 @@
+/* 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 "default_functions.hh"
+#include <paludis/qa.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/tokeniser.hh>
+#include <pcre++.h>
+#include <list>
+
+using namespace paludis;
+
+namespace
+{
+ enum State
+ {
+ st_default,
+ st_src_compile,
+ st_src_unpack
+ };
+}
+
+bool
+paludis::erepository::default_functions_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_echo("^\\s*(echo|einfo|ewarn)[^|<>]*$");
+ static pcrepp::Pcre::Pcre r_colon("^\\s*:");
+ static pcrepp::Pcre::Pcre r_true("^\\s*true");
+ static pcrepp::Pcre::Pcre r_comment("^\\s*#");
+ static pcrepp::Pcre::Pcre r_econf("^\\s*econf( *\\|\\| *die.*)?$");
+ static pcrepp::Pcre::Pcre r_emake("^\\s*emake( *\\|\\| *die.*)?$");
+ static pcrepp::Pcre::Pcre r_unpack("^\\s*unpack *([$]A|[$][{]A[}]|\"[$][{]A[}]\"|[$][{]A[}])( *\\|\\| *die.*)?$");
+ static pcrepp::Pcre::Pcre r_cd_s("^\\s*cd *([$]S|[$][{]S[}]|\"[$][{]S[}]\"|[$][{]S[}])( *\\|\\| *die.*)?$");
+
+ Log::get_instance()->message(ll_debug, lc_context) << "default_functions '"
+ << 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 line;
+ bool src_compile_changed(false), src_unpack_changed(false);
+
+ for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
+ l != l_end ; ++l)
+ {
+ switch (state)
+ {
+ case st_default:
+ {
+ if (*l == "src_compile() {")
+ state = st_src_compile;
+ else if (*l == "src_unpack() {")
+ state = st_src_unpack;
+ }
+ continue;
+
+ case st_src_compile:
+ {
+ if (*l == "}")
+ {
+ state = st_default;
+ if (! src_compile_changed)
+ reporter.message(QAMessage(entry, qaml_minor, name, "src_compile is redundant"));
+ }
+ else if (l->empty())
+ ;
+ else if (r_econf.search(*l))
+ ;
+ else if (r_emake.search(*l))
+ ;
+ else if (r_echo.search(*l))
+ ;
+ else if (r_colon.search(*l))
+ ;
+ else if (r_true.search(*l))
+ ;
+ else if (r_comment.search(*l))
+ ;
+ else
+ src_compile_changed = true;
+ }
+ continue;
+
+ case st_src_unpack:
+ {
+ if (*l == "}")
+ {
+ state = st_default;
+ if (! src_unpack_changed)
+ reporter.message(QAMessage(entry, qaml_minor, name, "src_unpack is redundant"));
+ }
+ else if (l->empty())
+ ;
+ else if (r_unpack.search(*l))
+ ;
+ else if (r_cd_s.search(*l))
+ ;
+ else if (r_echo.search(*l))
+ ;
+ else if (r_colon.search(*l))
+ ;
+ else if (r_true.search(*l))
+ ;
+ else if (r_comment.search(*l))
+ ;
+ else
+ src_unpack_changed = true;
+ }
+ continue;
+ }
+
+ throw InternalError(PALUDIS_HERE, "bad state");
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/default_functions.hh b/paludis/repositories/e/qa/default_functions.hh
new file mode 100644
index 0000000..182ee49
--- /dev/null
+++ b/paludis/repositories/e/qa/default_functions.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_DEFAULT_FUNCTIONS_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_DEFAULT_FUNCTIONS_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 default_functions_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/default_functions_TEST.cc b/paludis/repositories/e/qa/default_functions_TEST.cc
new file mode 100644
index 0000000..bae58aa
--- /dev/null
+++ b/paludis/repositories/e/qa/default_functions_TEST.cc
@@ -0,0 +1,116 @@
+/* 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 "default_functions.hh"
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/qa.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::erepository;
+using namespace test;
+
+namespace
+{
+ struct TestReporter :
+ QAReporter
+ {
+ unsigned count;
+ std::string messages;
+
+ TestReporter() :
+ count(0)
+ {
+ }
+
+ void message(const QAMessage & m)
+ {
+ ++count;
+ if (! messages.empty())
+ messages.append(", ");
+ messages.append(m.message);
+ }
+
+ void status(const std::string &)
+ {
+ }
+ };
+}
+
+namespace test_cases
+{
+ struct UnpackWithEPatchTest : TestCase
+ {
+ UnpackWithEPatchTest() : TestCase("unpack_with_epatch") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+ tr1::shared_ptr<FakePackageID> id(repo->add_version("cat", "pkg", "1"));
+ id->build_dependencies_key()->set_from_string("cat/other");
+
+ TestReporter r;
+ TEST_CHECK(default_functions_check(FSEntry("/var/empty"), r, id, "src_unpack() {\n\tunpack \"${A}\"\n\tcd \"${S}\"\n\tepatch \"${FILESDIR}\"/${PN}-cookie.patch\n}\n", "default_functions"));
+ TEST_CHECK_EQUAL(r.count, 0u);
+ }
+ } test_unpack_with_epatch;
+
+ struct UnpackEmptyTest : TestCase
+ {
+ UnpackEmptyTest() : TestCase("unpack_empty") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+ tr1::shared_ptr<FakePackageID> id(repo->add_version("cat", "pkg", "1"));
+ id->build_dependencies_key()->set_from_string("cat/other");
+
+ TestReporter r;
+ TEST_CHECK(default_functions_check(FSEntry("/var/empty"), r, id, "src_unpack() {\n\t:\n}\n", "default_functions"));
+ TEST_CHECK_EQUAL(r.count, 1u);
+ }
+ } test_unpack_empty;
+
+ struct UnpackWithNontrivialEchoTest : TestCase
+ {
+ UnpackWithNontrivialEchoTest() : TestCase("unpack_with_nontrivial_echo") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+ tr1::shared_ptr<FakePackageID> id(repo->add_version("cat", "pkg", "1"));
+ id->build_dependencies_key()->set_from_string("cat/other");
+
+ TestReporter r;
+ TEST_CHECK(default_functions_check(FSEntry("/var/empty"), r, id, "src_unpack() {\n\techo \"blah\" > foo\n}\n", "default_functions"));
+ TEST_CHECK_EQUAL(r.count, 0u);
+ }
+ } test_unpack_with_nontrivial_echo;
+}
+
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index 48e5e30..bd2d4c0 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -29,6 +29,7 @@
#include <paludis/repositories/e/qa/spec_keys.hh>
#include <paludis/repositories/e/qa/extractors.hh>
#include <paludis/repositories/e/qa/visibility.hh>
+#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/repo_name.hh>
@@ -99,6 +100,9 @@ QAChecks::QAChecks() :
tr1::bind(visibility_check, _1, _2, _3, _4, _5, "visibility"));
_imp->package_id_checks_group->add_prerequirement("visibility", "metadata_keys");
+ _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("kv_variables",
tr1::bind(kv_variables_check, _1, _2, _5, _6, "kv_variables"));