diff --git a/bin/dispatch-conf b/bin/dispatch-conf index a41464f..10455f4 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -79,7 +79,7 @@ class dispatch: confs = [] count = 0 - config_root = portage.const.EPREFIX or os.sep + config_root = portage.settings["EPREFIX"] or os.sep self.options = portage.dispatch_conf.read_config(MANDATORY_OPTS) if "log-file" in self.options: diff --git a/bin/portageq b/bin/portageq index c88ee88..1ae1fe1 100755 --- a/bin/portageq +++ b/bin/portageq @@ -1232,7 +1232,7 @@ def main(argv): sys.stderr.write("Run portageq with --help for info\n") sys.stderr.flush() sys.exit(os.EX_USAGE) - eprefix = portage.const.EPREFIX + eprefix = portage.settings["EPREFIX"] eroot = portage.util.normalize_path(argv[2]) if eprefix: diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 767a614..89766f1 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -2019,9 +2019,6 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): myportdir = None out = portage.output.EOutput() global_config_path = GLOBAL_CONFIG_PATH - if settings['EPREFIX']: - global_config_path = os.path.join(settings['EPREFIX'], - GLOBAL_CONFIG_PATH.lstrip(os.sep)) if not myportdir: sys.stderr.write("!!! PORTDIR is undefined. " + \ "Is %s/make.globals missing?\n" % global_config_path) @@ -3151,7 +3148,8 @@ def load_emerge_config(emerge_config=None, **kargs): emerge_config = _emerge_config(**kargs) kwargs = {} - for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")): + for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT"), + ("eprefix", "EPREFIX")): v = os.environ.get(envvar, None) if v and v.strip(): kwargs[k] = v @@ -3332,9 +3330,6 @@ def missing_sets_warning(root_config, missing_sets): if root_config.sets: msg.append(" sets defined: %s" % ", ".join(root_config.sets)) global_config_path = portage.const.GLOBAL_CONFIG_PATH - if root_config.settings['EPREFIX']: - global_config_path = os.path.join(root_config.settings['EPREFIX'], - portage.const.GLOBAL_CONFIG_PATH.lstrip(os.sep)) msg.append(" This usually means that '%s'" % \ (os.path.join(global_config_path, "sets/portage.conf"),)) msg.append(" is missing or corrupt.") diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index 689d136..c67f70b 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -541,6 +541,11 @@ def parse_opts(tmpcmdline, silent=False): "choices" : true_y_or_n }, + "--prefix": { + "help" : "specify the installation prefix", + "action" : "store" + }, + "--quiet": { "shortopt" : "-q", "help" : "reduced or condensed output", @@ -1024,6 +1029,8 @@ def emerge_main(args=None): os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"] if "--root" in myopts: os.environ["ROOT"] = myopts["--root"] + if "--prefix" in myopts: + os.environ["EPREFIX"] = myopts["--prefix"] if "--accept-properties" in myopts: os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"] if "--accept-restrict" in myopts: diff --git a/pym/portage/_legacy_globals.py b/pym/portage/_legacy_globals.py index abffa0e..bb9691a 100644 --- a/pym/portage/_legacy_globals.py +++ b/pym/portage/_legacy_globals.py @@ -27,7 +27,8 @@ def _get_legacy_global(name): os.umask(0o22) kwargs = {} - for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")): + for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), + ("target_root", "ROOT"), ("eprefix", "EPREFIX")): kwargs[k] = os.environ.get(envvar) portage._initializing_globals = True diff --git a/pym/portage/_sets/__init__.py b/pym/portage/_sets/__init__.py index c196a70..8123af7 100644 --- a/pym/portage/_sets/__init__.py +++ b/pym/portage/_sets/__init__.py @@ -295,9 +295,6 @@ def load_default_config(settings, trees): return SetConfig(None, settings, trees) global_config_path = GLOBAL_CONFIG_PATH - if settings['EPREFIX']: - global_config_path = os.path.join(settings['EPREFIX'], - GLOBAL_CONFIG_PATH.lstrip(os.sep)) def _getfiles(): for path, dirs, files in os.walk(os.path.join(global_config_path, "sets")): for f in files: diff --git a/pym/portage/const.py b/pym/portage/const.py index 5e960d9..d22d144 100644 --- a/pym/portage/const.py +++ b/pym/portage/const.py @@ -52,10 +52,23 @@ WORLD_SETS_FILE = PRIVATE_PATH + "/world_sets" CONFIG_MEMORY_FILE = PRIVATE_PATH + "/config" NEWS_LIB_PATH = "var/lib/gentoo" -# these variables get EPREFIX prepended automagically when they are -# translated into their lowercase variants -DEPCACHE_PATH = "/var/cache/edb/dep" -GLOBAL_CONFIG_PATH = "/usr/share/portage/config" +# The EPREFIX for the current install is hardcoded here, but access to this +# constant should be minimal, in favor of access via the EPREFIX setting of +# a config instance (since it's possible to contruct a config instance with +# a different EPREFIX). +EPREFIX="" + +# pick up EPREFIX from the environment if set +if "PORTAGE_OVERRIDE_EPREFIX" in os.environ: + EPREFIX = os.environ["PORTAGE_OVERRIDE_EPREFIX"] + if EPREFIX: + EPREFIX = os.path.normpath(EPREFIX) + +# these variables are based on the prefix of the portage installation, not +# the prefix of the installed packages, and as such use the builtin EPREFIX +# rather than the EPREFIX setting in a config instance. +DEPCACHE_PATH = EPREFIX + "/var/cache/edb/dep" +GLOBAL_CONFIG_PATH = EPREFIX + "/usr/share/portage/config" # these variables are not used with target_root or config_root # NOTE: Use realpath(__file__) so that python module symlinks in site-packages @@ -152,19 +165,6 @@ MANIFEST2_REQUIRED_HASH = "SHA256" MANIFEST2_IDENTIFIERS = ("AUX", "MISC", "DIST", "EBUILD") -# The EPREFIX for the current install is hardcoded here, but access to this -# constant should be minimal, in favor of access via the EPREFIX setting of -# a config instance (since it's possible to contruct a config instance with -# a different EPREFIX). Therefore, the EPREFIX constant should *NOT* be used -# in the definition of any other constants within this file. -EPREFIX="" - -# pick up EPREFIX from the environment if set -if "PORTAGE_OVERRIDE_EPREFIX" in os.environ: - EPREFIX = os.environ["PORTAGE_OVERRIDE_EPREFIX"] - if EPREFIX: - EPREFIX = os.path.normpath(EPREFIX) - VCS_DIRS = ("CVS", "RCS", "SCCS", ".bzr", ".git", ".hg", ".svn") # =========================================================================== diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py index 4c68dfc..570bd8c 100644 --- a/pym/portage/dispatch_conf.py +++ b/pym/portage/dispatch_conf.py @@ -43,7 +43,7 @@ def diffstatusoutput(cmd, file1, file2): return (proc.wait(), output) def read_config(mandatory_opts): - eprefix = portage.const.EPREFIX + eprefix = portage.settings["EPREFIX"] config_path = os.path.join(eprefix or os.sep, "etc/dispatch-conf.conf") loader = KeyValuePairFileLoader(config_path, None) opts, errors = loader.load() diff --git a/pym/portage/package/ebuild/_config/LocationsManager.py b/pym/portage/package/ebuild/_config/LocationsManager.py index 5057f95..4171807 100644 --- a/pym/portage/package/ebuild/_config/LocationsManager.py +++ b/pym/portage/package/ebuild/_config/LocationsManager.py @@ -275,29 +275,7 @@ class LocationsManager(object): self.eroot = self.target_root.rstrip(os.sep) + self.eprefix + os.sep - # make.globals should not be relative to config_root - # because it only contains constants. However, if EPREFIX - # is set then there are two possible scenarios: - # 1) If $ROOT == "/" then make.globals should be - # relative to EPREFIX. - # 2) If $ROOT != "/" then the correct location of - # make.globals needs to be specified in the constructor - # parameters, since it's a property of the host system - # (and the current config represents the target system). self.global_config_path = GLOBAL_CONFIG_PATH - if self.eprefix: - if self.target_root == "/": - # case (1) above - self.global_config_path = os.path.join(self.eprefix, - GLOBAL_CONFIG_PATH.lstrip(os.sep)) - else: - # case (2) above - # For now, just assume make.globals is relative - # to EPREFIX. - # TODO: Pass in more info to the constructor, - # so we know the host system configuration. - self.global_config_path = os.path.join(self.eprefix, - GLOBAL_CONFIG_PATH.lstrip(os.sep)) def set_port_dirs(self, portdir, portdir_overlay): self.portdir = portdir diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 1c29af9..199a0f5 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -594,14 +594,8 @@ class config(object): self.backup_changes("PORTAGE_CONFIGROOT") self["ROOT"] = target_root self.backup_changes("ROOT") - - # The PORTAGE_OVERRIDE_EPREFIX variable propagates the EPREFIX - # of this config instance to any portage commands or API - # consumers running in subprocesses. self["EPREFIX"] = eprefix self.backup_changes("EPREFIX") - self["PORTAGE_OVERRIDE_EPREFIX"] = eprefix - self.backup_changes("PORTAGE_OVERRIDE_EPREFIX") self["EROOT"] = eroot self.backup_changes("EROOT") @@ -781,21 +775,6 @@ class config(object): self.backupenv["USE_ORDER"] = "env:pkg:conf:defaults:pkginternal:repo:env.d" self.depcachedir = DEPCACHE_PATH - if eprefix: - # See comments about make.globals and EPREFIX - # above. DEPCACHE_PATH is similar. - if target_root == "/": - # case (1) above - self.depcachedir = os.path.join(eprefix, - DEPCACHE_PATH.lstrip(os.sep)) - else: - # case (2) above - # For now, just assume DEPCACHE_PATH is relative - # to EPREFIX. - # TODO: Pass in more info to the constructor, - # so we know the host system configuration. - self.depcachedir = os.path.join(eprefix, - DEPCACHE_PATH.lstrip(os.sep)) if self.get("PORTAGE_DEPCACHEDIR", None): self.depcachedir = self["PORTAGE_DEPCACHEDIR"] diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index 6de47bb..69463d2 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -159,7 +159,7 @@ def _doebuild_path(settings, eapi=None): # Note: PORTAGE_BIN_PATH may differ from the global constant # when portage is reinstalling itself. portage_bin_path = settings["PORTAGE_BIN_PATH"] - eprefix = settings["EPREFIX"] + eprefix = portage.const.EPREFIX prerootpath = [x for x in settings.get("PREROOTPATH", "").split(":") if x] rootpath = [x for x in settings.get("ROOTPATH", "").split(":") if x] overrides = [x for x in settings.get( diff --git a/pym/portage/package/ebuild/fetch.py b/pym/portage/package/ebuild/fetch.py index 50a1b72..4cdf326 100644 --- a/pym/portage/package/ebuild/fetch.py +++ b/pym/portage/package/ebuild/fetch.py @@ -865,10 +865,6 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, protocol = loc[0:loc.find("://")] global_config_path = GLOBAL_CONFIG_PATH - if mysettings['EPREFIX']: - global_config_path = os.path.join(mysettings['EPREFIX'], - GLOBAL_CONFIG_PATH.lstrip(os.sep)) - missing_file_param = False fetchcommand_var = "FETCHCOMMAND_" + protocol.upper() fetchcommand = mysettings.get(fetchcommand_var) diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py index bff4512..eb15e1c 100644 --- a/pym/portage/tests/resolver/ResolverPlayground.py +++ b/pym/portage/tests/resolver/ResolverPlayground.py @@ -426,8 +426,7 @@ class ResolverPlayground(object): f.close() #Create /usr/share/portage/config/make.globals - make_globals_path = os.path.join(self.eroot, - GLOBAL_CONFIG_PATH.lstrip(os.sep), "make.globals") + make_globals_path = os.path.join(GLOBAL_CONFIG_PATH, "make.globals") ensure_dirs(os.path.dirname(make_globals_path)) os.symlink(os.path.join(PORTAGE_BASE_PATH, "cnf", "make.globals"), make_globals_path) diff --git a/pym/portage/util/env_update.py b/pym/portage/util/env_update.py index e9c06c5..289842c 100644 --- a/pym/portage/util/env_update.py +++ b/pym/portage/util/env_update.py @@ -46,12 +46,11 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, if isinstance(env, config): vardbapi = vartree(settings=env).dbapi else: + eprefix = portage.settings["EPREFIX"] if target_root is None: - eprefix = portage.settings["EPREFIX"] target_root = portage.settings["ROOT"] target_eroot = portage.settings['EROOT'] else: - eprefix = portage.const.EPREFIX target_eroot = os.path.join(target_root, eprefix.lstrip(os.sep)) target_eroot = target_eroot.rstrip(os.sep) + os.sep