aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-31 23:56:26 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-31 23:56:26 +0000
commit7f37b0156c66cc6058a71e255a805eb23d5d5906 (patch)
treee98fdcc47e9b405202a409d4b2a42b3b6f7994a0
parentf757378ef7a643fc8bc7dabe4c84bfd070514e5b (diff)
downloadpaludis-7f37b0156c66cc6058a71e255a805eb23d5d5906.tar.gz
paludis-7f37b0156c66cc6058a71e255a805eb23d5d5906.tar.xz
CRAN dependencies
-rw-r--r--paludis/repositories/cran/Makefile.am4
-rw-r--r--paludis/repositories/cran/cran_package_id.cc20
-rw-r--r--paludis/repositories/cran/cran_repository.cc19
-rw-r--r--paludis/repositories/cran/dep_spec_pretty_printer.cc85
-rw-r--r--paludis/repositories/cran/dep_spec_pretty_printer.hh53
-rw-r--r--paludis/repositories/cran/keys.cc42
-rw-r--r--paludis/repositories/cran/keys.hh25
7 files changed, 238 insertions, 10 deletions
diff --git a/paludis/repositories/cran/Makefile.am b/paludis/repositories/cran/Makefile.am
index 41420cc..bfd9689 100644
--- a/paludis/repositories/cran/Makefile.am
+++ b/paludis/repositories/cran/Makefile.am
@@ -35,7 +35,8 @@ paludis_repositories_cran_include_HEADERS = \
description_file.hh \
masks.hh \
keys.hh \
- normalise.hh
+ normalise.hh \
+ dep_spec_pretty_printer.hh
libpaludiscranrepository_la_SOURCES = \
cran_package_id.cc \
@@ -47,6 +48,7 @@ libpaludiscranrepository_la_SOURCES = \
normalise.cc \
masks.cc \
keys.cc \
+ dep_spec_pretty_printer.cc \
$(paludis_repositories_cran_include_HEADERS)
libpaludiscranrepository_la_LIBADD = \
diff --git a/paludis/repositories/cran/cran_package_id.cc b/paludis/repositories/cran/cran_package_id.cc
index 713309b..0dd5950 100644
--- a/paludis/repositories/cran/cran_package_id.cc
+++ b/paludis/repositories/cran/cran_package_id.cc
@@ -60,6 +60,8 @@ namespace paludis
tr1::shared_ptr<StringKey> long_description_key;
tr1::shared_ptr<PackageIDKey> contained_in_key;
tr1::shared_ptr<PackageIDSequenceKey> contains_key;
+ tr1::shared_ptr<DepKey> depends_key;
+ tr1::shared_ptr<DepKey> suggests_key;
Implementation(const tr1::shared_ptr<const Repository> & r, const FSEntry & f) :
repository(r),
@@ -72,7 +74,7 @@ namespace paludis
repository(r->repository()),
name("cran/" + cran_name_to_internal(t)),
version(r->version()),
- contained_in_key(new PackageIDKey("Contained", "Contained in", mkt_normal, r))
+ contained_in_key(new PackageIDKey("Contained", "Contained in", r, mkt_normal))
{
}
};
@@ -188,6 +190,22 @@ CRANPackageID::CRANPackageID(const tr1::shared_ptr<const Repository> & r, const
}
}
}
+
+ if (! file.get("Suggests").empty())
+ {
+ Context local_context("When handling Suggests: key:");
+ _imp->suggests_key.reset(new DepKey("Suggests", "Suggests", file.get("Suggests"), mkt_dependencies));
+ add_metadata_key(_imp->suggests_key);
+ }
+
+ if (! file.get("Depends").empty())
+ {
+ Context local_context("When handling Depends: key:");
+ _imp->depends_key.reset(new DepKey("Depends", "Depends", file.get("Depends") + ", R", mkt_dependencies));
+ }
+ else
+ _imp->depends_key.reset(new DepKey("Depends", "Depends", "R", mkt_dependencies));
+ add_metadata_key(_imp->depends_key);
}
catch (const Exception & e)
{
diff --git a/paludis/repositories/cran/cran_repository.cc b/paludis/repositories/cran/cran_repository.cc
index 09b16fa..6da7810 100644
--- a/paludis/repositories/cran/cran_repository.cc
+++ b/paludis/repositories/cran/cran_repository.cc
@@ -37,6 +37,8 @@
#include <paludis/util/join.hh>
#include <paludis/util/log.hh>
#include <paludis/util/map.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/mutex.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/strip.hh>
@@ -76,16 +78,18 @@ namespace paludis
{
CRANRepositoryParams params;
+ mutable tr1::shared_ptr<Mutex> big_nasty_mutex;
mutable bool has_ids;
mutable IDMap ids;
- Implementation(const CRANRepositoryParams &);
+ Implementation(const CRANRepositoryParams &, const tr1::shared_ptr<Mutex> &);
~Implementation();
};
}
-Implementation<CRANRepository>::Implementation(const CRANRepositoryParams & p) :
+Implementation<CRANRepository>::Implementation(const CRANRepositoryParams & p, const tr1::shared_ptr<Mutex> & m) :
params(p),
+ big_nasty_mutex(m),
has_ids(false)
{
}
@@ -115,7 +119,7 @@ CRANRepository::CRANRepository(const CRANRepositoryParams & p) :
.hook_interface(0)
.manifest_interface(0),
"cran"),
- PrivateImplementationPattern<CRANRepository>(new Implementation<CRANRepository>(p))
+ PrivateImplementationPattern<CRANRepository>(new Implementation<CRANRepository>(p, make_shared_ptr(new Mutex)))
{
tr1::shared_ptr<RepositoryInfoSection> config_info(new RepositoryInfoSection("Configuration information"));
@@ -143,6 +147,7 @@ bool
CRANRepository::do_has_package_named(const QualifiedPackageName & q) const
{
Context context("When checking for package '" + stringify(q) + "' in " + stringify(name()) + ":");
+ Lock l(*_imp->big_nasty_mutex);
if (! do_has_category_named(q.category))
return false;
@@ -155,6 +160,7 @@ tr1::shared_ptr<const CategoryNamePartSet>
CRANRepository::do_category_names() const
{
Context context("When fetching category names in " + stringify(name()) + ":");
+ Lock l(*_imp->big_nasty_mutex);
tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
result->insert(CategoryNamePart("cran"));
@@ -167,6 +173,7 @@ CRANRepository::do_package_names(const CategoryNamePart & c) const
{
Context context("When fetching package names in category '" + stringify(c)
+ "' in " + stringify(name()) + ":");
+ Lock l(*_imp->big_nasty_mutex);
tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
if (! do_has_category_named(c))
@@ -185,6 +192,7 @@ CRANRepository::do_package_ids(const QualifiedPackageName & n) const
{
Context context("When fetching versions of '" + stringify(n) + "' in "
+ stringify(name()) + ":");
+ Lock l(*_imp->big_nasty_mutex);
tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
if (! do_has_package_named(n))
@@ -201,6 +209,8 @@ CRANRepository::do_package_ids(const QualifiedPackageName & n) const
void
CRANRepository::need_ids() const
{
+ Lock l(*_imp->big_nasty_mutex);
+
if (_imp->has_ids)
return;
@@ -352,6 +362,7 @@ bool
CRANRepository::do_sync() const
{
Context context("When syncing repository '" + stringify(name()) + "':");
+ Lock l(*_imp->big_nasty_mutex);
std::string cmd("rsync --delete --recursive --progress --exclude \"*.html\" --exclude \"*.INDEX\" '" +
_imp->params.sync + "/src/contrib/Descriptions/' ./");
@@ -421,7 +432,7 @@ CRANRepositoryConfigurationError::CRANRepositoryConfigurationError(
void
CRANRepository::invalidate()
{
- _imp.reset(new Implementation<CRANRepository>(_imp->params));
+ _imp.reset(new Implementation<CRANRepository>(_imp->params, _imp->big_nasty_mutex));
}
void
diff --git a/paludis/repositories/cran/dep_spec_pretty_printer.cc b/paludis/repositories/cran/dep_spec_pretty_printer.cc
new file mode 100644
index 0000000..dffb0a2
--- /dev/null
+++ b/paludis/repositories/cran/dep_spec_pretty_printer.cc
@@ -0,0 +1,85 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.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 <paludis/repositories/cran/dep_spec_pretty_printer.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <ostream>
+#include <sstream>
+
+using namespace paludis;
+using namespace paludis::cranrepository;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<DepSpecPrettyPrinter>
+ {
+ std::stringstream s;
+ const unsigned indent;
+ const bool multiline;
+ bool need_comma;
+
+ Implementation(const unsigned u, const bool m) :
+ indent(u),
+ multiline(m),
+ need_comma(false)
+ {
+ }
+ };
+}
+
+DepSpecPrettyPrinter::DepSpecPrettyPrinter(const unsigned initial_indent, const bool multiline) :
+ PrivateImplementationPattern<DepSpecPrettyPrinter>(new Implementation<DepSpecPrettyPrinter>(initial_indent, multiline))
+{
+}
+
+DepSpecPrettyPrinter::~DepSpecPrettyPrinter()
+{
+}
+
+void
+DepSpecPrettyPrinter::visit_leaf(const PackageDepSpec & p)
+{
+ if (_imp->multiline)
+ _imp->s << std::string(_imp->indent, ' ');
+ else if (_imp->need_comma)
+ _imp->s << ", ";
+ else
+ _imp->need_comma = true;
+
+ _imp->s << stringify(p);
+
+ if (_imp->multiline)
+ _imp->s << std::endl;
+}
+
+void
+DepSpecPrettyPrinter::visit_leaf(const BlockDepSpec &)
+{
+}
+
+std::ostream &
+paludis::cranrepository::operator<< (std::ostream & s, const DepSpecPrettyPrinter & p)
+{
+ s << p._imp->s.str();
+ return s;
+}
+
diff --git a/paludis/repositories/cran/dep_spec_pretty_printer.hh b/paludis/repositories/cran/dep_spec_pretty_printer.hh
new file mode 100644
index 0000000..f344c88
--- /dev/null
+++ b/paludis/repositories/cran/dep_spec_pretty_printer.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.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_REPOSITORIES_CRAN_DEP_SPEC_PRETTY_PRINTER_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_CRAN_DEP_SPEC_PRETTY_PRINTER_HH 1
+
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/dep_spec.hh>
+#include <iosfwd>
+
+namespace paludis
+{
+ namespace cranrepository
+ {
+ class DepSpecPrettyPrinter :
+ private PrivateImplementationPattern<DepSpecPrettyPrinter>,
+ public ConstVisitor<DependencySpecTree>,
+ public ConstVisitor<DependencySpecTree>::VisitConstSequence<DepSpecPrettyPrinter, AllDepSpec>,
+ public ConstVisitor<DependencySpecTree>::VisitConstSequence<DepSpecPrettyPrinter, UseDepSpec>,
+ public ConstVisitor<DependencySpecTree>::VisitConstSequence<DepSpecPrettyPrinter, AnyDepSpec>
+ {
+ friend std::ostream & operator<< (std::ostream &, const DepSpecPrettyPrinter &);
+
+ public:
+ DepSpecPrettyPrinter(const unsigned initial_indent, const bool multiline);
+ ~DepSpecPrettyPrinter();
+
+ void visit_leaf(const PackageDepSpec &);
+
+ void visit_leaf(const BlockDepSpec &);
+ };
+
+ std::ostream & operator<< (std::ostream & s, const DepSpecPrettyPrinter & p);
+ }
+}
+
+#endif
diff --git a/paludis/repositories/cran/keys.cc b/paludis/repositories/cran/keys.cc
index 64c51d6..872d165 100644
--- a/paludis/repositories/cran/keys.cc
+++ b/paludis/repositories/cran/keys.cc
@@ -19,8 +19,11 @@
#include <paludis/repositories/cran/keys.hh>
#include <paludis/repositories/cran/cran_package_id.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/dep_spec_pretty_printer.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/sequence.hh>
+#include <paludis/util/stringify.hh>
#include <paludis/dep_spec.hh>
using namespace paludis;
@@ -80,8 +83,8 @@ PackageIDSequenceKey::push_back(const tr1::shared_ptr<const PackageID> & i)
_v->push_back(i);
}
-PackageIDKey::PackageIDKey(const std::string & r, const std::string & h, const MetadataKeyType t,
- const CRANPackageID * const v) :
+PackageIDKey::PackageIDKey(const std::string & r, const std::string & h,
+ const CRANPackageID * const v, const MetadataKeyType t) :
MetadataPackageIDKey(r, h, t),
_v(v)
{
@@ -93,3 +96,38 @@ PackageIDKey::value() const
return _v->shared_from_this();
}
+DepKey::DepKey(const std::string & r, const std::string & h, const std::string & v,
+ const MetadataKeyType t) :
+ MetadataSpecTreeKey<DependencySpecTree>(r, h, t),
+ _v(v)
+{
+}
+
+const tr1::shared_ptr<const DependencySpecTree::ConstItem>
+DepKey::value() const
+{
+ Lock l(_m);
+ if (_c)
+ return _c;
+
+ Context context("When parsing CRAN dependency string:");
+ _c = parse_depends(_v);
+ return _c;
+}
+
+std::string
+DepKey::pretty_print() const
+{
+ DepSpecPrettyPrinter p(12, true);
+ value()->accept(p);
+ return stringify(p);
+}
+
+std::string
+DepKey::pretty_print_flat() const
+{
+ DepSpecPrettyPrinter p(0, false);
+ value()->accept(p);
+ return stringify(p);
+}
+
diff --git a/paludis/repositories/cran/keys.hh b/paludis/repositories/cran/keys.hh
index ad1fd94..ca39b0a 100644
--- a/paludis/repositories/cran/keys.hh
+++ b/paludis/repositories/cran/keys.hh
@@ -21,6 +21,7 @@
#define PALUDIS_GUARD_PALUDIS_PALUDIS_REPOSITORIES_CRAN_KEYS_HH 1
#include <paludis/metadata_key.hh>
+#include <paludis/util/mutex.hh>
namespace paludis
{
@@ -82,12 +83,32 @@ namespace paludis
const CRANPackageID * const _v;
public:
- PackageIDKey(const std::string &, const std::string &, const MetadataKeyType,
- const CRANPackageID * const);
+ PackageIDKey(const std::string &, const std::string &, const CRANPackageID * const, const MetadataKeyType);
virtual const tr1::shared_ptr<const PackageID> value() const
PALUDIS_ATTRIBUTE((warn_unused_result));
};
+
+ class DepKey :
+ public MetadataSpecTreeKey<DependencySpecTree>
+ {
+ private:
+ mutable Mutex _m;
+ mutable tr1::shared_ptr<DependencySpecTree::ConstItem> _c;
+ const std::string _v;
+
+ public:
+ DepKey(const std::string &, const std::string &, const std::string &, const MetadataKeyType);
+
+ virtual const tr1::shared_ptr<const DependencySpecTree::ConstItem> value() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual std::string pretty_print() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual std::string pretty_print_flat() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
}
}