aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-19 15:33:56 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-19 15:33:56 +0000
commitacd3207915cda6872d5c1e6277d26cc0c7b3f62d (patch)
tree51bf18e6fdd93743d7e6c52debd05a6333cbcf5b
parentf9414ae849b877a6b378192d3908b0e4e8e1d270 (diff)
downloadpaludis-acd3207915cda6872d5c1e6277d26cc0c7b3f62d.tar.gz
paludis-acd3207915cda6872d5c1e6277d26cc0c7b3f62d.tar.xz
Use new Exheres mask format
-rw-r--r--paludis/repositories/e/dep_parser.cc57
-rw-r--r--paludis/repositories/e/dep_parser.hh6
-rw-r--r--paludis/repositories/e/exheres_mask_store.cc77
3 files changed, 121 insertions, 19 deletions
diff --git a/paludis/repositories/e/dep_parser.cc b/paludis/repositories/e/dep_parser.cc
index 2c3549b..7825cc3 100644
--- a/paludis/repositories/e/dep_parser.cc
+++ b/paludis/repositories/e/dep_parser.cc
@@ -261,6 +261,13 @@ namespace
throw EDepParseError(s, "Label '" + f + "' not allowed here");
}
+ void use_not_allowed_handler(const std::string & s, const std::string & f) PALUDIS_ATTRIBUTE((noreturn));
+
+ void use_not_allowed_handler(const std::string & s, const std::string & f)
+ {
+ throw EDepParseError(s, "Conditional '" + f + "' not allowed here");
+ }
+
template <typename T_>
void dependency_label_handler(
const Environment * const env,
@@ -534,6 +541,56 @@ paludis::erepository::parse_depend(const std::string & s, const Environment * co
return top;
}
+std::shared_ptr<SetSpecTree>
+paludis::erepository::parse_commented_set(const std::string & s, const Environment * const, const EAPI & eapi)
+{
+ using namespace std::placeholders;
+
+ ParseStackTypes<SetSpecTree>::Stack stack;
+ std::shared_ptr<AllDepSpec> spec(std::make_shared<AllDepSpec>());
+ std::shared_ptr<DepSpec> thing_to_annotate(spec);
+ std::list<std::shared_ptr<DepSpec> > thing_to_star_annotate;
+ std::shared_ptr<SetSpecTree> top(std::make_shared<SetSpecTree>(spec));
+ stack.push_front(make_named_values<ParseStackTypes<SetSpecTree>::Item>(
+ n::block_children() = std::list<std::pair<std::shared_ptr<BlockDepSpec>, BlockFixOp> >(),
+ n::children() = std::list<std::shared_ptr<DepSpec> >(),
+ n::item() = top->top(),
+ n::spec() = spec
+ ));
+
+ ELikeDepParserCallbacks callbacks(
+ make_named_values<ELikeDepParserCallbacks>(
+ n::on_all() = std::bind(&any_all_handler<SetSpecTree, AllDepSpec>, std::ref(stack)),
+ n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), std::cref(thing_to_star_annotate), _1),
+ n::on_any() = std::bind(&any_not_allowed_handler, s),
+ n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2),
+ n::on_error() = std::bind(&error_handler, s, _1),
+ n::on_exactly_one() = std::bind(&exactly_one_not_allowed_handler, s),
+ n::on_label() = std::bind(&labels_not_allowed_handler, s, _1),
+ n::on_no_annotations() = &do_nothing,
+ n::on_pop() = std::bind(&pop_handler<SetSpecTree>, std::ref(stack),
+ ParseStackTypes<SetSpecTree>::AnnotationsGoHere(std::bind(
+ &set_thing_to_annotate, std::ref(thing_to_annotate), _1)),
+ ParseStackTypes<SetSpecTree>::StarAnnotationsGoHere(std::bind(
+ &set_thing_to_star_annotate, std::ref(thing_to_star_annotate), _1)),
+ s),
+ n::on_should_be_empty() = std::bind(&should_be_empty_handler<SetSpecTree>, std::ref(stack), s),
+ n::on_string() = std::bind(&package_dep_spec_string_handler<SetSpecTree>, std::ref(stack),
+ ParseStackTypes<SetSpecTree>::AnnotationsGoHere(std::bind(
+ &set_thing_to_annotate, std::ref(thing_to_annotate), _1)), _1, eapi),
+ n::on_use() = std::bind(&use_not_allowed_handler, s, _1),
+ n::on_use_under_any() = std::bind(&use_under_any_handler, s, std::cref(eapi))
+ ));
+
+ parse_elike_dependencies(s, callbacks, { edpo_allow_embedded_comments });
+
+ for (auto b(stack.begin()->block_children().begin()), b_end(stack.begin()->block_children().end()) ;
+ b != b_end ; ++b)
+ add_synthetic_block_annotations(eapi, b->first, b->second);
+
+ return top;
+}
+
std::shared_ptr<ProvideSpecTree>
paludis::erepository::parse_provide(const std::string & s, const Environment * const env, const EAPI & eapi, const bool is_installed)
{
diff --git a/paludis/repositories/e/dep_parser.hh b/paludis/repositories/e/dep_parser.hh
index 9df0bf4..8c7ed9c 100644
--- a/paludis/repositories/e/dep_parser.hh
+++ b/paludis/repositories/e/dep_parser.hh
@@ -56,6 +56,12 @@ namespace paludis
const Environment * const, const EAPI &, const bool is_installed) PALUDIS_VISIBLE;
/**
+ * Parse a commented set heirarchy (such as exheres mask files).
+ */
+ std::shared_ptr<SetSpecTree> parse_commented_set(const std::string & s,
+ const Environment * const, const EAPI &) PALUDIS_VISIBLE;
+
+ /**
* Parse a provide heirarchy.
*/
std::shared_ptr<ProvideSpecTree> parse_provide(const std::string & s,
diff --git a/paludis/repositories/e/exheres_mask_store.cc b/paludis/repositories/e/exheres_mask_store.cc
index 718d999..14f625a 100644
--- a/paludis/repositories/e/exheres_mask_store.cc
+++ b/paludis/repositories/e/exheres_mask_store.cc
@@ -19,17 +19,24 @@
#include <paludis/repositories/e/exheres_mask_store.hh>
#include <paludis/repositories/e/profile_file.hh>
-#include <paludis/repositories/e/e_repository_mask_file.hh>
#include <paludis/repositories/e/eapi.hh>
+#include <paludis/repositories/e/dep_parser.hh>
+
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/hashes.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/log.hh>
#include <paludis/util/make_null_shared_ptr.hh>
+#include <paludis/util/safe_ifstream.hh>
+#include <paludis/util/make_named_values.hh>
+#include <paludis/util/fs_stat.hh>
+
#include <paludis/dep_spec.hh>
#include <paludis/package_id.hh>
#include <paludis/match_package.hh>
+#include <paludis/dep_spec_flattener.hh>
+#include <paludis/dep_spec_annotations.hh>
#include <algorithm>
#include <unordered_map>
@@ -78,6 +85,32 @@ ExheresMaskStore::~ExheresMaskStore()
{
}
+namespace
+{
+ std::string extract_annotation(const PackageDepSpec & s, const DepSpecAnnotationRole role)
+ {
+ if (! s.maybe_annotations())
+ return "";
+
+ auto a(s.maybe_annotations()->find(role));
+ if (a == s.maybe_annotations()->end())
+ return "";
+ else
+ return a->value();
+ }
+
+ std::shared_ptr<MaskInfo> make_mask_info(const PackageDepSpec & s, const FSPath & f)
+ {
+ auto result(std::make_shared<MaskInfo>(make_named_values<MaskInfo>(
+ n::comment() = extract_annotation(s, dsar_general_description),
+ n::mask_file() = f,
+ n::token() = ""
+ )));
+
+ return result;
+ }
+}
+
void
ExheresMaskStore::_populate()
{
@@ -85,25 +118,31 @@ ExheresMaskStore::_populate()
using namespace std::placeholders;
- ProfileFile<MaskFile> repository_mask_file(_imp->eapi_for_file);
- std::for_each(_imp->files->begin(), _imp->files->end(),
- std::bind(&ProfileFile<MaskFile>::add_file, std::ref(repository_mask_file), _1));
-
- for (ProfileFile<MaskFile>::ConstIterator
- line(repository_mask_file.begin()), line_end(repository_mask_file.end()) ;
- line != line_end ; ++line)
+ for (auto f(_imp->files->begin()), f_end(_imp->files->end()) ;
+ f != f_end ; ++f)
{
+ if (! f->stat().exists())
+ continue;
+
+ SafeIFStream file(*f);
+ std::string file_text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
+
try
{
- auto a(parse_elike_package_dep_spec(
- line->second.first, line->first->supported()->package_dep_spec_parse_options(),
- line->first->supported()->version_spec_options()));
- if (a.package_ptr())
- _imp->repo_mask[*a.package_ptr()].push_back(std::make_pair(a, line->second.second));
- else
- Log::get_instance()->message("e.package_mask.bad_spec", ll_warning, lc_context)
- << "Loading package mask spec '" << line->second.first << "' failed because specification does not restrict to a "
- "unique package";
+ auto specs(parse_commented_set(file_text, _imp->env, *EAPIData::get_instance()->eapi_from_string(_imp->eapi_for_file(*f))));
+ DepSpecFlattener<SetSpecTree, PackageDepSpec> flat_specs(_imp->env, make_null_shared_ptr());
+ specs->top()->accept(flat_specs);
+
+ for (auto s(flat_specs.begin()), s_end(flat_specs.end()) ;
+ s != s_end ; ++s)
+ {
+ if ((*s)->package_ptr())
+ _imp->repo_mask[*(*s)->package_ptr()].push_back(std::make_pair(**s, make_mask_info(**s, *f)));
+ else
+ Log::get_instance()->message("e.package_mask.bad_spec", ll_warning, lc_context)
+ << "Loading package mask spec '" << **s << "' failed because specification does not restrict to a "
+ "unique package";
+ }
}
catch (const InternalError &)
{
@@ -111,8 +150,8 @@ ExheresMaskStore::_populate()
}
catch (const Exception & e)
{
- Log::get_instance()->message("e.package_mask.bad_spec", ll_warning, lc_context) << "Loading package mask spec '"
- << line->second.first << "' failed due to exception '" << e.message() << "' ("
+ Log::get_instance()->message("e.exheres_mask.bad", ll_warning, lc_context) << "Loading package mask file '"
+ << *f << "' failed due to exception '" << e.message() << "' ("
<< e.what() << ")";
}
}