aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-18 06:59:09 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-18 06:59:09 +0000
commitfb2f0dfcc1bfe96b04c76f776959ee2aaa31ecab (patch)
treed90e1e5bbaf9087ac65dadbacefde5bb893b2339
parentbf2f85f23955583170ad11b01dd80ce72fac6858 (diff)
downloadpaludis-fb2f0dfcc1bfe96b04c76f776959ee2aaa31ecab.tar.gz
paludis-fb2f0dfcc1bfe96b04c76f776959ee2aaa31ecab.tar.xz
Check licences
-rw-r--r--paludis/fake_repository.cc6
-rw-r--r--paludis/fake_repository.hh2
-rw-r--r--paludis/portage_repository.cc13
-rw-r--r--paludis/portage_repository.hh2
-rw-r--r--paludis/qa/dep_flags_check.cc45
-rw-r--r--paludis/qa/dep_flags_check.hh2
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/license_check.cc117
-rw-r--r--paludis/qa/license_check.hh51
-rw-r--r--paludis/repository.hh13
10 files changed, 250 insertions, 2 deletions
diff --git a/paludis/fake_repository.cc b/paludis/fake_repository.cc
index fe074b9..4cf560d 100644
--- a/paludis/fake_repository.cc
+++ b/paludis/fake_repository.cc
@@ -199,3 +199,9 @@ FakeRepository::do_is_expand_flag(const UseFlagName &) const
return false;
}
+bool
+FakeRepository::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
diff --git a/paludis/fake_repository.hh b/paludis/fake_repository.hh
index 498d194..f036fb9 100644
--- a/paludis/fake_repository.hh
+++ b/paludis/fake_repository.hh
@@ -75,6 +75,8 @@ namespace paludis
virtual bool do_is_expand_flag(const UseFlagName &) const;
+ virtual bool do_is_licence(const std::string &) const;
+
public:
/**
* Constructor.
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index f44b31f..bd3e403 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -809,3 +809,16 @@ PortageRepository::do_is_expand_flag(const UseFlagName & u) const
return false;
}
+bool
+PortageRepository::do_is_licence(const std::string & s) const
+{
+ FSEntry l(_implementation->location);
+ l /= "licenses";
+
+ if (! l.is_directory())
+ return false;
+
+ l /= s;
+ return l.exists() && l.is_regular_file();
+}
+
diff --git a/paludis/portage_repository.hh b/paludis/portage_repository.hh
index 5cb2225..850e27d 100644
--- a/paludis/portage_repository.hh
+++ b/paludis/portage_repository.hh
@@ -86,6 +86,8 @@ namespace paludis
virtual bool do_is_expand_flag(const UseFlagName &) const;
+ virtual bool do_is_licence(const std::string &) const;
+
public:
/**
* Constructor.
diff --git a/paludis/qa/dep_flags_check.cc b/paludis/qa/dep_flags_check.cc
index ffbb47c..7498cf0 100644
--- a/paludis/qa/dep_flags_check.cc
+++ b/paludis/qa/dep_flags_check.cc
@@ -20,6 +20,8 @@
#include "dep_flags_check.hh"
#include <paludis/dep_parser.hh>
#include <paludis/dep_atom.hh>
+#include <paludis/nest_parser.hh>
+#include <paludis/nest_atom.hh>
using namespace paludis;
using namespace paludis::qa;
@@ -27,7 +29,8 @@ using namespace paludis::qa;
namespace
{
struct Checker :
- DepAtomVisitorTypes::ConstVisitor
+ DepAtomVisitorTypes::ConstVisitor,
+ NestAtomVisitorTypes::ConstVisitor
{
CheckResult & result;
const std::string role;
@@ -80,6 +83,34 @@ namespace
void visit(const BlockDepAtom * const)
{
}
+
+ void visit(const TextNestAtom * const)
+ {
+ }
+
+ void visit(const AllNestAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const UseNestAtom * const u)
+ {
+ if (env->package_database()->fetch_repository(env->package_database()->
+ favourite_repository())->is_arch_flag(u->flag()))
+ {
+ result << Message(qal_major, "Arch flag '" + stringify(u->flag()) +
+ "' in " + role);
+ }
+ else if (env->package_database()->fetch_repository(env->package_database()->
+ favourite_repository())->is_expand_flag(u->flag()))
+ {
+ }
+ else if (iuse.end() == iuse.find(u->flag()))
+ result << Message(qal_major, "Conditional flag '" + stringify(u->flag()) +
+ "' in " + role + " not in IUSE");
+
+ std::for_each(u->begin(), u->end(), accept_visitor(this));
+ }
};
}
@@ -115,6 +146,18 @@ DepFlagsCheck::operator() (const EbuildCheckData & e) const
Checker pdepend_checker(result, "PDEPEND", e.get<ecd_environment>(), iuse);
std::string pdepend(metadata->get(vmk_pdepend));
DepParser::parse(pdepend)->accept(&pdepend_checker);
+
+ Checker provide_checker(result, "PROVIDE", e.get<ecd_environment>(), iuse);
+ std::string provide(metadata->get(vmk_provide));
+ NestParser::parse(provide)->accept(&provide_checker);
+
+ Checker license_checker(result, "LICENSE", e.get<ecd_environment>(), iuse);
+ std::string license(metadata->get(vmk_license));
+ NestParser::parse(license)->accept(&license_checker);
+
+ Checker src_uri_checker(result, "SRC_URI", e.get<ecd_environment>(), iuse);
+ std::string src_uri(metadata->get(vmk_src_uri));
+ NestParser::parse(src_uri)->accept(&src_uri_checker);
}
catch (const InternalError &)
{
diff --git a/paludis/qa/dep_flags_check.hh b/paludis/qa/dep_flags_check.hh
index 6c92928..a90b95f 100644
--- a/paludis/qa/dep_flags_check.hh
+++ b/paludis/qa/dep_flags_check.hh
@@ -39,7 +39,7 @@ namespace paludis
virtual std::string describe() const
{
- return "Checks *DEPEND and PROVIDE use? flags";
+ return "Checks use? flags in metadata";
}
};
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 6d33b51..e231003 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -30,6 +30,7 @@ add(`has_misc_files_check', `hh', `cc', `test', `testscript')
add(`homepage_check', `hh', `cc')
add(`iuse_check', `hh', `cc')
add(`keywords_check', `hh', `cc')
+add(`license_check', `hh', `cc')
add(`message', `hh', `cc', `test')
add(`metadata_check', `hh', `cc')
add(`package_dir_check', `hh', `cc')
diff --git a/paludis/qa/license_check.cc b/paludis/qa/license_check.cc
new file mode 100644
index 0000000..d09856b
--- /dev/null
+++ b/paludis/qa/license_check.cc
@@ -0,0 +1,117 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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 "license_check.hh"
+#include <paludis/nest_atom.hh>
+#include <paludis/nest_parser.hh>
+#include <paludis/tokeniser.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+namespace
+{
+ struct Checker :
+ NestAtomVisitorTypes::ConstVisitor
+ {
+ CheckResult & result;
+ const Environment * const env;
+
+ Checker(CheckResult & rr, const Environment * const e) :
+ result(rr),
+ env(e)
+ {
+ }
+
+ void visit(const TextNestAtom * const a)
+ {
+ if (! env->package_database()->fetch_repository(
+ env->package_database()->favourite_repository())->is_license(a->text()))
+ result << Message(qal_major, "Item '" + a->text() + "' is not a licence");
+ }
+
+ void visit(const AllNestAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const UseNestAtom * const u)
+ {
+ std::for_each(u->begin(), u->end(), accept_visitor(this));
+ }
+ };
+}
+
+LicenseCheck::LicenseCheck()
+{
+}
+
+CheckResult
+LicenseCheck::operator() (const EbuildCheckData & e) const
+{
+ CheckResult result(stringify(e.get<ecd_name>()) + "-" + stringify(e.get<ecd_version>()),
+ identifier());
+
+ try
+ {
+ do
+ {
+ PackageDatabaseEntry ee(e.get<ecd_name>(), e.get<ecd_version>(),
+ e.get<ecd_environment>()->package_database()->favourite_repository());
+ VersionMetadata::ConstPointer metadata(
+ e.get<ecd_environment>()->package_database()->fetch_metadata(ee));
+
+ std::string license(metadata->get(vmk_license));
+
+ NestAtom::ConstPointer license_parts(0);
+ try
+ {
+ license_parts = NestParser::parse(license);
+
+ Checker checker(result, e.get<ecd_environment>());
+ license_parts->accept(&checker);
+ }
+ catch (const DepStringError & e)
+ {
+ result << Message(qal_major, "Invalid LICENSE: '" + e.message() + "' ("
+ + e.what() + ")");
+ break;
+ }
+ } while (false);
+ }
+ catch (const InternalError &)
+ {
+ throw;
+ }
+ catch (const Exception & e)
+ {
+ result << Message(qal_fatal, "Caught Exception '" + e.message() + "' ("
+ + e.what() + ")");
+ }
+
+ return result;
+}
+
+const std::string &
+LicenseCheck::identifier()
+{
+ static const std::string id("license");
+ return id;
+}
+
diff --git a/paludis/qa/license_check.hh b/paludis/qa/license_check.hh
new file mode 100644
index 0000000..0ce8467
--- /dev/null
+++ b/paludis/qa/license_check.hh
@@ -0,0 +1,51 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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_LICENSE_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_LICENSE_CHECK_HH 1
+
+#include <paludis/qa/ebuild_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class LicenseCheck :
+ public EbuildCheck
+ {
+ public:
+ LicenseCheck();
+
+ CheckResult operator() (const EbuildCheckData &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks that LICENSE is sane";
+ }
+ };
+
+ static const EbuildCheckMaker::RegisterMaker register_license_check(
+ LicenseCheck::identifier(), &MakeEbuildCheck<LicenseCheck>::make_ebuild_check);
+ }
+}
+
+#endif
diff --git a/paludis/repository.hh b/paludis/repository.hh
index b724d66..5367df5 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -138,6 +138,11 @@ namespace paludis
*/
virtual bool do_is_expand_flag(const UseFlagName &) const = 0;
+ /**
+ * Override in descendents: is this a licence?
+ */
+ virtual bool do_is_licence(const std::string &) const = 0;
+
public:
/**
* Destructor.
@@ -336,6 +341,14 @@ namespace paludis
{
return do_is_expand_flag(u);
}
+
+ /**
+ * Query whether the specified item is a licence.
+ */
+ bool is_license(const std::string & u) const
+ {
+ return do_is_licence(u);
+ }
};
/**