aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-29 13:26:16 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-29 13:26:16 +0000
commit628bfe3bdb31b85483d89a21d561bf2273637ff4 (patch)
tree1169961553fd876e85515ede0c48a2334753ba22
parenta17a68c762433ba16c0e722f9cc9b130f015d596 (diff)
downloadpaludis-628bfe3bdb31b85483d89a21d561bf2273637ff4.tar.gz
paludis-628bfe3bdb31b85483d89a21d561bf2273637ff4.tar.xz
More PortageEnvironment work
-rw-r--r--paludis/environments/portage/Makefile.am20
-rw-r--r--paludis/environments/portage/portage_environment.cc47
-rw-r--r--paludis/environments/portage/portage_environment_TEST.cc72
-rwxr-xr-xpaludis/environments/portage/portage_environment_TEST_cleanup.sh9
-rwxr-xr-xpaludis/environments/portage/portage_environment_TEST_setup.sh42
5 files changed, 183 insertions, 7 deletions
diff --git a/paludis/environments/portage/Makefile.am b/paludis/environments/portage/Makefile.am
index 00d0265..645288e 100644
--- a/paludis/environments/portage/Makefile.am
+++ b/paludis/environments/portage/Makefile.am
@@ -29,19 +29,33 @@ paludis_environment_portage_include_HEADERS = \
portage_environment.hh
EXTRA_DIST = \
- $(BUILT_SOURCES)
+ $(BUILT_SOURCES) \
+ portage_environment_TEST_setup.sh \
+ portage_environment_TEST.cc \
+ portage_environment_TEST_cleanup.sh
-TESTS =
+TESTS = portage_environment_TEST
TESTS_ENVIRONMENT = env \
PALUDIS_EBUILD_DIR="$(top_srcdir)/ebuild/" \
PALUDIS_SKIP_CONFIG="yes" \
PALUDIS_REPOSITORY_SO_DIR="$(top_builddir)/paludis/repositories" \
TEST_SCRIPT_DIR="$(srcdir)/" \
+ SYSCONFDIR="$(sysconfdir)" \
bash $(top_srcdir)/test/run_test.sh
+portage_environment_TEST_SOURCES = portage_environment_TEST.cc
+portage_environment_TEST_LDADD = \
+ libpaludisportageenvironment.la \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ $(top_builddir)/paludis/repositories/libpaludisrepositories.la \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(DYNAMIC_LD_LIBS)
+
check_PROGRAMS = $(TESTS)
-check_SCRIPTS =
+check_SCRIPTS = portage_environment_TEST_setup.sh portage_environment_TEST_cleanup.sh
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/paludis/environments/portage/portage_environment.cc b/paludis/environments/portage/portage_environment.cc
index a9c35b9..120ec43 100644
--- a/paludis/environments/portage/portage_environment.cc
+++ b/paludis/environments/portage/portage_environment.cc
@@ -27,6 +27,7 @@
#include <paludis/util/strip.hh>
#include <paludis/repositories/repository_maker.hh>
#include <paludis/config_file.hh>
+#include <paludis/match_package.hh>
#include <set>
#include <vector>
@@ -84,7 +85,8 @@ namespace
return true;
std::set<std::string> use_expand;
- WhitespaceTokeniser::get_instance()->tokenise(k.get("USE_EXPAND"), std::inserter(use_expand, use_expand.begin()));
+ WhitespaceTokeniser::get_instance()->tokenise(k.get("USE_EXPAND"),
+ std::inserter(use_expand, use_expand.begin()));
if (use_expand.end() != use_expand.find(s))
return true;
@@ -108,7 +110,8 @@ PortageEnvironment::PortageEnvironment(const std::string & s) :
if ((_imp->conf_dir / "make.globals").exists())
_imp->vars.reset(new KeyValueConfigFile(_imp->conf_dir / "make.globals", _imp->vars, &is_incremental));
if ((_imp->conf_dir / "make.conf").exists())
- _imp->vars.reset(new KeyValueConfigFile(_imp->conf_dir / "make.conf", _imp->vars, &is_incremental_excluding_use_expand));
+ _imp->vars.reset(new KeyValueConfigFile(_imp->conf_dir / "make.conf", _imp->vars,
+ &is_incremental_excluding_use_expand));
/* TODO: load USE etc from env? */
@@ -116,6 +119,8 @@ PortageEnvironment::PortageEnvironment(const std::string & s) :
_add_virtuals_repository();
_add_installed_virtuals_repository();
+ if (_imp->vars->get("PORTDIR").empty())
+ throw PortageEnvironmentConfigurationError("PORTDIR empty or unset");
_add_portdir_repository(FSEntry(_imp->vars->get("PORTDIR")));
_add_vdb_repository();
/* TODO: OVERLAY */
@@ -268,7 +273,8 @@ PortageEnvironment::_add_portdir_repository(const FSEntry & portdir)
keys->insert("root", stringify(root()));
keys->insert("location", stringify(portdir));
keys->insert("profiles", stringify((_imp->conf_dir / "make.profile").realpath()) + " " +
- ((_imp->conf_dir / "portage" / "profile").is_directory() ? stringify(_imp->conf_dir / "portage" / "profile") : ""));
+ ((_imp->conf_dir / "portage" / "profile").is_directory() ?
+ stringify(_imp->conf_dir / "portage" / "profile") : ""));
keys->insert("format", "ebuild");
keys->insert("names_cache", "/var/empty");
package_database()->add_repository(2,
@@ -316,6 +322,22 @@ PortageEnvironment::query_use(const UseFlagName & f, const PackageDatabaseEntry
if (u != _imp->use_with_expands.end())
state = use_enabled;
+ /* check use: per package config */
+ if (e)
+ {
+ for (PackageUse::const_iterator i(_imp->package_use.begin()), i_end(_imp->package_use.end()) ;
+ i != i_end ; ++i)
+ {
+ if (! match_package(*this, *i->first, *e))
+ continue;
+
+ if (i->second == stringify(f))
+ state = use_enabled;
+ else if (i->second == "-" + stringify(f))
+ state = use_disabled;
+ }
+ }
+
switch (state)
{
case use_disabled:
@@ -365,6 +387,25 @@ PortageEnvironment::accept_keyword(const KeywordName & k, const PackageDatabaseE
if (_imp->accept_keywords.end() != _imp->accept_keywords.find(stringify(k)))
result = true;
+ if (d)
+ {
+ for (PackageKeywords::const_iterator i(_imp->package_keywords.begin()), i_end(_imp->package_keywords.end()) ;
+ i != i_end ; ++i)
+ {
+ if (! match_package(*this, *i->first, *d))
+ continue;
+
+ if (i->second == stringify(k))
+ result = true;
+ else if (i->second == "-" + stringify(k))
+ result = false;
+ else if (i->second == "-*")
+ result = false;
+ else if (i->second == "**")
+ result = true;
+ }
+ }
+
if ((! result) && override_tilde_keywords && ('~' == stringify(k).at(0)))
result = accept_keyword(KeywordName(stringify(k).substr(1)), d, false);
diff --git a/paludis/environments/portage/portage_environment_TEST.cc b/paludis/environments/portage/portage_environment_TEST.cc
index 9f998b7..a1a2e88 100644
--- a/paludis/environments/portage/portage_environment_TEST.cc
+++ b/paludis/environments/portage/portage_environment_TEST.cc
@@ -17,5 +17,75 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "portage_environment_TEST.hh"
+#include "portage_environment.hh"
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ struct QueryUseTest : TestCase
+ {
+ QueryUseTest() : TestCase("query_use") { }
+
+ void run()
+ {
+ PortageEnvironment env("portage_environment_TEST_dir/query_use");
+
+ TEST_CHECK(env.query_use(UseFlagName("one"), 0));
+ TEST_CHECK(env.query_use(UseFlagName("two"), 0));
+ TEST_CHECK(! env.query_use(UseFlagName("three"), 0));
+ TEST_CHECK(! env.query_use(UseFlagName("four"), 0));
+ TEST_CHECK(! env.query_use(UseFlagName("five"), 0));
+
+ PackageDatabaseEntry d(QualifiedPackageName("app/one"), VersionSpec("1"),
+ RepositoryName("repo"));
+
+ TEST_CHECK(! env.query_use(UseFlagName("one"), &d));
+ TEST_CHECK(env.query_use(UseFlagName("two"), &d));
+ TEST_CHECK(! env.query_use(UseFlagName("three"), &d));
+ TEST_CHECK(env.query_use(UseFlagName("four"), &d));
+ TEST_CHECK(! env.query_use(UseFlagName("five"), &d));
+ }
+ } test_query_use;
+
+ struct AcceptKeywordsTest : TestCase
+ {
+ AcceptKeywordsTest() : TestCase("accept_keywords") { }
+
+ void run()
+ {
+ PortageEnvironment env("portage_environment_TEST_dir/accept_keywords");
+
+ TEST_CHECK(env.accept_keyword(KeywordName("arch"), 0));
+ TEST_CHECK(env.accept_keyword(KeywordName("other_arch"), 0));
+ TEST_CHECK(! env.accept_keyword(KeywordName("~arch"), 0));
+
+ PackageDatabaseEntry d1(QualifiedPackageName("app/one"), VersionSpec("1"),
+ RepositoryName("repo"));
+ TEST_CHECK(env.accept_keyword(KeywordName("arch"), &d1));
+ TEST_CHECK(env.accept_keyword(KeywordName("other_arch"), &d1));
+ TEST_CHECK(env.accept_keyword(KeywordName("~arch"), &d1));
+
+ PackageDatabaseEntry d2(QualifiedPackageName("app/two"), VersionSpec("1"),
+ RepositoryName("repo"));
+ TEST_CHECK(env.accept_keyword(KeywordName("other_arch"), &d2));
+ TEST_CHECK(env.accept_keyword(KeywordName("arch"), &d2));
+ TEST_CHECK(env.accept_keyword(KeywordName("~arch"), &d2));
+
+ PackageDatabaseEntry d3(QualifiedPackageName("app/three"), VersionSpec("1"),
+ RepositoryName("repo"));
+ TEST_CHECK(! env.accept_keyword(KeywordName("other_arch"), &d3));
+ TEST_CHECK(! env.accept_keyword(KeywordName("arch"), &d3));
+ TEST_CHECK(! env.accept_keyword(KeywordName("~arch"), &d3));
+
+ PackageDatabaseEntry d4(QualifiedPackageName("app/four"), VersionSpec("1"),
+ RepositoryName("repo"));
+ TEST_CHECK(env.accept_keyword(KeywordName("fred"), &d4));
+
+ }
+ } test_accept_keywords;
+}
diff --git a/paludis/environments/portage/portage_environment_TEST_cleanup.sh b/paludis/environments/portage/portage_environment_TEST_cleanup.sh
new file mode 100755
index 0000000..b64b00f
--- /dev/null
+++ b/paludis/environments/portage/portage_environment_TEST_cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d portage_environment_TEST_dir ] ; then
+ rm -fr portage_environment_TEST_dir
+else
+ true
+fi
+
diff --git a/paludis/environments/portage/portage_environment_TEST_setup.sh b/paludis/environments/portage/portage_environment_TEST_setup.sh
new file mode 100755
index 0000000..e76df25
--- /dev/null
+++ b/paludis/environments/portage/portage_environment_TEST_setup.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir portage_environment_TEST_dir || exit 2
+cd portage_environment_TEST_dir || exit 3
+
+mkdir -p profile
+cat <<"END" > profile/make.defaults
+ARCH="arch"
+ACCEPT_KEYWORDS="arch"
+END
+
+mkdir -p repo/profiles
+cat <<"END" > repo/profiles/repo_name
+repo
+END
+
+mkdir -p query_use/${SYSCONFDIR}/portage
+ln -s $(pwd )/profile query_use/${SYSCONFDIR}/make.profile
+cat <<END > query_use/${SYSCONFDIR}/make.conf
+USE="one two -three"
+PORTDIR="`pwd`/repo"
+END
+cat <<"END" > query_use/${SYSCONFDIR}/portage/package.use
+app/one -one four
+END
+
+mkdir -p accept_keywords/${SYSCONFDIR}/portage
+ln -s $(pwd )/profile accept_keywords/${SYSCONFDIR}/make.profile
+cat <<END > accept_keywords/${SYSCONFDIR}/make.conf
+USE="one two -three"
+PORTDIR="`pwd`/repo"
+ACCEPT_KEYWORDS="other_arch"
+END
+cat <<"END" > accept_keywords/${SYSCONFDIR}/portage/package.keywords
+app/one ~arch
+app/two
+app/three -*
+app/four **
+END
+
+