aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-22 01:26:46 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-22 01:26:46 +0000
commitb7eab59421d75a83c5a46f5f7a283b7fd1d96ce3 (patch)
tree52af7324f8775fe4e9aa31dda4f57873db768529
parent9b6b3d98cf6b7927ff6642c21187d1d6fa3884cf (diff)
downloadpaludis-b7eab59421d75a83c5a46f5f7a283b7fd1d96ce3.tar.gz
paludis-b7eab59421d75a83c5a46f5f7a283b7fd1d96ce3.tar.xz
Restore subshell die check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am17
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc7
-rw-r--r--paludis/repositories/e/qa/subshell_die.cc80
-rw-r--r--paludis/repositories/e/qa/subshell_die.hh44
-rw-r--r--paludis/repositories/e/qa/subshell_die_TEST.cc80
5 files changed, 227 insertions, 1 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index d3b4887..2725fc2 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -42,6 +42,7 @@ paludis_repositories_e_include_HEADERS = \
default_functions.hh \
kv_variables.hh \
root_variable.hh \
+ subshell_die.hh \
restrict_key.hh \
visibility.hh \
whitespace.hh \
@@ -73,6 +74,7 @@ libpaludiserepositoryqa_la_SOURCES = \
default_functions.cc \
kv_variables.cc \
root_variable.cc \
+ subshell_die.cc \
restrict_key.cc \
visibility.cc \
whitespace.cc \
@@ -138,7 +140,8 @@ TESTS = \
kv_variables_TEST \
visibility_TEST \
misc_files_TEST \
- gpg_TEST
+ gpg_TEST \
+ subshell_die_TEST
check_PROGRAMS = $(TESTS)
@@ -250,6 +253,18 @@ gpg_TEST_LDADD = \
$(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
$(top_builddir)/test/libtest.a
+subshell_die_TEST_SOURCES = subshell_die_TEST.cc
+subshell_die_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
+
endif
built-sources : $(BUILT_SOURCES)
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index f0a878b..f0d66ec 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -40,6 +40,7 @@
#include <paludis/repositories/e/qa/variable_assigns.hh>
#include <paludis/repositories/e/qa/kv_variables.hh>
#include <paludis/repositories/e/qa/root_variable.hh>
+#include <paludis/repositories/e/qa/subshell_die.hh>
#include <paludis/repositories/e/qa/whitespace.hh>
#include <paludis/repositories/e/qa/header.hh>
#include <paludis/repositories/e/qa/repo_name.hh>
@@ -91,6 +92,9 @@ QAChecks::QAChecks() :
_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("subshell_die",
+ tr1::bind(subshell_die_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "subshell_die"));
+
_imp->eclass_file_contents_checks_group->add_check("header",
tr1::bind(header_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "header"));
@@ -162,6 +166,9 @@ QAChecks::QAChecks() :
_imp->package_id_file_contents_checks_group->add_check("root_variable",
tr1::bind(root_variable_check, _1, _2, _5, _6, "root_variable"));
+ _imp->package_id_file_contents_checks_group->add_check("subshell_die",
+ tr1::bind(subshell_die_check, _1, _2, _5, _6, "subshell_die"));
+
_imp->package_id_file_contents_checks_group->add_check("whitespace",
tr1::bind(whitespace_check, _1, _2, _5, _6, "whitespace"));
diff --git a/paludis/repositories/e/qa/subshell_die.cc b/paludis/repositories/e/qa/subshell_die.cc
new file mode 100644
index 0000000..f368157
--- /dev/null
+++ b/paludis/repositories/e/qa/subshell_die.cc
@@ -0,0 +1,80 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk
+ *
+ * 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 <paludis/repositories/e/qa/subshell_die.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::subshell_die_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 subshell_die_check on '" + (id ? stringify(*id) : stringify(entry)) + "':");
+
+ pcrepp::Pcre::Pcre r_comment("^\\s*#");
+ pcrepp::Pcre::Pcre r_subshell_die("\\([^\\)]*\\bdie\\b");
+
+ if (id)
+ Log::get_instance()->message(ll_debug, lc_context) << "subshell_die '"
+ << entry << "', '" << *id << "', '" << name << "'";
+ else
+ Log::get_instance()->message(ll_debug, lc_context) << "subshell_die '"
+ << entry << "', '" << name << "'";
+
+ std::list<std::string> lines;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+
+ unsigned line(0);
+ for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
+ l != l_end ; ++l)
+ {
+ ++line;
+
+ if (l->empty() || r_comment.search(*l))
+ continue;
+
+ if (r_subshell_die.search(*l))
+ {
+ reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Invalid call of 'die' within subshell on line "
+ + stringify(line)), id));
+ continue;
+ }
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/subshell_die.hh b/paludis/repositories/e/qa/subshell_die.hh
new file mode 100644
index 0000000..51506c5
--- /dev/null
+++ b/paludis/repositories/e/qa/subshell_die.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_SUBSHELL_DIE_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_SUBSHELL_DIE_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 subshell_die_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/subshell_die_TEST.cc b/paludis/repositories/e/qa/subshell_die_TEST.cc
new file mode 100644
index 0000000..faf274e
--- /dev/null
+++ b/paludis/repositories/e/qa/subshell_die_TEST.cc
@@ -0,0 +1,80 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk
+ *
+ * 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 "subshell_die.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;
+
+ TestReporter() :
+ count(0)
+ {
+ }
+
+ void message(const QAMessage &)
+ {
+ ++count;
+ }
+
+ void status(const std::string &)
+ {
+ }
+ };
+}
+
+namespace test_cases
+{
+ struct SubshellDieCheckTest : TestCase
+ {
+ SubshellDieCheckTest() : TestCase("subshell_die") { }
+
+ 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"));
+
+ TestReporter r1;
+ TEST_CHECK(subshell_die_check(FSEntry("/var/empty"), r1, id, "src_unpack() {\n\tunpack \"${A}\"\n\tcd \"${S}\"\n\ttrue && ( epatch \"${FILESDIR}\"/${PN}-cookie.patch || die \"subshelled!\")\n}\n", "subshell_die"));
+ TEST_CHECK_EQUAL(r1.count, 1u);
+
+ TestReporter r2;
+ TEST_CHECK(subshell_die_check(FSEntry("/var/empty"), r2, id, "src_unpack() {\n\t:\n}\n", "subshell_die"));
+ TEST_CHECK_EQUAL(r2.count, 0u);
+ }
+ } test_subshell_die;
+}
+
+