aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-30 12:44:41 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-30 12:44:41 +0000
commit66e9ecd85d32b4eda1ce5964369f32e428b56735 (patch)
treea9bd7f719fd7c0c18534a27a3632eef934161ca9
parentcabe1e40deeeacb4ebd0fbc7eab1c8c311984888 (diff)
downloadpaludis-66e9ecd85d32b4eda1ce5964369f32e428b56735.tar.gz
paludis-66e9ecd85d32b4eda1ce5964369f32e428b56735.tar.xz
Add in check_deps_exist demo program
-rw-r--r--src/Makefile.am8
-rw-r--r--src/check_deps_exist.cc204
2 files changed, 212 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 83c182e..7df1205 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,7 @@ AM_CXXFLAGS = -I$(top_srcdir)
DEFS=-DSYSCONFDIR=\"$(sysconfdir)\" -DLIBEXECDIR=\"$(libexecdir)\"
bin_PROGRAMS = paludis
+noinst_PROGRAMS = check_deps_exist
paludis_SOURCES = \
command_line.hh command_line.cc \
@@ -13,10 +14,17 @@ paludis_SOURCES = \
query.hh query.cc \
paludis.cc
+check_deps_exist_SOURCES = \
+ check_deps_exist.cc
+
paludis_LDADD = \
$(top_builddir)/paludis/libpaludis.a \
$(top_builddir)/paludis/args/libpaludisargs.a
+check_deps_exist_LDADD = \
+ $(top_builddir)/paludis/libpaludis.a \
+ $(top_builddir)/paludis/args/libpaludisargs.a
+
TESTS_ENVIRONMENT = env TEST_SCRIPT_DIR="$(srcdir)/" $(SHELL) $(top_srcdir)/test/run_test.sh bash
TESTS = version_TEST
diff --git a/src/check_deps_exist.cc b/src/check_deps_exist.cc
new file mode 100644
index 0000000..6b7ac40
--- /dev/null
+++ b/src/check_deps_exist.cc
@@ -0,0 +1,204 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * 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 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/paludis.hh>
+#include <paludis/args/args.hh>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+
+using namespace paludis;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+struct CheckDepsExistCommandline :
+ args::ArgsHandler,
+ InstantiationPolicy<CheckDepsExistCommandline, instantiation_method::SingletonAsNeededTag>
+{
+ friend class InstantiationPolicy<CheckDepsExistCommandline, instantiation_method::SingletonAsNeededTag>;
+
+ args::ArgsGroup a_general_args;
+ args::SwitchArg a_help;
+ args::SwitchArg a_check_blockers;
+
+ CheckDepsExistCommandline() :
+ a_general_args(this, "General options"),
+ a_help(&a_general_args, "help", 'h', "Display a help message"),
+ a_check_blockers(&a_general_args, "check-blockers", 'b', "Include blockers in checks")
+ {
+ }
+};
+
+struct DepExistsChecker :
+ DepAtomVisitorTypes::ConstVisitor
+{
+ Environment * const env;
+ int status;
+
+ DepExistsChecker(Environment * const e) :
+ env(e),
+ status(0)
+ {
+ }
+
+ void visit(const AllDepAtom * a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const AnyDepAtom * a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const UseDepAtom * a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const BlockDepAtom * a)
+ {
+ if (CheckDepsExistCommandline::get_instance()->a_check_blockers.specified())
+ a->blocked_atom()->accept(this);
+ }
+
+ void visit(const PackageDepAtom * a)
+ {
+ if (env->package_database()->query(a)->empty())
+ {
+ status |= 1;
+ cout << *a << " ";
+ }
+ }
+};
+
+int
+check_one(const std::string & a)
+{
+ Context context("When checking '" + a + "':");
+
+ Environment * const env(DefaultEnvironment::get_instance());
+ PackageDepAtom::Pointer atom(new PackageDepAtom(a));
+
+ PackageDatabaseEntryCollection::ConstPointer entries(env->package_database()->query(atom));
+ if (entries->empty())
+ throw NoSuchPackageError(a);
+
+ int retcode(0);
+ for (PackageDatabaseEntryCollection::Iterator entry(entries->begin()),
+ entry_end(entries->end()) ; entry != entry_end ; ++entry)
+ {
+ Context local_context("When checking '" + stringify(*entry) + "':");
+ cout << *entry << ": ";
+
+ DepExistsChecker checker(env);
+ VersionMetadata::ConstPointer metadata(env->package_database()->fetch_metadata(*entry));
+ DepParser::parse(metadata->get(vmk_depend))->accept(&checker);
+ DepParser::parse(metadata->get(vmk_rdepend))->accept(&checker);
+ DepParser::parse(metadata->get(vmk_pdepend))->accept(&checker);
+
+ cout << (checker.status ? "BAD" : "OK") << endl;
+ retcode |= checker.status;
+ }
+
+ return retcode;
+}
+
+struct DoHelp
+{
+ const std::string message;
+
+ DoHelp(const std::string & m = "") :
+ message(m)
+ {
+ }
+};
+
+int
+main(int argc, char *argv[])
+{
+ Context context("In main program:");
+
+ int retcode = EXIT_SUCCESS;
+
+ try
+ {
+ CheckDepsExistCommandline::get_instance()->run(argc, argv);
+
+ if (CheckDepsExistCommandline::get_instance()->a_help.specified())
+ throw DoHelp();
+
+ if (CheckDepsExistCommandline::get_instance()->empty())
+ throw DoHelp("Expected at least one parameter");
+
+ for (CheckDepsExistCommandline::ParametersIterator
+ a(CheckDepsExistCommandline::get_instance()->begin_parameters()),
+ a_end(CheckDepsExistCommandline::get_instance()->end_parameters()) ;
+ a != a_end ; ++a)
+ retcode |= check_one(*a);
+ }
+ catch (const args::ArgsError & e)
+ {
+ cerr << "Usage error: " << e.message() << endl;
+ cerr << "Try " << argv[0] << " --help" << endl;
+ return EXIT_FAILURE;
+ }
+ catch (const Exception & e)
+ {
+ cout << endl;
+ cerr << "Unhandled exception:" << endl
+ << " * " << e.backtrace("\n * ")
+ << e.message() << " (" << e.what() << ")" << endl;
+ return EXIT_FAILURE;
+ }
+ catch (const std::exception & e)
+ {
+ cout << endl;
+ cerr << "Unhandled exception:" << endl
+ << " * " << e.what() << endl;
+ return EXIT_FAILURE;
+ }
+ catch (const DoHelp & h)
+ {
+ if (h.message.empty())
+ {
+ cout << "Usage: " << argv[0] << " [options]" << endl;
+ cout << endl;
+ cout << *CheckDepsExistCommandline::get_instance();
+ return EXIT_SUCCESS;
+ }
+ else
+ {
+ cerr << "Usage error: " << h.message << endl;
+ cerr << "Try " << argv[0] << " --help" << endl;
+ return EXIT_FAILURE;
+ }
+ }
+ catch (...)
+ {
+ cout << endl;
+ cerr << "Unhandled exception:" << endl
+ << " * Unknown exception type. Ouch..." << endl;
+ return EXIT_FAILURE;
+ }
+
+ return retcode;
+}
+