aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-12 13:46:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-12 13:46:39 +0000
commitd6846dd1e664baf1206153c3dbddbd9b1fd68766 (patch)
tree63dde125562d240faec6f33f495b0c6737a68bce
parent2cf014880a44a3580e65abbcf8a8fc4340f20108 (diff)
downloadpaludis-d6846dd1e664baf1206153c3dbddbd9b1fd68766.tar.gz
paludis-d6846dd1e664baf1206153c3dbddbd9b1fd68766.tar.xz
Very crude initial licence filtering
-rw-r--r--paludis/default_config.cc39
-rw-r--r--paludis/default_config.hh62
-rw-r--r--paludis/default_environment.cc37
-rw-r--r--paludis/default_environment.hh2
-rw-r--r--paludis/environment.cc64
-rw-r--r--paludis/environment.hh5
-rw-r--r--paludis/mask_reasons.cc4
-rw-r--r--paludis/mask_reasons.hh14
-rw-r--r--paludis/portage_repository.cc4
-rw-r--r--paludis/test_environment.cc6
-rw-r--r--paludis/test_environment.hh2
11 files changed, 231 insertions, 8 deletions
diff --git a/paludis/default_config.cc b/paludis/default_config.cc
index caac486..2da5918 100644
--- a/paludis/default_config.cc
+++ b/paludis/default_config.cc
@@ -172,6 +172,45 @@ DefaultConfig::DefaultConfig() :
"contain an entry in the form '* keyword')");
}
+ /* licenses */
+ {
+ std::list<FSEntry> files;
+ files.push_back(config_dir / "licenses.conf");
+
+ for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
+ file != file_end ; ++file)
+ {
+ Context local_context("When reading licenses file '" + stringify(*file) + "':");
+
+ if (! file->is_regular_file())
+ continue;
+
+ LineConfigFile f(*file);
+ for (LineConfigFile::Iterator line(f.begin()), line_end(f.end()) ;
+ line != line_end ; ++line)
+ {
+ std::vector<std::string> tokens;
+ tokeniser.tokenise(*line, std::back_inserter(tokens));
+ if (tokens.empty())
+ continue;
+ if ("*" == tokens.at(0))
+ std::copy(next(tokens.begin()), tokens.end(), std::back_inserter(_default_licenses));
+ else
+ {
+ PackageDepAtom::ConstPointer a(new PackageDepAtom(tokens.at(0)));
+ for (std::vector<std::string>::const_iterator t(next(tokens.begin())), t_end(tokens.end()) ;
+ t != t_end ; ++t)
+ _licenses[a->package()].push_back(std::make_pair(a, *t));
+ }
+ }
+ }
+
+ if (_default_licenses.empty())
+ throw DefaultConfigError("No default licenses specified (a licenses.conf file should "
+ "contain an entry in the form '* keyword', or '* *' if you don't want any "
+ "license filtering)");
+ }
+
/* user mask */
{
std::list<FSEntry> files;
diff --git a/paludis/default_config.hh b/paludis/default_config.hh
index 081fee8..53eb65c 100644
--- a/paludis/default_config.hh
+++ b/paludis/default_config.hh
@@ -134,6 +134,13 @@ namespace paludis
std::vector<KeywordName> _default_keywords;
+ std::map<QualifiedPackageName, std::vector<
+ std::pair<PackageDepAtom::ConstPointer, std::string> > > _licenses;
+
+ const std::vector<std::pair<PackageDepAtom::ConstPointer, std::string> > _empty_licenses;
+
+ std::vector<std::string> _default_licenses;
+
std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> > _user_masks;
std::map<QualifiedPackageName, std::vector<PackageDepAtom::ConstPointer> > _user_unmasks;
@@ -230,6 +237,61 @@ namespace paludis
}
/**
+ * Iterate over our licenses entries.
+ */
+ typedef std::vector<std::pair<PackageDepAtom::ConstPointer, std::string> >::const_iterator
+ PackageLicensesIterator;
+
+ /**
+ * Iterator to the start of the licenses entries for a
+ * particular package.
+ */
+ PackageLicensesIterator begin_package_licenses(const QualifiedPackageName & d) const
+ {
+ std::map<QualifiedPackageName, std::vector<
+ std::pair<PackageDepAtom::ConstPointer, std::string> > >::const_iterator r;
+ if (_licenses.end() != ((r = _licenses.find(d))))
+ return r->second.begin();
+ else
+ return _empty_licenses.begin();
+ }
+
+ /**
+ * Iterator to past the end of the licenses entries for a
+ * particular file.
+ */
+ PackageLicensesIterator end_package_licenses(const QualifiedPackageName & d) const
+ {
+ std::map<QualifiedPackageName, std::vector<
+ std::pair<PackageDepAtom::ConstPointer, std::string> > >::const_iterator r;
+ if (_licenses.end() != ((r = _licenses.find(d))))
+ return r->second.end();
+ else
+ return _empty_licenses.end();
+ }
+
+ /**
+ * Iterator over the default licenses entries.
+ */
+ typedef std::vector<std::string>::const_iterator DefaultLicensesIterator;
+
+ /**
+ * Iterator to the start of our default license entries.
+ */
+ DefaultLicensesIterator begin_default_licenses() const
+ {
+ return _default_licenses.begin();
+ }
+
+ /**
+ * Iterator to past the end of our default license entries.
+ */
+ DefaultLicensesIterator end_default_licenses() const
+ {
+ return _default_licenses.end();
+ }
+
+ /**
* Iterator over user package masks.
*/
typedef IndirectIterator<std::vector<PackageDepAtom::ConstPointer>::const_iterator,
diff --git a/paludis/default_environment.cc b/paludis/default_environment.cc
index 79f0c9a..e2c67de 100644
--- a/paludis/default_environment.cc
+++ b/paludis/default_environment.cc
@@ -176,6 +176,43 @@ DefaultEnvironment::accept_keyword(const KeywordName & keyword, const PackageDat
}
bool
+DefaultEnvironment::accept_license(const std::string & license, const PackageDatabaseEntry * const d) const
+{
+ if (license == "*")
+ return true;
+
+ Context context("When checking license of '" + license +
+ (d ? "' for " + stringify(*d) : stringify("'")) + ":");
+
+ bool result(false);
+
+ if (d)
+ for (DefaultConfig::PackageLicensesIterator
+ k(DefaultConfig::get_instance()->begin_package_licenses(d->get<pde_name>())),
+ k_end(DefaultConfig::get_instance()->end_package_licenses(d->get<pde_name>())) ;
+ k != k_end ; ++k)
+ {
+ if (! match_package(package_database(), k->first, d))
+ continue;
+
+ result |= k->second == license;
+ result |= k->second == "*";
+ }
+
+ result |= DefaultConfig::get_instance()->end_default_licenses() !=
+ std::find(DefaultConfig::get_instance()->begin_default_licenses(),
+ DefaultConfig::get_instance()->end_default_licenses(),
+ license);
+
+ result |= DefaultConfig::get_instance()->end_default_licenses() !=
+ std::find(DefaultConfig::get_instance()->begin_default_licenses(),
+ DefaultConfig::get_instance()->end_default_licenses(),
+ "*");
+
+ return result;
+}
+
+bool
DefaultEnvironment::query_user_masks(const PackageDatabaseEntry & d) const
{
for (DefaultConfig::UserMasksIterator
diff --git a/paludis/default_environment.hh b/paludis/default_environment.hh
index c98c139..e493b35 100644
--- a/paludis/default_environment.hh
+++ b/paludis/default_environment.hh
@@ -53,6 +53,8 @@ namespace paludis
virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const) const;
+ virtual bool accept_license(const std::string &, const PackageDatabaseEntry * const) const;
+
virtual bool query_user_masks(const PackageDatabaseEntry &) const;
virtual bool query_user_unmasks(const PackageDatabaseEntry &) const;
diff --git a/paludis/environment.cc b/paludis/environment.cc
index 244c2c2..383b9f0 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -18,6 +18,8 @@
*/
#include <paludis/package_database.hh>
+#include <paludis/dep_atom.hh>
+#include <paludis/dep_parser.hh>
#include <paludis/qa/environment.hh>
using namespace paludis;
@@ -31,9 +33,64 @@ Environment::~Environment()
{
}
+namespace
+{
+ struct LicenceChecker :
+ DepAtomVisitorTypes::ConstVisitor
+ {
+ bool ok;
+ const Environment * const env;
+ const PackageDatabaseEntry * const db_entry;
+
+ LicenceChecker(const Environment * const e, const PackageDatabaseEntry * const d) :
+ ok(true),
+ env(e),
+ db_entry(d)
+ {
+ }
+
+ ///\name Visit methods
+ ///{
+ void visit(const AllDepAtom * atom)
+ {
+ std::for_each(atom->begin(), atom->end(), accept_visitor(this));
+ }
+
+ void visit(const AnyDepAtom * atom)
+ {
+ std::for_each(atom->begin(), atom->end(), accept_visitor(this));
+ }
+
+ void visit(const UseDepAtom * atom)
+ {
+ if (env->query_use(atom->flag(), db_entry))
+ std::for_each(atom->begin(), atom->end(), accept_visitor(this));
+ }
+
+ void visit(const PlainTextDepAtom * atom)
+ {
+ if (! env->accept_license(atom->text(), db_entry))
+ ok = false;
+ }
+
+ void visit(const PackageDepAtom *) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw InternalError(PALUDIS_HERE, "todo: encountered PackageDepAtom in licence?"); /// \bug todo
+ }
+
+ void visit(const BlockDepAtom *) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw InternalError(PALUDIS_HERE, "todo: encountered BlockDepAtom in licence?"); /// \bug todo
+ }
+ ///}
+ };
+}
+
MaskReasons
Environment::mask_reasons(const PackageDatabaseEntry & e) const
{
+ Context context("When checking mask reasons for '" + stringify(e) + "'");
+
MaskReasons result;
VersionMetadata::ConstPointer metadata(package_database()->fetch_metadata(e));
@@ -41,7 +98,6 @@ Environment::mask_reasons(const PackageDatabaseEntry & e) const
result.set(mr_eapi);
else
{
-
result.set(mr_keyword);
for (VersionMetadata::KeywordIterator k(metadata->begin_keywords()),
k_end(metadata->end_keywords()) ; k != k_end ; ++k)
@@ -51,6 +107,12 @@ Environment::mask_reasons(const PackageDatabaseEntry & e) const
break;
}
+ LicenceChecker lc(this, &e);
+ DepParser::parse(metadata->get(vmk_license),
+ DepParserPolicy<PlainTextDepAtom, true>::get_instance())->accept(&lc);
+ if (! lc.ok)
+ result.set(mr_license);
+
if (! metadata->get(vmk_virtual).empty())
{
QualifiedPackageName n(metadata->get(vmk_virtual));
diff --git a/paludis/environment.hh b/paludis/environment.hh
index 9db6cc8..4644711 100644
--- a/paludis/environment.hh
+++ b/paludis/environment.hh
@@ -66,6 +66,11 @@ namespace paludis
virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const) const = 0;
/**
+ * Is the specified LICENSE accepted?
+ */
+ virtual bool accept_license(const std::string &, const PackageDatabaseEntry * const) const = 0;
+
+ /**
* Fetch the masks for a particular package.
*/
MaskReasons mask_reasons(const PackageDatabaseEntry &) const;
diff --git a/paludis/mask_reasons.cc b/paludis/mask_reasons.cc
index 8bec168..e3bd4e0 100644
--- a/paludis/mask_reasons.cc
+++ b/paludis/mask_reasons.cc
@@ -49,6 +49,10 @@ paludis::operator<< (std::ostream & s, const MaskReason & r)
s << "EAPI";
continue;
+ case mr_license:
+ s << "license";
+ continue;
+
case last_mr:
;
}
diff --git a/paludis/mask_reasons.hh b/paludis/mask_reasons.hh
index 78baa9a..7e35829 100644
--- a/paludis/mask_reasons.hh
+++ b/paludis/mask_reasons.hh
@@ -31,12 +31,14 @@ namespace paludis
*/
enum MaskReason
{
- mr_keyword, ///< no keyword match
- mr_user_mask, ///< user package.mask
- mr_profile_mask, ///< profile package.mask
- mr_repository_mask, ///< repository package.mask
- mr_eapi, ///< unknown eapi
- last_mr ///< number of entries
+ mr_keyword, ///< no keyword match
+ mr_user_mask, ///< user package.mask
+ mr_profile_mask, ///< profile package.mask
+ mr_repository_mask, ///< repository package.mask
+ mr_eapi, ///< unknown eapi
+ mr_license, ///< unaccepted license
+ mr_licence = mr_license, ///< convenience alias for those who can spell
+ last_mr ///< number of entries
};
/**
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index ecf90bc..105e4c2 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -855,7 +855,9 @@ PortageRepository::do_query_use(const UseFlagName & f) const
}
UseMap::iterator p(_imp->use.end());
- if (_imp->use.end() == ((p = _imp->use.find(f))))
+ if (query_use_mask(f))
+ return use_disabled;
+ else if (_imp->use.end() == ((p = _imp->use.find(f))))
return use_unspecified;
else
return p->second;
diff --git a/paludis/test_environment.cc b/paludis/test_environment.cc
index a686a01..79b954c 100644
--- a/paludis/test_environment.cc
+++ b/paludis/test_environment.cc
@@ -39,6 +39,12 @@ TestEnvironment::accept_keyword(const KeywordName & k, const PackageDatabaseEntr
}
bool
+TestEnvironment::accept_license(const std::string &, const PackageDatabaseEntry * const) const
+{
+ return true;
+}
+
+bool
TestEnvironment::query_user_masks(const PackageDatabaseEntry &) const
{
return false;
diff --git a/paludis/test_environment.hh b/paludis/test_environment.hh
index 24616bc..85ff906 100644
--- a/paludis/test_environment.hh
+++ b/paludis/test_environment.hh
@@ -46,6 +46,8 @@ namespace paludis
virtual bool query_user_unmasks(const PackageDatabaseEntry &) const;
+ virtual bool accept_license(const std::string &, const PackageDatabaseEntry * const) const;
+
virtual std::string bashrc_files() const
{
return "";