aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-03-15 15:00:03 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-03-15 15:00:03 +0000
commitad49b4e5029174059d9149640cd1b506e6c72168 (patch)
treeff0623ac9fe0fd21ebeb996fd27ca5a94b5de0e4
parent149ffdc4e50c3b89b06ffae1d8bd5181f4f69ef3 (diff)
downloadpaludis-ad49b4e5029174059d9149640cd1b506e6c72168.tar.gz
paludis-ad49b4e5029174059d9149640cd1b506e6c72168.tar.xz
More install work
-rw-r--r--ebuild/Makefile.am1
-rwxr-xr-xebuild/ebuild.bash2
-rw-r--r--ebuild/eclass_functions.bash6
-rw-r--r--ebuild/src_fetch.bash67
-rw-r--r--paludis/portage_repository.cc46
-rw-r--r--paludis/util/system.cc25
-rw-r--r--paludis/util/system.hh10
-rw-r--r--paludis/util/system_TEST.cc16
8 files changed, 150 insertions, 23 deletions
diff --git a/ebuild/Makefile.am b/ebuild/Makefile.am
index fa3a8c4..f6c1922 100644
--- a/ebuild/Makefile.am
+++ b/ebuild/Makefile.am
@@ -24,6 +24,7 @@ libexecprog_SCRIPTS = \
portage_stubs.bash \
sandbox_stubs.bash \
src_compile.bash \
+ src_fetch.bash \
src_install.bash \
src_test.bash \
src_unpack.bash \
diff --git a/ebuild/ebuild.bash b/ebuild/ebuild.bash
index 78f998d..5ef6d3d 100755
--- a/ebuild/ebuild.bash
+++ b/ebuild/ebuild.bash
@@ -93,7 +93,7 @@ ebuild_main()
ebuild_f_depend || die "${action} failed"
;;
- unpack|compile|install|test)
+ fetch|unpack|compile|install|test)
ebuild_load_module src_${action}
ebuild_load_ebuild "${ebuild}"
ebuild_f_${action} || die "${action} failed"
diff --git a/ebuild/eclass_functions.bash b/ebuild/eclass_functions.bash
index f68e263..5584cae 100644
--- a/ebuild/eclass_functions.bash
+++ b/ebuild/eclass_functions.bash
@@ -29,15 +29,15 @@ EXPORT_FUNCTIONS()
for e in "$@" ; do
case "$e" in
pkg_setup|pkg_prerm|pkg_postrm|pkg_preinst|pkg_postinst)
- eval "$1() { ${ECLASS}_${e} \"\$@\" ; }"
+ eval "${e}() { ${ECLASS}_${e} \"\$@\" ; }"
;;
src_unpack|src_compile|src_install|src_test)
- eval "$1() { ${ECLASS}_${e} \"\$@\" ; }"
+ eval "${e}() { ${ECLASS}_${e} \"\$@\" ; }"
;;
*)
- eval "$1() { ${ECLASS}_${e} \"\$@\" ; }"
+ eval "${e}() { ${ECLASS}_${e} \"\$@\" ; }"
ebuild_notice "qa" "$e should not be in EXPORT_FUNCTIONS for ${ECLASS}"
;;
esac
diff --git a/ebuild/src_fetch.bash b/ebuild/src_fetch.bash
new file mode 100644
index 0000000..46d109b
--- /dev/null
+++ b/ebuild/src_fetch.bash
@@ -0,0 +1,67 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License 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
+
+src_fetch()
+{
+ local a nofetch unique_aa
+ for a in ${FLAT_SRC_URI} ; do
+ local aa=${a##*/}
+ if [[ -f "${DISTDIR}/${aa}" ]] ; then
+ if ! hasq ${aa} ${unique_aa} ; then
+ ebuild_section "Already have ${aa}"
+ unique_aa="${unique_aa} ${aa}"
+ fi
+ continue
+ else
+ if ! hasq fetch ${RESTRICT} ; then
+ if ! hasq ${aa} ${unique_aa} ; then
+ ebuild_section "Need to fetch ${aa}"
+ unique_aa="${unique_aa} ${aa}"
+ fi
+ wget -O "${DISTDIR}/${aa}" "${a}"
+ else
+ if ! hasq ${aa} ${unique_aa} ; then
+ ebuild_section "Can't fetch ${aa}"
+ unique_aa="${unique_aa} ${aa}"
+ fi
+ nofetch="${nofetch:+${nofetch} }${aa}"
+ fi
+ fi
+ done
+
+ if [[ -n "${nofetch}" ]] ; then
+ local c
+ echo
+ eerror "Couldn't fetch the following components:"
+ for c in ${nofetch} ; do
+ eerror " * ${c}"
+ done
+ echo
+ die "src_fetch failed"
+ fi
+}
+
+ebuild_f_fetch()
+{
+ ebuild_section "Starting src_fetch"
+ src_fetch
+ ebuild_section "Done src_fetch"
+}
+
+
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 870b0e1..1eaf410 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -46,6 +46,7 @@
#include <deque>
#include <limits>
#include <iostream>
+
#include <strings.h>
using namespace paludis;
@@ -899,20 +900,29 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
VersionMetadata::ConstPointer metadata(version_metadata(q, v));
- std::string archives;
- PackageDatabaseEntry e(q, v, name());
- DepAtomFlattener f(_imp->env, &e,
- DepParser::parse(metadata->get(vmk_src_uri),
- DepParserPolicy<PlainTextDepAtom, false>::get_instance()));
-
- for (DepAtomFlattener::Iterator ff(f.begin()), ff_end(f.end()) ; ff != ff_end ; ++ff)
+ std::string archives, flat_src_uri;
{
- std::string::size_type p((*ff)->text().rfind('/'));
- if (std::string::npos == p)
- archives.append((*ff)->text());
- else
- archives.append((*ff)->text().substr(p + 1));
- archives.append(" ");
+ PackageDatabaseEntry e(q, v, name());
+ DepAtomFlattener f(_imp->env, &e,
+ DepParser::parse(metadata->get(vmk_src_uri),
+ DepParserPolicy<PlainTextDepAtom, false>::get_instance()));
+
+ for (DepAtomFlattener::Iterator ff(f.begin()), ff_end(f.end()) ; ff != ff_end ; ++ff)
+ {
+ std::string::size_type p((*ff)->text().rfind('/'));
+ if (std::string::npos == p)
+ archives.append((*ff)->text());
+ else
+ archives.append((*ff)->text().substr(p + 1));
+ archives.append(" ");
+
+ if (0 == (*ff)->text().compare(0, 9, "mirror://"))
+ {
+ }
+ else
+ flat_src_uri.append((*ff)->text());
+ flat_src_uri.append(" ");
+ }
}
std::string cmd(
@@ -923,6 +933,7 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
"PVR='" + stringify(v.remove_revision()) + "-" + v.revision_only() + "' " +
"PF='" + stringify(q.get<qpn_package>()) + "-" + stringify(v) + "' " +
"A='" + archives + "' " +
+ "FLAT_SRC_URI='" + flat_src_uri + "' " +
"CATEGORY='" + stringify(q.get<qpn_category>()) + "' " +
"FILESDIR='" + stringify(_imp->location) + "/" + stringify(q.get<qpn_category>()) + "/" +
stringify(q.get<qpn_package>()) + "/files/' " +
@@ -938,12 +949,9 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
stringify(_imp->location) + "/" + stringify(q.get<qpn_category>()) + "/" +
stringify(q.get<qpn_package>()) + "/" +
stringify(q.get<qpn_package>()) + "-" + stringify(v) + ".ebuild' "
- "init setup unpack compile test install preinst merge postinst tidyup");
+ "init fetch setup unpack compile test install preinst merge postinst tidyup");
- PStream prog(cmd);
- std::copy((std::istreambuf_iterator<char>(prog)), std::istreambuf_iterator<char>(),
- std::ostreambuf_iterator<char>(std::cout));
- if (prog.exit_status())
- throw InternalError(PALUDIS_HERE, "TODO"); /// \todo fixme
+ if (0 != run_command(cmd))
+ throw InternalError(PALUDIS_HERE, "todo"); /// \todo fixme
}
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 4d4d029..22a4622 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -20,6 +20,9 @@
#include <cstdlib>
#include <paludis/util/system.hh>
#include <sys/utsname.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
using namespace paludis;
@@ -62,3 +65,25 @@ paludis::kernel_version()
return result;
}
+int
+paludis::run_command(const std::string & cmd)
+{
+ pid_t child(fork());
+ int status(-1);
+ if (0 == child)
+ {
+ execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(0));
+ throw InternalError(PALUDIS_HERE, "execl failed"); /// \todo fixme
+ }
+ else if (-1 == child)
+ {
+ throw InternalError(PALUDIS_HERE, "fork failed"); /// \todo fixme
+ }
+ else
+ {
+ if (-1 == wait(&status))
+ throw InternalError(PALUDIS_HERE, "wait failed"); /// \todo fixme
+ }
+ return status;
+}
+
diff --git a/paludis/util/system.hh b/paludis/util/system.hh
index 801a953..0138b98 100644
--- a/paludis/util/system.hh
+++ b/paludis/util/system.hh
@@ -51,7 +51,17 @@ namespace paludis
*/
std::string getenv_or_error(const std::string & key);
+ /**
+ * Fetch the kernel version, for $KV.
+ */
std::string kernel_version();
+
+ /**
+ * Run a command, wait for it to terminate and return its exit status.
+ *
+ * Use PStream instead if you need to capture stdout.
+ */
+ int run_command(const std::string & cmd);
}
#endif
diff --git a/paludis/util/system_TEST.cc b/paludis/util/system_TEST.cc
index 4ba4e09..e6d7f0c 100644
--- a/paludis/util/system_TEST.cc
+++ b/paludis/util/system_TEST.cc
@@ -80,4 +80,20 @@ namespace test_cases
#endif
}
} test_kernel_version;
+
+ /**
+ * \test Test run_command.
+ *
+ * \ingroup Test
+ */
+ struct RunCommandTest : TestCase
+ {
+ RunCommandTest() : TestCase("run_command") { }
+
+ void run()
+ {
+ TEST_CHECK(0 == run_command("true"));
+ TEST_CHECK(0 != run_command("nosuchcommand"));
+ }
+ } test_run_command;
}