aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Danny van Dyk <dvandyk@exherbo.org> 2006-12-18 00:00:35 +0000
committerAvatar Danny van Dyk <dvandyk@exherbo.org> 2006-12-18 00:00:35 +0000
commitefca9244ce5f84f942a36b07d7053f3b3a93bc92 (patch)
tree8ee6b3f3f667c2b4a4a453a5dd91e83522dd434e
parent8cca913a6c7d065d8b708fbebedbf49ebe0b50a5 (diff)
downloadpaludis-efca9244ce5f84f942a36b07d7053f3b3a93bc92.tar.gz
paludis-efca9244ce5f84f942a36b07d7053f3b3a93bc92.tar.xz
Added check for subshelled die statements in ebuilds and eclasses.
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/subshell_die_check.cc82
-rw-r--r--paludis/qa/subshell_die_check.hh56
-rw-r--r--paludis/qa/subshell_die_check_TEST.cc54
-rwxr-xr-xpaludis/qa/subshell_die_check_TEST_cleanup.sh12
-rwxr-xr-xpaludis/qa/subshell_die_check_TEST_setup.sh43
6 files changed, 248 insertions, 0 deletions
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 00d2bdb..27f17b9 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -50,5 +50,6 @@ add(`src_uri_check', `hh', `cc')
add(`pdepend_overlap_check', `hh', `cc')
add(`qa', `hh', `cc')
add(`slot_check', `hh', `cc')
+add(`subshell_die_check', `hh', `cc', `test', `testscript')
add(`variable_assigns_check', `hh', `cc')
add(`whitespace_check', `hh', `cc')
diff --git a/paludis/qa/subshell_die_check.cc b/paludis/qa/subshell_die_check.cc
new file mode 100644
index 0000000..f7777c4
--- /dev/null
+++ b/paludis/qa/subshell_die_check.cc
@@ -0,0 +1,82 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 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 <paludis/qa/subshell_die_check.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <pcre++.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+SubshellDieCheck::SubshellDieCheck()
+{
+}
+
+CheckResult
+SubshellDieCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ static pcrepp::Pcre::Pcre r_comment("^\\s*#");
+ static pcrepp::Pcre::Pcre r_subshell_die("\\([^\\)]*\\bdie\\b");
+
+ 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;
+ unsigned line_number(0);
+ while (std::getline(ff, s))
+ {
+ ++line_number;
+
+ if (s.empty() || r_comment.search(s))
+ continue;
+
+ if (r_subshell_die.search(s))
+ {
+ result << Message(qal_major, "Invalid call of 'die' within subshell on line "
+ + stringify(line_number));
+ continue;
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
+const std::string &
+SubshellDieCheck::identifier()
+{
+ static const std::string id("subshell_die");
+ return id;
+}
+
+
+
diff --git a/paludis/qa/subshell_die_check.hh b/paludis/qa/subshell_die_check.hh
new file mode 100644
index 0000000..7504a3a
--- /dev/null
+++ b/paludis/qa/subshell_die_check.hh
@@ -0,0 +1,56 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 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_SUBSHELL_DIE_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_SUBSHELL_DIE_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ /**
+ * QA check: calls to die within subshells.
+ *
+ * \ingroup grpqacheck
+ */
+ class SubshellDieCheck :
+ public FileCheck
+ {
+ public:
+ SubshellDieCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks for call to die functions within subshells";
+ }
+ };
+
+ static const FileCheckMaker::RegisterMaker register_subshell_die_check(
+ SubshellDieCheck::identifier(), &MakeFileCheck<SubshellDieCheck>::make_file_check);
+ }
+}
+
+#endif
diff --git a/paludis/qa/subshell_die_check_TEST.cc b/paludis/qa/subshell_die_check_TEST.cc
new file mode 100644
index 0000000..b06f3c4
--- /dev/null
+++ b/paludis/qa/subshell_die_check_TEST.cc
@@ -0,0 +1,54 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 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 "check_result.hh"
+#include "subshell_die_check.hh"
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/join.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace test;
+
+namespace test_cases
+{
+ struct SubshellDieCheckTest : TestCase
+ {
+ SubshellDieCheckTest() : TestCase("subshell_die") { }
+
+ void run()
+ {
+ FSEntry f1(FSEntry::cwd() / "subshell_die_check_TEST_dir/repo1/cat-one/pkg-one/pkg-one-1.ebuild");
+ TEST_CHECK(f1.is_regular_file());
+ CheckResult r1((*(*FileCheckMaker::get_instance()->find_maker(
+ SubshellDieCheck::identifier()))())(f1));
+ TEST_CHECK(! r1.empty());
+
+ FSEntry f2(FSEntry::cwd() / "subshell_die_check_TEST_dir/repo1/cat-one/pkg-one/pkg-one-2.ebuild");
+ TEST_CHECK(f2.is_regular_file());
+ CheckResult r2((*(*FileCheckMaker::get_instance()->find_maker(
+ SubshellDieCheck::identifier()))())(f2));
+ TEST_CHECK(r2.empty());
+ }
+ } qa_environment_defaults_check_src_unpack_test;
+}
+
+
diff --git a/paludis/qa/subshell_die_check_TEST_cleanup.sh b/paludis/qa/subshell_die_check_TEST_cleanup.sh
new file mode 100755
index 0000000..a381d7d
--- /dev/null
+++ b/paludis/qa/subshell_die_check_TEST_cleanup.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d subshell_die_check_TEST_dir ] ; then
+ rm -fr subshell_die_check_TEST_dir
+else
+ true
+fi
+
+
+
+
diff --git a/paludis/qa/subshell_die_check_TEST_setup.sh b/paludis/qa/subshell_die_check_TEST_setup.sh
new file mode 100755
index 0000000..e73d018
--- /dev/null
+++ b/paludis/qa/subshell_die_check_TEST_setup.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir subshell_die_check_TEST_dir || exit 1
+cd subshell_die_check_TEST_dir || exit 1
+
+mkdir -p repo1/{eclass,distfiles,profiles/profile} || exit 1
+cd repo1 || exit 1
+echo "test-repo-1" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+cat-one
+cat-two
+cat-three
+END
+cat <<END > profiles/profile/make.defaults
+ARCH=test
+END
+cat <<END > profiles/profiles.desc
+test profile/ stable
+END
+mkdir -p cat-one/pkg-one
+cat <<"END" > cat-one/pkg-one/pkg-one-1.ebuild
+DESCRIPTION="foo"
+SLOT="foo"
+
+src_unpack() {
+ unpack "${A}"
+ cd "${S}"
+ true && ( epatch "${FILESDIR}"/${PN}-cookie.patch || die "subshelled!")
+}
+END
+cat <<"END" > cat-one/pkg-one/pkg-one-2.ebuild
+DESCRIPTION="foo"
+SLOT="foo"
+
+src_unpack() {
+ :
+}
+END
+
+cd ..
+
+