aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Danny van Dyk <dvandyk@exherbo.org> 2006-08-09 14:43:23 +0000
committerAvatar Danny van Dyk <dvandyk@exherbo.org> 2006-08-09 14:43:23 +0000
commit93a380c1dd687e5131e1594476a166e26ae3cc5b (patch)
tree7489dd84cf42bb0338bbb97214b6ce84b0b9082c
parentf77232df5389a47ef4ea26aaf34aa605889b3871 (diff)
downloadpaludis-93a380c1dd687e5131e1594476a166e26ae3cc5b.tar.gz
paludis-93a380c1dd687e5131e1594476a166e26ae3cc5b.tar.xz
Add repositories to support CRAN (http://cran.r-project.org).
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac2
-rw-r--r--cran/Makefile.am10
-rw-r--r--cran/cran.bash146
-rw-r--r--paludis/environment.cc2
-rw-r--r--paludis/portage_dep_lexer.hh4
-rw-r--r--paludis/portage_dep_parser.hh4
-rw-r--r--paludis/repositories/Makefile.am2
-rw-r--r--paludis/repositories/cran/Makefile.am67
-rw-r--r--paludis/repositories/cran/cran_dep_parser.cc61
-rw-r--r--paludis/repositories/cran/cran_dep_parser.hh21
-rw-r--r--paludis/repositories/cran/cran_dep_parser_TEST.cc149
-rw-r--r--paludis/repositories/cran/cran_description.cc103
-rw-r--r--paludis/repositories/cran/cran_description.hh129
-rw-r--r--paludis/repositories/cran/cran_installed_repository.cc587
-rw-r--r--paludis/repositories/cran/cran_installed_repository.hh186
-rw-r--r--paludis/repositories/cran/cran_repository.cc625
-rw-r--r--paludis/repositories/cran/cran_repository.hh195
-rw-r--r--paludis/repositories/cran/cran_repository_TEST.cc97
-rwxr-xr-xpaludis/repositories/cran/cran_repository_TEST_cleanup.sh8
-rwxr-xr-xpaludis/repositories/cran/cran_repository_TEST_setup.sh57
-rw-r--r--paludis/version_metadata.cc28
-rw-r--r--paludis/version_metadata.hh97
-rw-r--r--src/paludis/query.cc12
24 files changed, 2576 insertions, 18 deletions
diff --git a/Makefile.am b/Makefile.am
index 768855c..9dc90c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ MAINTAINERCLEANFILES = Makefile.in configure config/* aclocal.m4 \
config.h config.h.in INSTALL COPYING
AUTOMAKE_OPTIONS = dist-bzip2 no-dist-gzip std-options
EXTRA_DIST = autogen.bash automake-deps-hack.tmp
-SUBDIRS = misc test paludis ebuild src doc hooks eselect
+SUBDIRS = misc test paludis cran ebuild src doc hooks eselect
DISTCHECK_CONFIGURE_FLAGS = --enable-qa
diff --git a/configure.ac b/configure.ac
index 14cc984..7be7fa3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -484,6 +484,7 @@ dnl {{{ output
AM_CONFIG_HEADER(config.h)
AC_OUTPUT(
Makefile
+ cran/Makefile
doc/Makefile
doc/doxygen.conf
ebuild/Makefile
@@ -502,6 +503,7 @@ AC_OUTPUT(
paludis/hashed_containers.hh
paludis/qa/Makefile
paludis/repositories/Makefile
+ paludis/repositories/cran/Makefile
paludis/repositories/fake/Makefile
paludis/repositories/nothing/Makefile
paludis/repositories/portage/Makefile
diff --git a/cran/Makefile.am b/cran/Makefile.am
new file mode 100644
index 0000000..a4dee8c
--- /dev/null
+++ b/cran/Makefile.am
@@ -0,0 +1,10 @@
+MAINTAINERCLEANFILES = Makefile.in
+CLEANFILES = *~
+SUBDIRS = .
+
+libexecprogdir = $(libexecdir)/paludis/
+
+libexecprog_SCRIPTS = \
+ cran.bash
+
+EXTRA_DIST = $(libexecprog_SCRIPTS)
diff --git a/cran/cran.bash b/cran/cran.bash
new file mode 100644
index 0000000..6267e8a
--- /dev/null
+++ b/cran/cran.bash
@@ -0,0 +1,146 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Danny van Dyk <kugelfang@gentoo.org>
+#
+# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
+# Gentoo Foundation and distributed under the terms of the GNU General
+# Public License v2.
+#
+# 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 as published by the Free Software Foundation; either version
+# 2 of the License, or (at your option) any later version.
+#
+# 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
+
+. ${PALUDIS_EBUILD_DIR}/echo_functions.bash
+
+shopt -s expand_aliases
+
+CRAN_KILL_PID=$$
+alias die='diefunc "$FUNCNAME" "$LINENO"'
+trap 'echo "die trap: exiting with error." 1>&2 ; exit 250' 15
+
+for f in ${PALUDIS_BASHRC_FILES} ; do
+ if [[ -f ${f} ]] ; then
+ ebuild_notice "debug" "Loading bashrc file ${f}"
+ source ${f}
+ else
+ ebuild_notice "debug" "Skipping bashrc file ${f}"
+ fi
+done
+
+diefunc()
+{
+ local func="$1" line="$2"
+ shift 2
+ echo 1>&2
+ echo "!!! ERROR in cran/${PN:-?}:" 1>&2
+ echo "!!! In ${func:-?} at line ${line:-?}" 1>&2
+ echo "!!! ${*:-(no message provided)}" 1>&2
+ echo 1>&2
+
+ echo "!!! Call stack:" 1>&2
+ for (( n = 1 ; n < ${#FUNCNAME[@]} ; ++n )) ; do
+ funcname=${FUNCNAME[${n}]}
+ sourcefile=${BASH_SOURCE[${n}]}
+ lineno=${BASH_LINENO[$(( n - 1 ))]}
+ echo "!!! * ${funcname} (${sourcefile}:${lineno})" 1>&2
+ done
+ echo 1>&2
+
+ kill ${CRAN_KILL_PID}
+ exit 249
+}
+
+cran_command() {
+ local ret=1 command=${1}
+ shift
+
+ ebuild_section "Starting ${command}"
+
+ if type cran_do_${command} &> /dev/null ; then
+ cran_do_${command} || die "Failed to run command: ${command}"
+ else
+ die "Unknown command: ${command}"
+ fi
+
+ ebuild_section "Done ${command}"
+}
+
+cran_do_clean() {
+ [[ -e ${WORKDIR} ]] && rm -rf ${WORKDIR}
+ [[ -e ${IMAGE} ]] && rm -rf ${IMAGE}
+ return 0
+}
+
+cran_do_fetch() {
+ local mirror ret=0
+ shift
+
+ for mirror in ${PALUDIS_CRAN_MIRRORS[@]} ; do
+ mkdir -p ${DISTDIR}
+ cd ${DISTDIR}
+
+ if [[ -e ${DISTFILE} ]] ; then
+ echo "Already fetched: $(basename ${DISTFILE})"
+ return 0
+ fi
+
+ local dofetch="${PALUDIS_EBUILD_DIR}/fetchers/do$(echo ${mirror%%://*})"
+ local a="${mirror}/src/contrib/${DISTFILE}"
+ if [[ -f "${dofetch}" ]] ; then
+ ${dofetch} "${a}" "${DISTFILE}"
+ ret=$?
+ else
+ eerror "Don't know how to fetch '${a}'"
+ ret=1
+ fi
+ if [[ ${ret} == 0 ]] ; then
+ break
+ else
+ echo "Failed to run \"${command}\" for mirror ${mirror}."
+ fi
+ done
+ if [[ ${ret} != 0 ]] ; then
+ echo "Finally failed to run \"${command}\"."
+ fi
+}
+
+cran_do_install() {
+ if [[ -e "${WORKDIR}" ]] ; then
+ rm -Rf "${WORKDIR}" || die "Could not remove existing WORKDIR: ${WORKDIR}"
+ fi
+ mkdir -p "${WORKDIR}"
+ cd "${WORKDIR}" || die "Could not cd to WORKDIR: ${WORKDIR}"
+
+ local dounpack="${PALUDIS_EBUILD_DIR}/utils/dounpack"
+ ${dounpack} "${DISTFILE}"
+
+ # \todo Sandbox this?
+ R CMD INSTALL -l "${IMAGE}/${PALUDIS_CRAN_LIBRARY##${ROOT}}" ${PN}
+}
+
+cran_do_merge() {
+ [[ -e "${IMAGE}/${INSTALL_TO##${ROOT}}/R.css" ]] \
+ && rm -f "${IMAGE}/${PALUDIS_CRAN_LIBRARY##${ROOT}}/R.css"
+ mkdir -p "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}"
+ ${PALUDIS_EBUILD_DIR}/utils/merge "${IMAGE}" "${ROOT}" "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/CONTENTS"
+}
+
+cran_do_unmerge() {
+ [[ -e "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/CONTENTS" ]] || die "CONTENTS file is missing for package ${PN}"
+ ${PALUDIS_EBUILD_DIR}/utils/unmerge "${ROOT}" "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/CONTENTS"
+}
+
+for cmd in $* ; do
+ cran_command ${cmd}
+done
diff --git a/paludis/environment.cc b/paludis/environment.cc
index f190ba7..0923e9c 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -132,7 +132,7 @@ Environment::mask_reasons(const PackageDatabaseEntry & e) const
e.get<pde_repository>())->version_metadata(e.get<pde_name>(), e.get<pde_version>()));
if (metadata->get<vm_eapi>() != "0" && metadata->get<vm_eapi>() != ""
- && metadata->get<vm_eapi>() != "paludis-1")
+ && metadata->get<vm_eapi>() != "paludis-1" && metadata->get<vm_eapi>() != "CRAN-0")
result.set(mr_eapi);
else
{
diff --git a/paludis/portage_dep_lexer.hh b/paludis/portage_dep_lexer.hh
index 678a774..8835157 100644
--- a/paludis/portage_dep_lexer.hh
+++ b/paludis/portage_dep_lexer.hh
@@ -17,8 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_DEP_PARSER_LEXER_HH
-#define PALUDIS_GUARD_PALUDIS_DEP_PARSER_LEXER_HH 1
+#ifndef PALUDIS_GUARD_PALUDIS_PORTAGE_DEP_LEXER_HH
+#define PALUDIS_GUARD_PALUDIS_PORTAGE_DEP_LEXER_HH 1
#include <paludis/util/exception.hh>
#include <paludis/util/instantiation_policy.hh>
diff --git a/paludis/portage_dep_parser.hh b/paludis/portage_dep_parser.hh
index f3f1d01..a498819 100644
--- a/paludis/portage_dep_parser.hh
+++ b/paludis/portage_dep_parser.hh
@@ -17,8 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_DEP_PARSER_HH
-#define PALUDIS_GUARD_PALUDIS_DEP_PARSER_HH 1
+#ifndef PALUDIS_GUARD_PALUDIS_PORTAGE_DEP_PARSER_HH
+#define PALUDIS_GUARD_PALUDIS_PORTAGE_DEP_PARSER_HH 1
#include <paludis/dep_atom.hh>
#include <paludis/portage_dep_lexer.hh>
diff --git a/paludis/repositories/Makefile.am b/paludis/repositories/Makefile.am
index b2dc1e3..bfaa41f 100644
--- a/paludis/repositories/Makefile.am
+++ b/paludis/repositories/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = fake nothing portage vdb
+SUBDIRS = cran fake nothing portage vdb
CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda
MAINTAINERCLEANFILES = Makefile.in
diff --git a/paludis/repositories/cran/Makefile.am b/paludis/repositories/cran/Makefile.am
new file mode 100644
index 0000000..9e6f884
--- /dev/null
+++ b/paludis/repositories/cran/Makefile.am
@@ -0,0 +1,67 @@
+CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda
+MAINTAINERCLEANFILES = Makefile.in
+
+AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@
+DEFS= \
+ -DSYSCONFDIR=\"$(sysconfdir)\" \
+ -DLIBEXECDIR=\"$(libexecdir)\" \
+ -DDATADIR=\"$(datadir)\" \
+ -DLIBDIR=\"$(libdir)\"
+
+paludis_repositories_libdir = $(libdir)/paludis/repositories
+paludis_repositories_lib_LTLIBRARIES = libpaludiscranrepository.la
+paludis_repositories_cran_includedir = $(includedir)/paludis/repositories/cran/
+libpaludiscranrepository_la_LDFLAGS = -version-info @VERSION_LIB_CURRENT@:@VERSION_LIB_REVISION@:0
+
+paludis_repositories_cran_include_HEADERS = \
+ cran_description.hh \
+ cran_dep_parser.hh \
+ cran_repository.hh \
+ cran_installed_repository.hh
+
+libpaludiscranrepository_la_SOURCES = \
+ cran_description.cc \
+ cran_dep_parser.cc \
+ cran_repository.cc \
+ cran_installed_repository.cc
+ $(paludis_repositories_cran_include_HEADERS)
+
+TESTS = cran_dep_parser_TEST cran_repository_TEST
+
+cran_dep_parser_TEST_SOURCES = cran_dep_parser_TEST.cc
+
+cran_dep_parser_TEST_LDADD= \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ libpaludiscranrepository.la \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(DYNAMIC_LD_LIBS)
+
+cran_repository_TEST_SOURCES = cran_repository_TEST.cc
+
+cran_repository_TEST_LDADD = \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ libpaludiscranrepository.la \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(DYNAMIC_LD_LIBS)
+
+cran_repository_TEST_CXXFLAGS = -I$(top_srcdir)
+
+EXTRA_DIST = \
+ cran_repository_TEST.cc \
+ cran_repository_TEST_setup.sh \
+ cran_repository_TEST_cleanup.sh
+
+check_PROGRAMS = $(TESTS)
+check_SCRIPTS = cran_repository_TEST_setup.sh cran_repository_TEST_cleanup.sh
+
+TESTS_ENVIRONMENT = env \
+ CRAN_BASH_DIR="$(top_srcdir)/cran/" \
+ PALUDIS_SKIP_CONFIG="yes" \
+ TEST_SCRIPT_DIR="$(srcdir)/" \
+ PALUDIS_REPOSITORY_SO_DIR="$(top_builddir)/paludis/repositories" \
+ bash $(top_srcdir)/test/run_test.sh
+
diff --git a/paludis/repositories/cran/cran_dep_parser.cc b/paludis/repositories/cran/cran_dep_parser.cc
new file mode 100644
index 0000000..acc9a74
--- /dev/null
+++ b/paludis/repositories/cran/cran_dep_parser.cc
@@ -0,0 +1,61 @@
+#include <paludis/dep_atom.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <string>
+#include <list>
+
+using namespace paludis;
+
+DepAtom::ConstPointer
+CRANDepParser::parse(const std::string & s)
+{
+ Context context("When parsing CRAN 'Depends:' string: '" + s + "':");
+
+ CompositeDepAtom::Pointer result(new AllDepAtom);
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> atom_tokeniser(",");
+
+ std::list<std::string> atoms;
+ atom_tokeniser.tokenise(s, std::back_inserter(atoms));
+ std::list<std::string>::const_iterator a(atoms.begin()), a_end(atoms.end());
+ for ( ; a != a_end ; ++a)
+ {
+ Context context("When processing token '" + *a + "':");
+
+ std::string aa = strip_leading(strip_trailing(*a, ")"), " \t");
+
+ std::string name, tmp, version, range;
+ std::string::size_type p(aa.find('('));
+ if ((std::string::npos != p))
+ {
+ name = strip_leading(strip_trailing(aa.substr(0, p), " \t"), " \t");
+ tmp = aa.substr(p + 1);
+ p = tmp.find(')');
+ aa = tmp.substr(0, p);
+ version = strip_trailing(strip_leading(aa, " \t(<>=~"), " )\t\n");
+ range = strip_trailing(strip_leading(aa.substr(0, aa.find(version)), " \t"), " \t\n");
+ }
+ else
+ name = strip_leading(strip_trailing(aa, " \t"), " \t");
+
+ CRANDescription::normalise_name(name);
+ CRANDescription::normalise_version(version);
+
+ if ("R" == name)
+ name = "dev-lang/R";
+ else
+ name = "cran/" + name;
+
+ std::string atom_string;
+ if (version.empty() || range.empty())
+ atom_string = name;
+ else
+ atom_string = range + name + "-" + version;
+ PackageDepAtom::Pointer atom(new PackageDepAtom(atom_string));
+ result->add_child(atom);
+ }
+
+ return result;
+}
diff --git a/paludis/repositories/cran/cran_dep_parser.hh b/paludis/repositories/cran/cran_dep_parser.hh
new file mode 100644
index 0000000..caa6aa3
--- /dev/null
+++ b/paludis/repositories/cran/cran_dep_parser.hh
@@ -0,0 +1,21 @@
+#ifndef PALUDIS_GUARD_PALUDIS_CRAN_DEP_PARSER_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_DEP_PARSER_HH 1
+
+#include <paludis/dep_atom.hh>
+#include <string>
+
+namespace paludis
+{
+ /**
+ * The CRANDepParser conversts a string representation of a CRAN Depends:
+ * specification into a DepAtom instance.
+ *
+ * \ingroup grpdepparser
+ */
+ struct CRANDepParser
+ {
+ static DepAtom::ConstPointer parse(const std::string & s);
+ };
+}
+
+#endif
diff --git a/paludis/repositories/cran/cran_dep_parser_TEST.cc b/paludis/repositories/cran/cran_dep_parser_TEST.cc
new file mode 100644
index 0000000..c2e5979
--- /dev/null
+++ b/paludis/repositories/cran/cran_dep_parser_TEST.cc
@@ -0,0 +1,149 @@
+/* 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 <paludis/dep_atom.hh>
+#include <paludis/dep_atom_flattener.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/test_environment.hh>
+#include <paludis/util/system.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace test;
+using namespace paludis;
+
+#ifndef DOXYGEN
+namespace
+{
+ class DepAtomDumper :
+ public DepAtomVisitorTypes::ConstVisitor,
+ private InstantiationPolicy<DepAtomDumper, instantiation_method::NonCopyableTag>
+ {
+ private:
+ std::ostream * const _o;
+
+ public:
+ DepAtomDumper(std::ostream * const o);
+
+ void visit(const AllDepAtom * const);
+
+ void visit(const AnyDepAtom * const);
+
+ void visit(const UseDepAtom * const);
+
+ void visit(const PackageDepAtom * const);
+
+ void visit(const PlainTextDepAtom * const);
+
+ void visit(const BlockDepAtom * const);
+ };
+
+ DepAtomDumper::DepAtomDumper(std::ostream * const o) :
+ _o(o)
+ {
+ }
+
+ void
+ DepAtomDumper::visit(const AllDepAtom * const a)
+ {
+ *_o << "<all>";
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ *_o << "</all>";
+ }
+
+ void
+ DepAtomDumper::visit(const AnyDepAtom * const a)
+ {
+ *_o << "<any>";
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ *_o << "</any>";
+ }
+
+ void
+ DepAtomDumper::visit(const UseDepAtom * const a)
+ {
+ *_o << "<use flag=\"" << a->flag() << "\" inverse=\""
+ << (a->inverse() ? "true" : "false") << "\">";
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ *_o << "</use>";
+ }
+
+ void
+ DepAtomDumper::visit(const PackageDepAtom * const p)
+ {
+ *_o << "<package";
+ if (p->slot_ptr())
+ *_o << " slot=\"" << *p->slot_ptr() << "\"";
+ if (p->version_spec_ptr())
+ *_o << " version=\"" << p->version_operator() << *p->version_spec_ptr() << "\"";
+ *_o << ">" << p->package() << "</package>";
+ }
+
+ void
+ DepAtomDumper::visit(const PlainTextDepAtom * const t)
+ {
+ *_o << "<text>" << t->text() << "</text>";
+ }
+
+ void
+ DepAtomDumper::visit(const BlockDepAtom * const b)
+ {
+ *_o << "<block>";
+ b->blocked_atom()->accept(this);
+ *_o << "</block>";
+ }
+}
+#endif
+
+/** \file
+ * Test cases for CRANRepository.
+ *
+ * \ingroup grptestcases
+ */
+
+namespace test_cases
+{
+ /**
+ * \test Test CRANDepParser::parse to parse well formed CRAN Depends: strings.
+ *
+ * \ingroup grptestcases
+ */
+ struct CRANDepParserTest : TestCase
+ {
+ CRANDepParserTest() : TestCase("DepParser") { }
+
+ void run()
+ {
+ std::stringstream s1, s2, s3;
+ DepAtomDumper d1(&s1), d2(&s2), d3(&s3);
+ // test R dependency
+ std::string dep1("R (>= 2.0.0)");
+ CRANDepParser::parse(dep1)->accept(&d1);
+ TEST_CHECK_EQUAL(s1.str(), "<all><package version=\">=2.0.0\">dev-lang/R</package></all>");
+ // test varying whitespaces
+ std::string dep2("testpackage1 \t(<1.9)");
+ CRANDepParser::parse(dep2)->accept(&d2);
+ TEST_CHECK_EQUAL(s2.str(), "<all><package version=\"<1.9\">cran/testpackage1</package></all>");
+ // test for package-name and version normalisation
+ std::string dep3("R.matlab (>= 2.3-1)");
+ CRANDepParser::parse(dep3)->accept(&d3);
+ TEST_CHECK_EQUAL(s3.str(), "<all><package version=\">=2.3.1\">cran/R-matlab</package></all>");
+ }
+ } test_cran_dep_parser;
+}
diff --git a/paludis/repositories/cran/cran_description.cc b/paludis/repositories/cran/cran_description.cc
new file mode 100644
index 0000000..57c006b
--- /dev/null
+++ b/paludis/repositories/cran/cran_description.cc
@@ -0,0 +1,103 @@
+/* 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 <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/config_file.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/strip.hh>
+#include <string>
+
+using namespace paludis;
+
+CRANDescription::CRANDescription(const std::string & n, const FSEntry & f) :
+ name("cran/" + n),
+ version("0"),
+ metadata(new VersionMetadata::CRAN(CRANDepParser::parse))
+{
+ Context context("When parsing file '" + stringify(f) + "' for package '" + n + "':");
+
+ if (! f.is_regular_file())
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Unexpected irregular file: '" + stringify(f) + "'.");
+ metadata->set<vm_eapi>("INVALID");
+
+ return;
+ }
+
+ LineConfigFile file(f);
+ LineConfigFile::Iterator l(file.begin()), l_end(file.end());
+
+ // Fill in default values
+ metadata->set<vm_slot>(SlotName("0"));
+ metadata->set<vm_eapi>("CRAN-0");
+ metadata->get_cran_interface()->set<cranvm_keywords>(std::string("*"));
+
+ std::string key;
+ for ( ; l != l_end ; ++l)
+ {
+ Context context("When parsing line '" + *l + "':");
+
+ std::string line(strip_leading(strip_trailing(*l, " \t\r\n"), " \t\r\n")), value;
+ std::string::size_type pos(line.find(':'));
+ if (std::string::npos == pos)
+ {
+ value = strip_leading(strip_trailing(line, " \t"), " \t");
+ }
+ else
+ {
+ key = strip_leading(strip_trailing(line.substr(0, pos), " \t"), " \t");
+ value = strip_leading(strip_trailing(line.substr(pos + 1), " \t\r\n"), " \t\r\n");
+ }
+
+ if ("Package" == key)
+ {
+ metadata->get_cran_interface()->set<cranvm_package>(value);
+ metadata->set<vm_homepage>("http://cran.r-project.org/src/contrib/Descriptions/" + value + ".html");
+ CRANDescription::normalise_name(value);
+ if (n != value)
+ Log::get_instance()->message(ll_warning, lc_context, "Inconsistent package name in file '" +
+ stringify(name) + "': '" + n + "', '" + value + "':");
+ }
+ else if ("Bundle" == key)
+ {
+ metadata->get_cran_interface()->set<cranvm_is_bundle>(true);
+ }
+ else if ("Version" == key)
+ {
+ metadata->get_cran_interface()->set<cranvm_version>(value);
+ normalise_version(value);
+ version = VersionSpec(value);
+ }
+ else if ("Title" == key)
+ {
+ metadata->set<vm_description>(value);
+ }
+ else if ("Depends" == key)
+ {
+ if (value.empty())
+ value = "R";
+ else
+ value.append(", R");
+ metadata->get<vm_deps>().set<vmd_build_depend_string>(value);
+ metadata->get<vm_deps>().set<vmd_run_depend_string>(value);
+ }
+ }
+}
+
diff --git a/paludis/repositories/cran/cran_description.hh b/paludis/repositories/cran/cran_description.hh
new file mode 100644
index 0000000..2d34ee1
--- /dev/null
+++ b/paludis/repositories/cran/cran_description.hh
@@ -0,0 +1,129 @@
+/* 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_CRAN_DESCRIPTION_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_DESCRIPTION_HH 1
+
+#include <paludis/version_metadata.hh>
+#include <paludis/util/fs_entry.hh>
+
+namespace paludis
+{
+ /**
+ * CRANDescription as used by CRANRepository and CRANInstalledRepository
+ */
+ struct CRANDescription
+ {
+ /// Our package name.
+ QualifiedPackageName name;
+
+ /// Our package version.
+ VersionSpec version;
+
+ /// Our metadata, may be zero.
+ VersionMetadata::Pointer metadata;
+
+ /// Turn a CRAN package name into a paludis package name.
+ static void normalise_name(std::string & s)
+ {
+ std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '.'), '-');
+ }
+
+ /// Turn a paludis package name into a CRAN package name.
+ static void denormalise_name(std::string & s)
+ {
+ std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '-'), '.');
+ }
+
+ /// Turn a CRAN package version into a paludis package version.
+ static void normalise_version(std::string & s)
+ {
+ std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '-'), '.');
+ }
+
+ /// Constructor
+ CRANDescription(const std::string & n, const FSEntry & f);
+
+ /// Comparison operator
+ bool operator< (const CRANDescription & other) const
+ {
+ if (name < other.name)
+ return true;
+ if (name > other.name)
+ return false;
+ if (version < other.version)
+ return true;
+ return false;
+ }
+
+ /**
+ * Compare a CRANDescription by name only.
+ *
+ * \ingroup grpcrandesc
+ */
+ struct ComparePackage
+ {
+ bool operator() (const QualifiedPackageName & c, const CRANDescription & d) const
+ {
+ return c < d.name;
+ }
+
+ bool operator() (const CRANDescription & d, const QualifiedPackageName & c) const
+ {
+ return d.name < c;
+ }
+ };
+
+ /**
+ * Compare a CRANIDescription by name and version.
+ *
+ * \ingroup grpcrandesc
+ */
+ struct CompareVersion
+ {
+ bool operator() (const std::pair<QualifiedPackageName, VersionSpec> & c,
+ const CRANDescription & d) const
+ {
+ if (c.first < d.name)
+ return true;
+ else if (c.first > d.name)
+ return false;
+ else if (c.second < d.version)
+ return true;
+ else
+ return false;
+ }
+
+ bool operator() (const CRANDescription & d,
+ const std::pair<QualifiedPackageName, VersionSpec> & c) const
+ {
+ if (d.name < c.first)
+ return true;
+ else if (d.name > c.first)
+ return false;
+ else if (d.version < c.second)
+ return true;
+ else
+ return false;
+ }
+ };
+ };
+}
+
+#endif
diff --git a/paludis/repositories/cran/cran_installed_repository.cc b/paludis/repositories/cran/cran_installed_repository.cc
new file mode 100644
index 0000000..4d45d3c
--- /dev/null
+++ b/paludis/repositories/cran/cran_installed_repository.cc
@@ -0,0 +1,587 @@
+/* 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 <paludis/hashed_containers.hh>
+#include <paludis/config_file.hh>
+#include <paludis/match_package.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_installed_repository.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/iterator.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/pstream.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <fstream>
+#include <functional>
+#include <algorithm>
+#include <vector>
+
+using namespace paludis;
+
+
+namespace paludis
+{
+ /// Map for metadata.
+ typedef MakeHashedMap<std::pair<QualifiedPackageName, VersionSpec>, VersionMetadata::Pointer>::Type MetadataMap;
+
+ template <>
+ struct Implementation<CRANInstalledRepository> :
+ InternalCounted<Implementation<CRANInstalledRepository> >
+ {
+ /// Our owning db..
+ const PackageDatabase * const db;
+
+ /// Our owning env.
+ const Environment * const env;
+
+ /// Our base location.
+ FSEntry location;
+
+ /// Root location
+ FSEntry root;
+
+ /// World file.
+ FSEntry world_file;
+
+ // Do we have entries loaded?
+ mutable bool entries_valid;
+
+ mutable std::vector<CRANDescription> entries;
+
+ /// Load entries.
+ void load_entries() const;
+
+ /// Load metadata for one entry.
+ void load_entry(std::vector<CRANDescription>::iterator) const;
+
+ /// Metadata cache
+ mutable MetadataMap metadata;
+
+ /// Provide map.
+ mutable std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
+ /// Constructor.
+ Implementation(const CRANInstalledRepositoryParams &);
+
+ /// Destructor.
+ ~Implementation();
+
+ /// Invalidate.
+ void invalidate() const;
+ };
+}
+
+Implementation<CRANInstalledRepository>::Implementation(const CRANInstalledRepositoryParams & p) :
+ db(p.get<craninstrpk_package_database>()),
+ env(p.get<craninstrpk_environment>()),
+ location(p.get<craninstrpk_location>()),
+ root(p.get<craninstrpk_root>()),
+ world_file(p.get<craninstrpk_world>()),
+ entries_valid(false)
+{
+}
+
+Implementation<CRANInstalledRepository>::~Implementation()
+{
+}
+
+void
+Implementation<CRANInstalledRepository>::load_entries() const
+{
+ Context context("When loading CRANInstalledRepository entries from '" +
+ stringify(location) + "':");
+
+ entries.clear();
+ entries_valid = true;
+ try
+ {
+ for (DirIterator d(location), d_end ; d != d_end ; ++d)
+ {
+ Context context("When parsing directoryy '" + stringify(*d) + "'.");
+ if (! d->is_directory())
+ continue;
+
+ FSEntry f(FSEntry(stringify(*d)) / "DESCRIPTION");
+ if (! f.is_regular_file())
+ continue;
+
+ std::string n(d->basename());
+ CRANDescription::normalise_name(n);
+
+ CRANDescription desc(n, f);
+ entries.push_back(desc);
+
+ QualifiedPackageName q("cran/" + n);
+ metadata.insert(std::make_pair(std::make_pair(q, VersionSpec(desc.version)), desc.metadata));
+ }
+ }
+ catch (...)
+ {
+ entries_valid = false;
+ throw;
+ }
+}
+
+void
+Implementation<CRANInstalledRepository>::invalidate() const
+{
+ entries_valid = false;
+ entries.clear();
+}
+
+CRANInstalledRepository::CRANInstalledRepository(const CRANInstalledRepositoryParams & p) :
+ Repository(RepositoryName("cran_installed"),
+ RepositoryCapabilities::create((
+ param<repo_mask>(static_cast<MaskInterface *>(0)),
+ param<repo_installable>(static_cast<InstallableInterface *>(0)),
+ param<repo_installed>(this),
+ param<repo_news>(static_cast<NewsInterface *>(0)),
+ param<repo_sets>(this),
+ param<repo_syncable>(static_cast<SyncableInterface *>(0)),
+ param<repo_uninstallable>(this),
+ param<repo_use>(static_cast<UseInterface *>(0)),
+ param<repo_world>(this),
+ param<repo_environment_variable>(static_cast<EnvironmentVariableInterface *>(0)),
+ param<repo_mirrors>(static_cast<MirrorInterface *>(0))
+ ))),
+ PrivateImplementationPattern<CRANInstalledRepository>(new Implementation<CRANInstalledRepository>(p))
+{
+ RepositoryInfoSection::Pointer config_info(new RepositoryInfoSection("Configuration information"));
+
+ config_info->add_kv("location", stringify(_imp->location));
+ config_info->add_kv("root", stringify(_imp->root));
+ config_info->add_kv("format", std::string("cran-installed"));
+
+ _info->add_section(config_info);
+}
+
+CRANInstalledRepository::~CRANInstalledRepository()
+{
+}
+
+bool
+CRANInstalledRepository::do_has_category_named(const CategoryNamePart & c) const
+{
+ return (CategoryNamePart("cran") == c);
+}
+
+bool
+CRANInstalledRepository::do_has_package_named(const QualifiedPackageName & q) const
+{
+ Context context("When checking for package '" + stringify(q) +
+ "' in " + stringify(name()) + ":");
+
+ if (! do_has_category_named(q.get<qpn_category>()))
+ return false;
+
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ std::pair<std::vector<CRANDescription>::const_iterator, std::vector<CRANDescription>::const_iterator>
+ r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), q,
+ CRANDescription::ComparePackage()));
+
+ return r.first != r.second;
+}
+
+CategoryNamePartCollection::ConstPointer
+CRANInstalledRepository::do_category_names() const
+{
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection::Concrete);
+ result->insert(CategoryNamePart("cran"));
+ return result;
+}
+
+QualifiedPackageNameCollection::ConstPointer
+CRANInstalledRepository::do_package_names(const CategoryNamePart & c) const
+{
+ Context context("When fetching package names in category '" + stringify(c)
+ + "' in " + stringify(name()) + ":");
+
+ QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
+ if (! do_has_category_named(c))
+ return result;
+
+ std::vector<CRANDescription>::const_iterator e(_imp->entries.begin()), e_end(_imp->entries.end());
+ for ( ; e != e_end ; ++e)
+ result->insert(e->name);
+
+ return result;
+}
+
+VersionSpecCollection::ConstPointer
+CRANInstalledRepository::do_version_specs(const QualifiedPackageName & n) const
+{
+ Context context("When fetching versions of '" + stringify(n) + "' in "
+ + stringify(name()) + ":");
+
+ VersionSpecCollection::Pointer result(new VersionSpecCollection::Concrete);
+
+ std::pair<std::vector<CRANDescription>::const_iterator, std::vector<CRANDescription>::const_iterator>
+ r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), n,
+ CRANDescription::ComparePackage()));
+
+ for ( ; r.first != r.second ; ++(r.first))
+ result->insert(r.first->version);
+
+ return result;
+}
+
+bool
+CRANInstalledRepository::do_has_version(const QualifiedPackageName & q,
+ const VersionSpec & v) const
+{
+ Context context("When checking for version '" + stringify(v) + "' in '"
+ + stringify(q) + "' in " + stringify(name()) + ":");
+
+ VersionSpecCollection::ConstPointer versions(do_version_specs(q));
+ return versions->end() != versions->find(v);
+}
+
+VersionMetadata::ConstPointer
+CRANInstalledRepository::do_version_metadata(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ if (_imp->metadata.end() != _imp->metadata.find(
+ std::make_pair(q, v)))
+ return _imp->metadata.find(std::make_pair(q, v))->second;
+
+ Context context("When fetching metadata for " + stringify(q) +
+ "-" + stringify(v));
+
+ if (! has_version(q, v))
+ throw NoSuchPackageError(stringify(PackageDatabaseEntry(q, v, name())));
+
+ VersionMetadata::Pointer result(0);
+
+ FSEntry d(_imp->location);
+ d /= stringify(q.get<qpn_package>());
+ d /= "DESCRIPTION";
+
+ if (d.is_regular_file())
+ {
+ CRANDescription description(stringify(q.get<qpn_package>()), d);
+ result = description.metadata;
+ }
+ else
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "has_version failed for request for '" +
+ stringify(q) + "-" + stringify(v) + "' in repository '" +
+ stringify(name()) + "': No DESCRIPTION file present.");
+ result.assign(new VersionMetadata(CRANDepParser::parse));
+ result->set<vm_eapi>("UNKNOWN");
+ return result;
+ }
+
+ _imp->metadata.insert(std::make_pair(std::make_pair(q, v), result));
+ return result;
+}
+
+Contents::ConstPointer
+CRANInstalledRepository::do_contents(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ Context context("When fetching contents for " + stringify(q) +
+ "-" + stringify(v));
+
+ Contents::Pointer result(new Contents);
+
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ if (! has_version(q, v))
+ return result;
+
+ std::string pn = stringify(q.get<qpn_package>());
+ CRANDescription::normalise_name(pn);
+ FSEntry f(_imp->location / "paludis" / pn / "CONTENTS");
+ if (! f.is_regular_file())
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "CONTENTS lookup failed for request for' " +
+ stringify(q) + "-" + stringify(v) + "' in CRANInstalled '" +
+ stringify(_imp->location) + "'");
+ return result;
+ }
+
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ throw InternalError(PALUDIS_HERE, "TODO reading " + stringify(_imp->location) + " name " +
+ stringify(q) + " version " + stringify(v) + " CONTENTS"); /// \todo
+
+ std::string line;
+ unsigned line_number(0);
+ while (std::getline(ff, line))
+ {
+ ++line_number;
+
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(line, std::back_inserter(tokens));
+ if (tokens.empty())
+ continue;
+
+ if (tokens.size() < 2)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "CONTENTS for '" +
+ stringify(q) + "-" + stringify(v) + "' in vdb '" +
+ stringify(_imp->location) + "' has broken line " +
+ stringify(line_number) + ", skipping");
+ continue;
+ }
+
+ if ("obj" == tokens.at(0))
+ result->add(ContentsEntry::Pointer(new ContentsFileEntry(tokens.at(1))));
+ else if ("dir" == tokens.at(0))
+ result->add(ContentsEntry::Pointer(new ContentsDirEntry(tokens.at(1))));
+ else if ("misc" == tokens.at(0))
+ result->add(ContentsEntry::Pointer(new ContentsMiscEntry(tokens.at(1))));
+ else if ("sym" == tokens.at(0))
+ {
+ if (tokens.size() < 4)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "CONTENTS for '" +
+ stringify(q) + "-" + stringify(v) + "' in vdb '" +
+ stringify(_imp->location) + "' has broken sym line " +
+ stringify(line_number) + ", skipping");
+ continue;
+ }
+
+ result->add(ContentsEntry::Pointer(new ContentsSymEntry(
+ tokens.at(1), tokens.at(3))));
+ }
+ }
+
+ return result;
+}
+
+CountedPtr<Repository>
+CRANInstalledRepository::make_cran_installed_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m)
+{
+ Context context("When making CRAN installed repository from repo_file '" +
+ (m->end() == m->find("repo_file") ? std::string("?") : m->find("repo_file")->second) + "':");
+
+ std::string location;
+ if (m->end() == m->find("location") || ((location = m->find("location")->second)).empty())
+ throw CRANInstalledRepositoryConfigurationError("Key 'location' not specified or empty");
+
+ std::string root;
+ if (m->end() == m->find("root") || ((root = m->find("root")->second)).empty())
+ root = "/";
+
+ std::string world;
+ if (m->end() == m->find("world") || ((world = m->find("world")->second)).empty())
+ world = location + "/world";
+
+ return CountedPtr<Repository>(new CRANInstalledRepository(CRANInstalledRepositoryParams::create((
+ param<craninstrpk_environment>(env),
+ param<craninstrpk_package_database>(db),
+ param<craninstrpk_location>(location),
+ param<craninstrpk_root>(root),
+ param<craninstrpk_world>(world)))));
+}
+
+CRANInstalledRepositoryConfigurationError::CRANInstalledRepositoryConfigurationError(
+ const std::string & msg) throw () :
+ ConfigurationError("CRAN installed repository configuration error: " + msg)
+{
+}
+
+bool
+CRANInstalledRepository::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
+void
+CRANInstalledRepository::do_uninstall(const QualifiedPackageName & q, const VersionSpec & v,
+ const InstallOptions &) const
+{
+ Context context("When uninstalling '" + stringify(q) + "-" + stringify(v) +
+ "' from '" + stringify(name()) + "':");
+
+ if (! _imp->location.is_directory())
+ throw PackageInstallActionError("Couldn't uninstall '" + stringify(q) + "-" +
+ stringify(v) + "' because its location ('" + stringify(_imp->location) + "') is not a directory");
+
+ VersionMetadata::ConstPointer vm(do_version_metadata(q, v));
+
+ MakeEnvCommand cmd(LIBEXECDIR "/paludis/cran.bash unmerge", "");
+ cmd = cmd("PN", vm->get_cran_interface()->get<cranvm_package>());
+ cmd = cmd("PV", stringify(v));
+ cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->location));
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+
+
+
+ if (0 != run_command(cmd))
+ throw PackageUninstallActionError("Couldn't unmerge '" + stringify(q) + "-" + stringify(v) + "'");
+}
+
+DepAtom::Pointer
+CRANInstalledRepository::do_package_set(const std::string & s, const PackageSetOptions &) const
+{
+ Context context("When fetching package set '" + s + "' from '" +
+ stringify(name()) + "':");
+
+ if ("everything" == s)
+ {
+ AllDepAtom::Pointer result(new AllDepAtom);
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ for (std::vector<CRANDescription>::const_iterator p(_imp->entries.begin()),
+ p_end(_imp->entries.end()) ; p != p_end ; ++p)
+ {
+ PackageDepAtom::Pointer atom(new PackageDepAtom(p->name));
+ result->add_child(atom);
+ }
+
+ return result;
+ }
+ else if ("world" == s)
+ {
+ AllDepAtom::Pointer result(new AllDepAtom);
+
+ if (_imp->world_file.exists())
+ {
+ LineConfigFile world(_imp->world_file);
+
+ for (LineConfigFile::Iterator line(world.begin()), line_end(world.end()) ;
+ line != line_end ; ++line)
+ {
+ PackageDepAtom::Pointer atom(new PackageDepAtom(QualifiedPackageName(*line)));
+ result->add_child(atom);
+ }
+ }
+ else
+ Log::get_instance()->message(ll_warning, lc_no_context, "World file '" + stringify(_imp->world_file)
+ + "' doesn't exist");
+
+ return result;
+ }
+ else
+ return DepAtom::Pointer(0);
+}
+
+bool
+CRANInstalledRepository::do_sync() const
+{
+ return false;
+}
+
+void
+CRANInstalledRepository::invalidate() const
+{
+ _imp->invalidate();
+}
+
+Repository::ProvideMapIterator
+CRANInstalledRepository::begin_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
+Repository::ProvideMapIterator
+CRANInstalledRepository::end_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
+void
+CRANInstalledRepository::add_to_world(const QualifiedPackageName & n) const
+{
+ bool found(false);
+
+ if (_imp->world_file.exists())
+ {
+ LineConfigFile world(_imp->world_file);
+
+ for (LineConfigFile::Iterator line(world.begin()), line_end(world.end()) ;
+ line != line_end ; ++line)
+ if (QualifiedPackageName(*line) == n)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (! found)
+ {
+ std::ofstream world(stringify(_imp->world_file).c_str(), std::ios::out | std::ios::app);
+ if (! world)
+ Log::get_instance()->message(ll_warning, lc_no_context, "Cannot append to world file '"
+ + stringify(_imp->world_file) + "', skipping world update");
+ else
+ world << n << std::endl;
+ }
+}
+
+void
+CRANInstalledRepository::remove_from_world(const QualifiedPackageName & n) const
+{
+ std::list<std::string> world_lines;
+
+ if (_imp->world_file.exists())
+ {
+ std::ifstream world_file(stringify(_imp->world_file).c_str());
+
+ if (! world_file)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Cannot read world file '"
+ + stringify(_imp->world_file) + "', skipping world update");
+ return;
+ }
+
+ std::string line;
+ while (std::getline(world_file, line))
+ {
+ if (strip_leading(strip_trailing(line, " \t"), "\t") != stringify(n))
+ world_lines.push_back(line);
+ else
+ Log::get_instance()->message(ll_debug, lc_context, "Removing line '"
+ + line + "' from world file '" + stringify(_imp->world_file));
+ }
+ }
+
+ std::ofstream world_file(stringify(_imp->world_file).c_str());
+
+ if (! world_file)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Cannot write world file '"
+ + stringify(_imp->world_file) + "', skipping world update");
+ return;
+ }
+
+ std::copy(world_lines.begin(), world_lines.end(),
+ std::ostream_iterator<std::string>(world_file, "\n"));
+}
diff --git a/paludis/repositories/cran/cran_installed_repository.hh b/paludis/repositories/cran/cran_installed_repository.hh
new file mode 100644
index 0000000..3b8cd6c
--- /dev/null
+++ b/paludis/repositories/cran/cran_installed_repository.hh
@@ -0,0 +1,186 @@
+/* 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_CRAN_INSTALLED_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_INSTALLED_REPOSITORY_HH 1
+
+#include <paludis/repository.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/smart_record.hh>
+#include <paludis/util/fs_entry.hh>
+
+/** \file
+ * Declarations for CRANInstalledRepository.
+ *
+ * \ingroup grpcraninstrepository
+ */
+
+
+namespace paludis
+{
+ /**
+ * Keys for CRANInstalledRepositoryParams
+ *
+ * \see CRANInstalledRepositoryParams
+ * \ingroup grpcraninstrepository
+ */
+ enum CRANInstalledRepositoryParamsKeys
+ {
+ craninstrpk_environment,
+ craninstrpk_package_database,
+ craninstrpk_location,
+ craninstrpk_root,
+ craninstrpk_world,
+ last_craninstrpk
+ };
+
+ /**
+ * Tag for CRANInstalledRepositoryParams.
+ *
+ * \see CRANInstalledRepositoryParams
+ * \ingroup grpcraninstrepository
+ */
+ struct CRANInstalledRepositoryParamsTag :
+ SmartRecordTag<comparison_mode::NoComparisonTag, void>,
+ SmartRecordKeys<CRANInstalledRepositoryParamsKeys, last_craninstrpk>,
+ SmartRecordKey<craninstrpk_environment, const Environment *>,
+ SmartRecordKey<craninstrpk_package_database, const PackageDatabase *>,
+ SmartRecordKey<craninstrpk_location, const FSEntry>,
+ SmartRecordKey<craninstrpk_root, const FSEntry>,
+ SmartRecordKey<craninstrpk_world, const FSEntry>
+ {
+ };
+
+ /**
+ * Constructor parameters for CRANInstalledRepository.
+ *
+ * \see CRANInstalledRepository
+ * \ingroup grpcraninstrepository
+ */
+ typedef MakeSmartRecord<CRANInstalledRepositoryParamsTag>::Type CRANInstalledRepositoryParams;
+
+ /**
+ * A CRANInstalledRepository represents the database used for
+ * installed CRAN packages.
+ *
+ * \ingroup grpcraninstrepository
+ */
+ class CRANInstalledRepository :
+ public Repository,
+ public Repository::InstalledInterface,
+ public Repository::UninstallableInterface,
+ public Repository::SetsInterface,
+ public Repository::WorldInterface,
+ public PrivateImplementationPattern<CRANInstalledRepository>
+ {
+ protected:
+ virtual bool do_has_category_named(const CategoryNamePart &) const;
+
+ virtual bool do_has_package_named(const QualifiedPackageName &) const;
+
+ virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+
+ virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
+ const CategoryNamePart &) const;
+
+ virtual VersionSpecCollection::ConstPointer do_version_specs(
+ const QualifiedPackageName &) const;
+
+ virtual bool do_has_version(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual VersionMetadata::ConstPointer do_version_metadata(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual Contents::ConstPointer do_contents(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual bool do_is_licence(const std::string &) const;
+
+ virtual void do_uninstall(const QualifiedPackageName &, const VersionSpec &,
+ const InstallOptions &) const;
+
+ virtual DepAtom::Pointer do_package_set(const std::string &, const PackageSetOptions &) const;
+
+ virtual bool do_sync() const;
+
+ public:
+ /**
+ * Constructor.
+ */
+ CRANInstalledRepository(const CRANInstalledRepositoryParams &);
+
+ /**
+ * Virtual constructor.
+ */
+ static CountedPtr<Repository> make_cran_installed_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m);
+
+ /**
+ * Destructor.
+ */
+ ~CRANInstalledRepository();
+
+ virtual bool installed() const
+ {
+ return true;
+ }
+
+ virtual void invalidate() const;
+
+ virtual ProvideMapIterator begin_provide_map() const;
+
+ virtual ProvideMapIterator end_provide_map() const;
+
+ virtual void add_to_world(const QualifiedPackageName &) const;
+
+ virtual void remove_from_world(const QualifiedPackageName &) const;
+ };
+
+ /**
+ * Thrown if invalid parameters are provided for
+ * PortageRepository::make_portage_repository.
+ *
+ * \ingroup grpcraninstrepository
+ * \ingroup grpexceptions
+ */
+ class CRANInstalledRepositoryConfigurationError : public ConfigurationError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ CRANInstalledRepositoryConfigurationError(const std::string & msg) throw ();
+ };
+
+ /**
+ * Register the CRAN Installed repository format.
+ *
+ * \ingroup grpcraninstrepository
+ */
+ static const RepositoryMaker::RegisterMaker register_cran_installed_repository(
+ "cran_installed", &CRANInstalledRepository::make_cran_installed_repository);
+}
+
+#endif
diff --git a/paludis/repositories/cran/cran_repository.cc b/paludis/repositories/cran/cran_repository.cc
new file mode 100644
index 0000000..3750496
--- /dev/null
+++ b/paludis/repositories/cran/cran_repository.cc
@@ -0,0 +1,625 @@
+/* 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 "config.h"
+
+#include <paludis/dep_atom.hh>
+#include <paludis/dep_atom_flattener.hh>
+#include <paludis/hashed_containers.hh>
+#include <paludis/config_file.hh>
+#include <paludis/match_package.hh>
+#include <paludis/package_database_entry.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_repository.hh>
+#include <paludis/syncer.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/iterator.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/pstream.hh>
+#include <paludis/util/random.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <map>
+#include <list>
+#include <fstream>
+#include <functional>
+#include <algorithm>
+#include <vector>
+#include <deque>
+#include <limits>
+
+#include <strings.h>
+#include <ctype.h>
+
+/** \file
+ * Implementation CRANRepository.
+ *
+ * \ingroup grpcranrepository
+ */
+
+using namespace paludis;
+
+namespace paludis
+{
+ /// Map for versions.
+ typedef MakeHashedMap<QualifiedPackageName, VersionSpec>::Type VersionsMap;
+
+ /// Map for packages.
+ typedef MakeHashedMap<QualifiedPackageName, bool>::Type PackagesMap;
+
+ /// Map for mirrors.
+ typedef MakeHashedMap<std::string, std::list<std::string> >::Type MirrorMap;
+
+ /// Map for metadata.
+ typedef MakeHashedMap<std::pair<QualifiedPackageName, VersionSpec>, VersionMetadata::Pointer>::Type MetadataMap;
+
+ /**
+ * Implementation data for a CRANRepository.
+ *
+ * \ingroup grpportagerepository
+ */
+ template <>
+ struct Implementation<CRANRepository> :
+ InternalCounted<Implementation<CRANRepository> >
+ {
+ /// Our owning db.
+ const PackageDatabase * const db;
+
+ /// Our owning env.
+ const Environment * const env;
+
+ /// Our base location.
+ FSEntry location;
+
+ /// Distfiles dir
+ FSEntry distdir;
+
+ /// Mirror URL
+ std::string mirror;
+
+ /// Sync URL
+ std::string sync;
+
+ /// Build root location
+ FSEntry buildroot;
+
+ /// Root location
+ FSEntry root;
+
+ /// Library location
+ FSEntry library;
+
+ /// Have we loaded our category names?
+ mutable bool has_packages;
+
+ /// Our package names, and whether we have a fully loaded list of
+ /// version specs for that category.
+ mutable PackagesMap package_names;
+
+ /// Our version specs for each package.
+ mutable VersionsMap version_specs;
+
+ /// Metadata cache.
+ mutable MetadataMap metadata;
+
+ /// Do we have mirrors?
+ mutable bool has_mirrors;
+
+ /// Mirrors.
+ mutable MirrorMap mirrors;
+
+ /// Constructor.
+ Implementation(const CRANRepositoryParams &);
+
+ /// Destructor.
+ ~Implementation();
+
+ /// Invalidate our cache.
+ void invalidate() const;
+
+ /// (Empty) provides map.
+ const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+ };
+}
+
+Implementation<CRANRepository>::Implementation(const CRANRepositoryParams & p) :
+ db(p.get<cranrpk_package_database>()),
+ env(p.get<cranrpk_environment>()),
+ location(p.get<cranrpk_location>()),
+ distdir(p.get<cranrpk_distdir>()),
+ mirror(p.get<cranrpk_mirror>()),
+ sync(p.get<cranrpk_sync>()),
+ buildroot(p.get<cranrpk_buildroot>()),
+ root(p.get<cranrpk_root>()),
+ library(p.get<cranrpk_library>()),
+ has_packages(false),
+ has_mirrors(false)
+{
+}
+
+Implementation<CRANRepository>::~Implementation()
+{
+}
+
+void
+Implementation<CRANRepository>::invalidate() const
+{
+ package_names.clear();
+ has_packages = false;
+ version_specs.clear();
+ metadata.clear();
+ has_mirrors = false;
+ mirrors.clear();
+}
+
+
+CRANRepository::CRANRepository(const CRANRepositoryParams & p) :
+ Repository(CRANRepository::fetch_repo_name(stringify(p.get<cranrpk_location>())),
+ RepositoryCapabilities::create((
+ param<repo_mask>(static_cast<MaskInterface *>(0)),
+ param<repo_installable>(this),
+ param<repo_installed>(static_cast<InstalledInterface *>(0)),
+ param<repo_news>(static_cast<NewsInterface *>(0)),
+ param<repo_sets>(this),
+ param<repo_syncable>(this),
+ param<repo_uninstallable>(static_cast<UninstallableInterface *>(0)),
+ param<repo_use>(static_cast<UseInterface *>(0)),
+ param<repo_world>(static_cast<WorldInterface *>(0)),
+ param<repo_environment_variable>(static_cast<EnvironmentVariableInterface *>(0)),
+ param<repo_mirrors>(static_cast<MirrorInterface *>(0))
+ ))),
+ PrivateImplementationPattern<CRANRepository>(new Implementation<CRANRepository>(p))
+{
+ RepositoryInfoSection::Pointer config_info(new RepositoryInfoSection("Configuration information"));
+
+ config_info->add_kv("location", stringify(_imp->location));
+ config_info->add_kv("distdir", stringify(_imp->distdir));
+ config_info->add_kv("format", "cran");
+ config_info->add_kv("buildroot", stringify(_imp->buildroot));
+ config_info->add_kv("root", stringify(_imp->root));
+ config_info->add_kv("library", stringify(_imp->library));
+ config_info->add_kv("sync", _imp->sync);
+
+ _info->add_section(config_info);
+}
+
+CRANRepository::~CRANRepository()
+{
+}
+
+bool
+CRANRepository::do_has_category_named(const CategoryNamePart & c) const
+{
+ Context context("When checking for category '" + stringify(c) +
+ "' in " + stringify(name()) + ":");
+
+ return "cran" == stringify(c);
+}
+
+bool
+CRANRepository::do_has_package_named(const QualifiedPackageName & q) const
+{
+ Context context("When checking for package '" + stringify(q) + "' in " +
+ stringify(name()) + ":");
+
+ need_packages();
+
+ if (! do_has_category_named(q.get<qpn_category>()))
+ return false;
+
+ return _imp->package_names.end() != _imp->package_names.find(q);
+}
+
+CategoryNamePartCollection::ConstPointer
+CRANRepository::do_category_names() const
+{
+ Context context("When fetching category names in " + stringify(name()) + ":");
+
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection::Concrete);
+ result->insert(CategoryNamePart("cran"));
+
+ return result;
+}
+
+QualifiedPackageNameCollection::ConstPointer
+CRANRepository::do_package_names(const CategoryNamePart & c) const
+{
+ Context context("When fetching package names in category '" + stringify(c)
+ + "' in " + stringify(name()) + ":");
+
+ need_packages();
+
+ QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
+ if (! do_has_category_named(c))
+ return result;
+
+ PackagesMap::const_iterator n(_imp->package_names.begin()), n_end(_imp->package_names.end());
+ for ( ; n != n_end ; ++n)
+ result->insert(n->first);
+
+ return result;
+}
+
+VersionSpecCollection::ConstPointer
+CRANRepository::do_version_specs(const QualifiedPackageName & n) const
+{
+ Context context("When fetching versions of '" + stringify(n) + "' in "
+ + stringify(name()) + ":");
+
+ need_packages();
+
+ VersionSpecCollection::Pointer result(new VersionSpecCollection::Concrete);
+ if (_imp->version_specs.end() != _imp->version_specs.find(n))
+ result->insert(_imp->version_specs.find(n)->second);
+
+ return result;
+}
+
+bool
+CRANRepository::do_has_version(const QualifiedPackageName & q,
+ const VersionSpec & v) const
+{
+ Context context("When checking for version '" + stringify(v) + "' in '"
+ + stringify(q) + "' in " + stringify(name()) + ":");
+
+ need_packages();
+
+ if (has_package_named(q))
+ return v == _imp->version_specs.find(q)->second;
+ else
+ return false;
+}
+
+void
+CRANRepository::need_packages() const
+{
+ if (_imp->has_packages)
+ return;
+
+ Context context("When loading category names for " + stringify(name()) + ":");
+
+ LineConfigFile packages(FSEntry(_imp->location / "PACKAGES"));
+ LineConfigFile::Iterator l(packages.begin()), l_end(packages.end());
+ std::string last_package_name;
+ bool skip_invalid_package = false;
+ for ( ; l != l_end ; ++l)
+ {
+ Context context("When parsing line '" + *l + "':");
+
+ std::string line(strip_leading(strip_trailing(*l, " \t"), " \t"));
+ if (line.empty())
+ continue;
+
+ std::string::size_type pos(line.find(':'));
+ if (std::string::npos == pos)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Broken line in PACKAGES file: '" + stringify(_imp->location / "PACKAGES") + "'");
+ continue;
+ }
+
+ std::string key(line.substr(0, pos)), value(line.substr(pos + 1));
+ key = strip_leading(strip_trailing(key, " \t"), " \t");
+ value = strip_leading(strip_trailing(value, " \t"), " \t");
+ if (("Package" != key) && (skip_invalid_package))
+ {
+ skip_invalid_package = false;
+ continue;
+ }
+
+ if ("Package" == key)
+ {
+ CRANDescription::normalise_name(value);
+ last_package_name = value;
+ QualifiedPackageName package_name(CategoryNamePart("cran"), PackageNamePart(last_package_name));
+ _imp->package_names[package_name] = true;
+ }
+ else if ("Version" == key)
+ {
+ QualifiedPackageName package_name(CategoryNamePart("cran"), PackageNamePart(last_package_name));
+ CRANDescription::normalise_version(value);
+ VersionSpec version(value);
+ if (false == _imp->version_specs.insert(VersionsMap::value_type(package_name, version)).second)
+ {
+ skip_invalid_package = true;
+ Log::get_instance()->message(ll_warning, lc_context, "Multiple versions for package '"
+ + last_package_name + "'.");
+ continue;
+ }
+ }
+ else if ("Contains" == key)
+ {
+ std::list<std::string> contains;
+ WhitespaceTokeniser::get_instance()->tokenise(value, std::back_inserter(contains));
+ std::list<std::string>::const_iterator i(contains.begin()), i_end(contains.end());
+ // load metadata immediately
+ for ( ; i != i_end ; ++i)
+ {
+ Context c("When processing 'Contains:' line: '" + stringify(*i) + "':");
+
+ if (*i == last_package_name)
+ continue;
+
+ CRANDescription d(*i, FSEntry(_imp->location / std::string(last_package_name + ".DESCRIPTION")));
+
+ std::string dep(d.metadata->get<vm_deps>().get<vmd_build_depend_string>());
+ std::string pkg(d.metadata->get_cran_interface()->get<cranvm_package>());
+ if ("" == dep)
+ dep = pkg;
+ else
+ dep += "," + pkg;
+ d.metadata->get<vm_deps>().set<vmd_build_depend_string>(dep);
+
+ _imp->package_names[d.name] = true;
+ _imp->metadata.insert(std::make_pair(std::make_pair(d.name, d.version), d.metadata));
+ _imp->version_specs.insert(VersionsMap::value_type(d.name, d.version));
+ }
+ }
+ }
+
+ _imp->has_packages = true;
+}
+
+RepositoryName
+CRANRepository::fetch_repo_name(const std::string & location)
+{
+ std::string modified_location(FSEntry(location).basename());
+ std::replace(modified_location.begin(), modified_location.end(), '/', '-');
+ return RepositoryName("cran-" + modified_location);
+}
+
+VersionMetadata::ConstPointer
+CRANRepository::do_version_metadata(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ if (_imp->metadata.end() != _imp->metadata.find(
+ std::make_pair(q, v)))
+ return _imp->metadata.find(std::make_pair(q, v))->second;
+
+ Context context("When fetching metadata for " + stringify(q) +
+ "-" + stringify(v));
+
+ if (! has_version(q, v))
+ throw NoSuchPackageError(stringify(PackageDatabaseEntry(q, v, name())));
+
+ VersionMetadata::Pointer result(new VersionMetadata(CRANDepParser::parse));
+
+ FSEntry d(_imp->location);
+ PackageNamePart p(q.get<qpn_package>());
+ std::string n(stringify(p));
+ CRANDescription::denormalise_name(n);
+ d /= n + ".DESCRIPTION";
+
+ if (d.is_regular_file())
+ {
+ CRANDescription desc(stringify(p), d);
+ result = desc.metadata;
+ }
+ else
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "has_version failed for request for '" +
+ stringify(q) + "-" + stringify(v) + "' in repository '" +
+ stringify(name()) + "': File '" + n + ".DESCRIPTION' not present.");
+ VersionMetadata::Pointer result(new VersionMetadata(CRANDepParser::parse));
+ result->set<vm_eapi>("UNKNOWN");
+ }
+
+ _imp->metadata.insert(std::make_pair(std::make_pair(q, v), result));
+ return result;
+}
+
+Contents::ConstPointer
+CRANRepository::do_contents(
+ const CategoryNamePart &, const PackageNamePart &, const VersionSpec &) const
+{
+ return Contents::Pointer(new Contents);
+}
+
+CountedPtr<Repository>
+CRANRepository::make_cran_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m)
+{
+ Context context("When making CRAN repository from repo_file '" +
+ (m->end() == m->find("repo_file") ? std::string("?") : m->find("repo_file")->second) + "':");
+
+ std::string location;
+ if (m->end() == m->find("location") || ((location = m->find("location")->second)).empty())
+ throw CRANRepositoryConfigurationError("Key 'location' not specified or empty");
+
+ std::string library;
+ if (m->end() == m->find("library") || ((library = m->find("library")->second)).empty())
+ throw CRANRepositoryConfigurationError("Key 'library' not specified or empty");
+
+ std::string distdir;
+ if (m->end() == m->find("distdir") || ((distdir = m->find("distdir")->second)).empty())
+ distdir = location + "/distfiles";
+
+ std::string mirror;
+ if (m->end() == m->find("mirror") || ((mirror = m->find("mirror")->second)).empty())
+ mirror = "http://cran.r-project.org/";
+
+ std::string sync;
+ if (m->end() == m->find("sync") || ((sync = m->find("sync")->second)).empty())
+ sync = "rsync://cran.r-project.org/CRAN";
+
+ std::string buildroot;
+ if (m->end() == m->find("buildroot") || ((buildroot = m->find("buildroot")->second)).empty())
+ buildroot = "/var/tmp/paludis";
+
+ std::string root;
+ if (m->end() == m->find("root") || ((root = m->find("root")->second)).empty())
+ root = "/";
+
+ return CountedPtr<Repository>(new CRANRepository(CRANRepositoryParams::create((
+ param<cranrpk_environment>(env),
+ param<cranrpk_package_database>(db),
+ param<cranrpk_location>(location),
+ param<cranrpk_distdir>(distdir),
+ param<cranrpk_sync>(sync),
+ param<cranrpk_buildroot>(buildroot),
+ param<cranrpk_root>(root),
+ param<cranrpk_library>(library),
+ param<cranrpk_mirror>(mirror)))));
+}
+
+CRANRepositoryConfigurationError::CRANRepositoryConfigurationError(
+ const std::string & msg) throw () :
+ ConfigurationError("CRAN repository configuration error: " + msg)
+{
+}
+
+bool
+CRANRepository::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
+void
+CRANRepository::do_install(const QualifiedPackageName &q, const VersionSpec &vn,
+ const InstallOptions &o) const
+{
+ PackageNamePart pn(q.get<qpn_package>());
+ CategoryNamePart c("cran");
+ VersionMetadata::ConstPointer vm(do_version_metadata(q, vn));
+ std::string p(vm->get_cran_interface()->get<cranvm_package>());
+ std::string v(vm->get_cran_interface()->get<cranvm_version>());
+
+
+ MakeEnvCommand cmd(LIBEXECDIR "/paludis/cran.bash fetch", "");
+ cmd = cmd("CATEGORY", "cran");
+ cmd = cmd("DISTDIR", stringify(_imp->distdir));
+ cmd = cmd("DISTFILE", std::string(p + "_" + v + ".tar.gz"));
+ cmd = cmd("PN", stringify(pn));
+ cmd = cmd("PV", stringify(vn));
+ cmd = cmd("PALUDIS_CRAN_MIRRORS", _imp->mirror);
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string());
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+
+
+ if (0 != run_command(cmd))
+ throw PackageInstallActionError("Couldn't fetch sources for '" + stringify(q) + "-" + stringify(vn) + "'");
+
+ if (o.get<io_fetchonly>())
+ return;
+
+ std::string image(stringify(_imp->buildroot / stringify(q) / "image"));
+ std::string workdir(stringify(_imp->buildroot / stringify(q) / "work"));
+
+ cmd = MakeEnvCommand(make_sandbox_command(LIBEXECDIR "/paludis/cran.bash clean install"), "");
+ cmd = cmd("CATEGORY", "cran");
+ cmd = cmd("DISTDIR", stringify(_imp->distdir));
+ cmd = cmd("DISTFILE", std::string(p + "_" + v + ".tar.gz"));
+ cmd = cmd("IMAGE", image);
+ cmd = cmd("PN", stringify(pn));
+ cmd = cmd("PV", stringify(vn));
+ cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->library));
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string());
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+ cmd = cmd("ROOT", stringify(_imp->root));
+ cmd = cmd("WORKDIR", workdir);
+
+
+ if (0 != run_command(cmd))
+ throw PackageInstallActionError("Couldn't install '" + stringify(q) + "-" + stringify(vn) + "' to '" +
+ image + "'");
+
+ cmd = MakeEnvCommand(LIBEXECDIR "/paludis/cran.bash merge clean", "");
+ cmd = cmd("IMAGE", image);
+ cmd = cmd("PN", p);
+ cmd = cmd("PV", stringify(vn));
+ cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->library));
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", Log::get_instance()->log_level_string());
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+ cmd = cmd("ROOT", stringify(_imp->root));
+ cmd = cmd("WORKDIR", workdir);
+
+
+ if (0 != run_command(cmd))
+ throw PackageInstallActionError("Couldn't merge '" + stringify(q) + "-" + stringify(vn) + "' to '" +
+ stringify(_imp->root) + "'");
+
+ return;
+}
+
+DepAtom::Pointer
+CRANRepository::do_package_set(const std::string & s, const PackageSetOptions &) const
+{
+ if ("base" == s)
+ {
+ /**
+ * \todo Implement system as all package which are installed
+ * by dev-lang/R by default.
+ */
+ return AllDepAtom::Pointer(new AllDepAtom);
+ }
+ else
+ return DepAtom::Pointer(0);
+}
+
+bool
+CRANRepository::do_sync() const
+{
+ Context context("When syncing repository '" + stringify(name()) + "':");
+
+ std::string cmd("rsync --delete --recursive --progress --exclude \"*.html\" --exclude \"*.INDEX\" '" +
+ _imp->sync + "/src/contrib/Descriptions/' ./");
+
+ if (0 != run_command_in_directory(cmd, _imp->location))
+ return false;
+
+ cmd = "rsync --progress '" + _imp->sync + "/src/contrib/PACKAGES' ./";
+
+ if (0 != run_command_in_directory(cmd, _imp->location))
+ return false;
+
+ cmd = "rsync --progress '" + _imp->sync + "/CRAN_mirrors.csv' ./";
+
+ return 0 == run_command_in_directory(cmd, _imp->location);
+}
+
+void
+CRANRepository::invalidate() const
+{
+ _imp->invalidate();
+}
+
+Repository::ProvideMapIterator
+CRANRepository::begin_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
+Repository::ProvideMapIterator
+CRANRepository::end_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
diff --git a/paludis/repositories/cran/cran_repository.hh b/paludis/repositories/cran/cran_repository.hh
new file mode 100644
index 0000000..a15793c
--- /dev/null
+++ b/paludis/repositories/cran/cran_repository.hh
@@ -0,0 +1,195 @@
+/* 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_CRAN_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_REPOSITORY_HH 1
+
+#include <paludis/repository.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/smart_record.hh>
+#include <string>
+
+/** \file
+ * Declaration for the CRANRepository class.
+ *
+ * \ingroup grpcranrepository
+ */
+
+namespace paludis
+{
+ class PackageDatabase;
+
+ /**
+ * Keys for PortageRepositoryParams.
+ *
+ * \see PortageRepositoryParams
+ * \ingroup grpportagerepository
+ */
+ enum CRANRepositoryParamsKeys
+ {
+ cranrpk_environment,
+ cranrpk_package_database,
+ cranrpk_location,
+ cranrpk_distdir,
+ cranrpk_mirror,
+ cranrpk_sync,
+ cranrpk_buildroot,
+ cranrpk_root,
+ cranrpk_library,
+ last_cranrpk
+ };
+
+ /**
+ * Tag for CRANRepositoryParams.
+ *
+ * \see CRANRepositoryParams
+ * \ingroup grpcranrepository
+ */
+ struct CRANRepositoryParamsTag :
+ SmartRecordTag<comparison_mode::NoComparisonTag, void>,
+ SmartRecordKeys<CRANRepositoryParamsKeys, last_cranrpk>,
+ SmartRecordKey<cranrpk_environment, const Environment *>,
+ SmartRecordKey<cranrpk_package_database, const PackageDatabase *>,
+ SmartRecordKey<cranrpk_location, const FSEntry>,
+ SmartRecordKey<cranrpk_distdir, const FSEntry>,
+ SmartRecordKey<cranrpk_mirror, const std::string>,
+ SmartRecordKey<cranrpk_sync, const std::string>,
+ SmartRecordKey<cranrpk_buildroot, const FSEntry>,
+ SmartRecordKey<cranrpk_root, const FSEntry>,
+ SmartRecordKey<cranrpk_library, const FSEntry>
+ {
+ };
+
+ /**
+ * Constructor parameters for CRANRepository.
+ *
+ * \see CRANRepository
+ * \ingroup grpcranrepository
+ */
+ typedef MakeSmartRecord<CRANRepositoryParamsTag>::Type CRANRepositoryParams;
+
+ /**
+ * A CRANRepository is a Repository that handles the layout used by
+ * the GNU R project for the Comprehensive R Archive Network
+ *
+ * \ingroup grpcranrepository
+ */
+ class CRANRepository :
+ public Repository,
+ public Repository::InstallableInterface,
+ public Repository::SyncableInterface,
+ public Repository::SetsInterface,
+ private PrivateImplementationPattern<CRANRepository>
+ {
+ private:
+ void need_packages() const;
+ void need_version_names(const QualifiedPackageName &) const;
+ void need_virtual_names() const;
+
+ protected:
+ /**
+ * Try to get the repository name for a particular repository.
+ */
+ static RepositoryName fetch_repo_name(const std::string & location);
+
+ virtual bool do_has_category_named(const CategoryNamePart &) const;
+
+ virtual bool do_has_package_named(const QualifiedPackageName &) const;
+
+ virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+
+ virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
+ const CategoryNamePart &) const;
+
+ virtual VersionSpecCollection::ConstPointer do_version_specs(
+ const QualifiedPackageName &) const;
+
+ virtual bool do_has_version(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual VersionMetadata::ConstPointer do_version_metadata(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual Contents::ConstPointer do_contents(
+ const CategoryNamePart &, const PackageNamePart &,
+ const VersionSpec &) const;
+
+ virtual bool do_is_licence(const std::string &) const;
+
+ virtual void do_install(const QualifiedPackageName &, const VersionSpec &,
+ const InstallOptions &) const;
+
+ virtual DepAtom::Pointer do_package_set(const std::string &, const PackageSetOptions &) const;
+
+ virtual bool do_sync() const;
+
+ public:
+ /**
+ * Constructor.
+ */
+ CRANRepository(const CRANRepositoryParams &);
+
+ /**
+ * Virtual constructor.
+ */
+ static CountedPtr<Repository> make_cran_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m);
+
+ /**
+ * Destructor.
+ */
+ virtual ~CRANRepository();
+
+ virtual void invalidate() const;
+
+ virtual ProvideMapIterator begin_provide_map() const;
+
+ virtual ProvideMapIterator end_provide_map() const;
+
+ };
+
+ /**
+ * Thrown if invalid parameters are provided for
+ * CRANRepository::make_cran_repository.
+ *
+ * \ingroup grpexceptions
+ * \ingroup grpportagerepository
+ */
+ class CRANRepositoryConfigurationError : public ConfigurationError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ CRANRepositoryConfigurationError(const std::string & msg) throw ();
+ };
+
+ /**
+ * Register CRANRepository.
+ */
+ static const RepositoryMaker::RegisterMaker register_cran_repository(
+ "cran", &CRANRepository::make_cran_repository);
+
+}
+
+#endif
diff --git a/paludis/repositories/cran/cran_repository_TEST.cc b/paludis/repositories/cran/cran_repository_TEST.cc
new file mode 100644
index 0000000..7b00f18
--- /dev/null
+++ b/paludis/repositories/cran/cran_repository_TEST.cc
@@ -0,0 +1,97 @@
+/* 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 <paludis/dep_atom.hh>
+#include <paludis/dep_atom_flattener.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_repository.hh>
+#include <paludis/test_environment.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/system.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace test;
+using namespace paludis;
+
+/** \file
+ * Test cases for CRANRepository.
+ *
+ * \ingroup grptestcases
+ */
+
+namespace test_cases
+{
+ /**
+ * \test Test CRANRepository to parse a well formed PACKAGES file.
+ *
+ * \ingroup grptestcases
+ */
+ struct CRANRepositoryPackagesTest : TestCase
+ {
+ CRANRepositoryPackagesTest() : TestCase("PACKAGES") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "cran");
+ keys->insert("library", "cran_repository_TEST_dir/library");
+ keys->insert("location", "cran_repository_TEST_dir/repo1");
+ keys->insert("buildroot", "cran_repository_TEST_dir/tmp");
+ CRANRepository::Pointer repo(CRANRepository::make_cran_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ TEST_CHECK(repo->has_category_named(CategoryNamePart("cran")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/testpackage1")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/testpackage2")));
+ }
+ } test_cran_repository_packages;
+
+ /**
+ * \test Test CRANRepository to handly 'Bundle:'s correctly.
+ *
+ * \ingroup grptestcases
+ */
+ struct CRANRepositoryBundleTest: TestCase
+ {
+ CRANRepositoryBundleTest() : TestCase("Bundle") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "cran");
+ keys->insert("library", "cran_repository_TEST_dir/library");
+ keys->insert("location", "cran_repository_TEST_dir/repo2");
+ keys->insert("buildroot", "cran_repository_TEST_dir/tmp");
+ CRANRepository::Pointer repo(CRANRepository::make_cran_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/testbundle")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/bundlepkg1")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/bundlepkg2")));
+ }
+ } test_cran_repository_bundle;
+
+ /** \todo in repo1
+ * \todo test case for DESCRIPTION files
+ */
+}
diff --git a/paludis/repositories/cran/cran_repository_TEST_cleanup.sh b/paludis/repositories/cran/cran_repository_TEST_cleanup.sh
new file mode 100755
index 0000000..d304922
--- /dev/null
+++ b/paludis/repositories/cran/cran_repository_TEST_cleanup.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d cran_repository_TEST_dir ] ; then
+ rm -fr cran_repository_TEST_dir
+else
+ true
+fi
diff --git a/paludis/repositories/cran/cran_repository_TEST_setup.sh b/paludis/repositories/cran/cran_repository_TEST_setup.sh
new file mode 100755
index 0000000..93fdbee
--- /dev/null
+++ b/paludis/repositories/cran/cran_repository_TEST_setup.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir cran_repository_TEST_dir || exit 1
+cd cran_repository_TEST_dir || exit 1
+
+# repo1
+mkdir -p repo1
+cat <<EOF >> repo1/PACKAGES
+Package: testpackage1
+Version: 2006.05.08
+Title: Test on a well formed PACKAGES file
+Depends: R (>= 2.0.0)
+
+
+Package: testpackage2
+Version: 2006.05.08
+Title: Test on a well formed PACKAGES file
+EOF
+cat <<EOF >> repo1/testpackage1.DESCRIPTION
+Package: testpackage1
+Version: 2006.05.08
+Title: Test on a well formed PACKAGES file
+Depends: R (>= 2.0.0)
+Description: This description
+ spans
+ multiple lines without
+ trailing backslashes or leading tabs :-/
+License: Some weirdo license string
+Packaged: Mon May 08 12:00:00 2006; kugelfang
+EOF
+cat <<EOF >> repo1/testpackage2.DESCRIPTION
+Package: testpackage2
+Version: 1
+Title: 2nd Test Packages
+Depends: R, testpackage1
+License: Another weirdo license string
+Packaged: Mon May 08 22:00:00 2006; kugelfang
+EOF
+
+mkdir -p repo2
+cat <<EOF >> repo2/PACKAGES
+Package: testbundle
+Version: 1
+Title: Testbundle for bundlepkg1 and bundlepkg2
+Bundle: testbundle
+Contains: bundlepkg1 bundlepkg2
+EOF
+cat <<EOF >> repo2/testbundle.DESCRIPTION
+Bundle: testbundle
+Version: 1
+Date: 21 May 2006
+Title: Testbundle for bundlepkg1 and bundlepkg2
+Contains: bundlepkg1 bundlepkg2
+License: Weird obfuscation of GPL
+Packaged: Sun May 21 12:34:56 2006; kugelfang
+EOF
diff --git a/paludis/version_metadata.cc b/paludis/version_metadata.cc
index 6126190..bee0a7a 100644
--- a/paludis/version_metadata.cc
+++ b/paludis/version_metadata.cc
@@ -58,14 +58,24 @@ VersionMetadataDeps::post_depend() const
return get<vmd_parser>()(get<vmd_post_depend_string>());
}
+VersionMetadata::CRAN::CRAN(ParserFunction f) :
+ VersionMetadata(f, &_c, 0, 0),
+ _c(CRANVersionMetadata::create((
+ param<cranvm_keywords>(""),
+ param<cranvm_package>(""),
+ param<cranvm_version>(""),
+ param<cranvm_is_bundle>(false))))
+{
+}
+
VersionMetadata::Ebuild::Ebuild(ParserFunction f) :
- VersionMetadata(f, &_e, 0),
+ VersionMetadata(f, 0, &_e, 0),
_e()
{
}
VersionMetadata::Ebin::Ebin(ParserFunction f) :
- VersionMetadata(f, &_e, &_eb),
+ VersionMetadata(f, 0, &_e, &_eb),
_e(),
_eb()
{
@@ -85,11 +95,15 @@ VersionMetadata::VersionMetadata(ParserFunction p) :
param<vm_eapi>("UNSET"),
param<vm_license>("")
))),
- _ebuild_if(0)
+ _cran_if(0),
+ _ebuild_if(0),
+ _ebin_if(0)
{
}
-VersionMetadata::VersionMetadata(ParserFunction p, EbuildVersionMetadata * ebuild_if,
+VersionMetadata::VersionMetadata(ParserFunction p,
+ CRANVersionMetadata * cran_if,
+ EbuildVersionMetadata * ebuild_if,
EbinVersionMetadata * ebin_if) :
MakeSmartRecord<VersionMetadataTag>::Type(MakeSmartRecord<VersionMetadataTag>::Type::create((
param<vm_slot>(SlotName("unset")),
@@ -100,8 +114,9 @@ VersionMetadata::VersionMetadata(ParserFunction p, EbuildVersionMetadata * ebuil
param<vm_eapi>("UNSET"),
param<vm_license>("")
))),
- _ebuild_if(ebuild_if),
- _ebin_if(ebin_if)
+ _cran_if(cran_if),
+ _ebuild_if(ebuild_if),
+ _ebin_if(ebin_if)
{
}
@@ -138,4 +153,3 @@ VersionMetadata::license() const
return PortageDepParser::parse(get<vm_license>(), PortageDepParserPolicy<PlainTextDepAtom,
true>::get_instance());
}
-
diff --git a/paludis/version_metadata.hh b/paludis/version_metadata.hh
index f8917ba..c93120a 100644
--- a/paludis/version_metadata.hh
+++ b/paludis/version_metadata.hh
@@ -190,7 +190,6 @@ namespace paludis
* Constructor.
*/
EbuildVersionMetadata();
-
/**
* PROVIDE, as a dep atom.
*/
@@ -198,6 +197,45 @@ namespace paludis
};
/**
+ * Key for CRANVersionMetadata.
+ *
+ * \see CRANVersionMetadata
+ * \ingroup grpversions
+ */
+ enum CRANVersionMetadataKey
+ {
+ cranvm_keywords,
+ cranvm_package,
+ cranvm_version,
+ cranvm_is_bundle,
+ last_cranvm
+ };
+
+ /**
+ * Tag for CRANVersionMetadata.
+ *
+ * \see CRANVersionMetadata
+ * \ingroup grpversions
+ */
+ struct CRANVersionMetadataTag :
+ SmartRecordTag<comparison_mode::NoComparisonTag, void>,
+ SmartRecordKeys<CRANVersionMetadataKey, last_cranvm>,
+ SmartRecordKey<cranvm_keywords, std::string>,
+ SmartRecordKey<cranvm_package, std::string>,
+ SmartRecordKey<cranvm_version, std::string>,
+ SmartRecordKey<cranvm_is_bundle, bool>
+ {
+ };
+
+ /**
+ * Version metadata for a CRAN package.
+ *
+ * \ingroup grpversions
+ * \see VersionMetadata
+ */
+ typedef MakeSmartRecord<CRANVersionMetadataTag>::Type CRANVersionMetadata;
+
+ /**
* Key for EbinVersionMetadata.
*
* \see EbinVersionMetadata
@@ -251,6 +289,7 @@ namespace paludis
public InternalCounted<VersionMetadata>
{
private:
+ CRANVersionMetadata * _cran_if;
EbuildVersionMetadata * _ebuild_if;
EbinVersionMetadata * _ebin_if;
@@ -258,7 +297,8 @@ namespace paludis
/**
* Constructor.
*/
- VersionMetadata(ParserFunction, EbuildVersionMetadata * ebuild_if,
+ VersionMetadata(ParserFunction, CRANVersionMetadata * cran_if,
+ EbuildVersionMetadata * ebuild_if,
EbinVersionMetadata * ebin_if);
public:
@@ -273,6 +313,27 @@ namespace paludis
virtual ~VersionMetadata();
/**
+ * Fetch out CRAN interface, or 0.
+ */
+ CRANVersionMetadata *
+ get_cran_interface()
+ {
+ return _cran_if;
+ }
+
+ /**
+ * Fetch out CRAN interface, or 0.
+ */
+ const CRANVersionMetadata *
+ get_cran_interface() const
+ {
+ return _cran_if;
+ }
+
+
+ class CRAN;
+
+ /**
* Fetch our ebuild interface, or 0.
*/
EbuildVersionMetadata *
@@ -290,6 +351,7 @@ namespace paludis
return _ebuild_if;
}
+ class Ebuild;
/**
* Fetch our ebin interface, or 0.
@@ -313,12 +375,39 @@ namespace paludis
* Fetch our licence, as a dep atom structure.
*/
DepAtom::ConstPointer license() const;
-
- class Ebuild;
class Ebin;
};
/**
+ * VersionMetadata subclass, for CRAN repositories.
+ *
+ * \ingroup grpversions
+ * \see VersionMetadata
+ */
+ class VersionMetadata::CRAN :
+ public VersionMetadata
+ {
+ private:
+ CRANVersionMetadata _c;
+
+ public:
+ /**
+ * Constructor.
+ */
+ CRAN(ParserFunction);
+
+ /**
+ * Pointer to us.
+ */
+ typedef CountedPtr<VersionMetadata::CRAN, count_policy::InternalCountTag> Pointer;
+
+ /**
+ * Const pointer to us.
+ */
+ typedef CountedPtr<const VersionMetadata::Ebuild, count_policy::InternalCountTag> ConstPointer;
+ };
+
+ /**
* VersionMetadata subclass, for ebuilds.
*
* \ingroup grpversions
diff --git a/src/paludis/query.cc b/src/paludis/query.cc
index 8a46bad..b6a4a4d 100644
--- a/src/paludis/query.cc
+++ b/src/paludis/query.cc
@@ -195,6 +195,18 @@ void do_one_query(
cout << " " << std::setw(22) << std::left << "PDEPEND:" << std::setw(0) <<
" " << metadata->get<p::vm_deps>().get<p::vmd_post_depend_string>() << endl;
+ if (metadata->get_cran_interface())
+ {
+ cout << " " << std::setw(22) << std::left << "KEYWORDS:" << std::setw(0) <<
+ " " << metadata->get_cran_interface()->get<p::cranvm_keywords>() << endl;
+ cout << " " << std::setw(22) << std::left << "PACKAGE:" << std::setw(0) <<
+ " " << metadata->get_cran_interface()->get<p::cranvm_package>() << endl;
+ cout << " " << std::setw(22) << std::left << "VERSION:" << std::setw(0) <<
+ " " << metadata->get_cran_interface()->get<p::cranvm_version>() << endl;
+ cout << " " << std::setw(22) << std::left << "IS_BUNDLE:" << std::setw(0) <<
+ " " << std::boolalpha << metadata->get_cran_interface()->get<p::cranvm_is_bundle>() << endl;
+ }
+
if (metadata->get_ebuild_interface())
{
cout << " " << std::setw(22) << std::left << "IUSE:" << std::setw(0) <<