diff options
author | Felix Bier <Felix.Bier@rohde-schwarz.com> | 2020-11-10 01:03:03 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gentoo.org> | 2020-11-14 11:34:57 -0500 |
commit | 37a386056f77f7cc8f1c2bdfe680b13bd806b4e6 (patch) | |
tree | e93e57acaa918b12dd1acb50ca5155538334909c /catalyst/base | |
parent | Ensure deep copying of config defaults (diff) | |
download | catalyst-37a386056f77f7cc8f1c2bdfe680b13bd806b4e6.tar.gz catalyst-37a386056f77f7cc8f1c2bdfe680b13bd806b4e6.tar.bz2 catalyst-37a386056f77f7cc8f1c2bdfe680b13bd806b4e6.zip |
Move from PORTDIR_OVERLAY to repos.conf
This commit fixes the following issues:
* The PORTDIR_OVERLAY variable has been deprecated by Gentoo.
With this commit, the variable is no longer written to the
generated make.conf. Instead, a config file
/etc/portage/repos.conf/<repo-name>.conf
is generated for each overlay. The repo name is read from the
overlay using the portage API. Internally, portage parses
metadata/layout.conf and profiles/repo_name to obtain the name.
References:
https://wiki.gentoo.org/wiki//etc/portage/make.conf
https://wiki.gentoo.org/wiki//etc/portage/repos.conf
* All overlays were copied into the same target directory. If the
same file name occurred in multiple overlays, the last overlay
would overwrite all previous files with this name. In particular,
only the metadata/layout.conf of the last overlay was retained,
so it was not possible to reference the other overlays e.g. via
the masters entry in the layout.conf or the portage-2 syntax
for specifying a parent profile from another overlay. Also,
this created problems when the overlays contained ebuilds
for the same package, but with differing versions, because
after copying, the target directory contained both versions of the
ebuild but only the manifest file of the last overlay.
With this commit, each overlay is copied into a separate
sub-directory, e.g. /var/db/repos/<repo-name>.
This directory is referenced via the location entry in the
generated /etc/portage/repos.conf/<repo-name>.conf.
Signed-off-by: Felix Bier <felix.bier@rohde-schwarz.com>
Signed-off-by: Matt Turner <mattst88@gentoo.org>
Diffstat (limited to 'catalyst/base')
-rw-r--r-- | catalyst/base/stagebase.py | 84 |
1 files changed, 62 insertions, 22 deletions
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 21cf96a0..fe79b55a 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -1,4 +1,5 @@ +import configparser import copy import os import platform @@ -19,8 +20,8 @@ from catalyst import log from catalyst.context import namespace from catalyst.defaults import (confdefaults, MOUNT_DEFAULTS, PORT_LOGDIR_CLEAN) from catalyst.support import (CatalystError, file_locate, normpath, - cmd, read_makeconf, ismount, file_check, - sanitize_name) + cmd, read_makeconf, get_repo_name, ismount, + file_check, sanitize_name) from catalyst.base.targetbase import TargetBase from catalyst.base.clearbase import ClearBase from catalyst.base.genbase import GenBase @@ -786,17 +787,55 @@ class StageBase(TargetBase, ClearBase, GenBase): env=self.env) self.resume.enable("setup_confdir") + def to_chroot(self, path): + """ Prepend chroot path to the given path. """ + + chroot = Path(self.settings['chroot_path']) + return chroot / path.relative_to(path.anchor) + + def get_repo_conf_path(self, repo_name): + """ Construct repo conf path: {repos_conf}/{name}.conf """ + return Path(self.settings['repos_conf'], repo_name + ".conf") + + def get_repo_location(self, repo_name): + """ Construct overlay repo path: {repo_basedir}/{name} """ + return Path(self.settings['repo_basedir'], repo_name) + + def write_repo_conf(self, repo_name, config): + """ Write ConfigParser to {chroot}/{repos_conf}/{name}.conf """ + + repo_conf = self.get_repo_conf_path(repo_name) + + repo_conf_chroot = self.to_chroot(repo_conf) + repo_conf_chroot.parent.mkdir(mode=0o755, parents=True, exist_ok=True) + + log.info(f'Creating repo config {repo_conf_chroot}.') + + try: + with open(repo_conf_chroot, 'w') as f: + config.write(f) + except OSError as e: + raise CatalystError(f'Could not write {repo_conf_chroot}: {e}') from e + def portage_overlay(self): - """ We copy the contents of our overlays to /usr/local/portage """ + """ We copy the contents of our repos to get_repo_location(repo_name) """ if "portage_overlay" in self.settings: for x in self.settings["portage_overlay"]: if os.path.exists(x): - log.info('Copying overlay dir %s', x) - ensure_dirs( - self.settings['chroot_path'] + self.settings['local_overlay']) - cmd("cp -a " + x + "/* " + self.settings["chroot_path"] + - self.settings["local_overlay"], - env=self.env) + name = get_repo_name(x) + + location = self.get_repo_location(name) + config = configparser.ConfigParser() + config[name] = {'location': location} + self.write_repo_conf(name, config) + + location_chroot = self.to_chroot(location) + location_chroot.mkdir(mode=0o755, parents=True, exist_ok=True) + + log.info(f'Copying overlay dir {x} to {location_chroot}') + cmd(f'cp -a {x}/* {location_chroot}', env=self.env) + else: + log.warning(f'Skipping missing overlay {x}.') def root_overlay(self): """ Copy over the root_overlay """ @@ -852,8 +891,8 @@ class StageBase(TargetBase, ClearBase, GenBase): cxt = libmount.Context(source=source, target=target, fstype=fstype, options=options) cxt.mount() - except OSError as e: - raise CatalystError(f"Couldn't mount: {source}, {e.strerror}") + except Exception as e: + raise CatalystError(f"Couldn't mount: {source}, {e}") def chroot_setup(self): self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] + @@ -1018,12 +1057,6 @@ class StageBase(TargetBase, ClearBase, GenBase): varname = x.split('_')[1].upper() myf.write(f'{varname}="{self.settings[x]}"\n') - if setup: - # Setup the portage overlay - if "portage_overlay" in self.settings: - myf.write('PORTDIR_OVERLAY="%s"\n' % - self.settings["local_overlay"]) - # Set default locale for system responses. #478382 myf.write( '\n' @@ -1097,11 +1130,18 @@ class StageBase(TargetBase, ClearBase, GenBase): log.warning("You've been hacking. Clearing target patches: %s", target) clear_path(target) - # Remove our overlay - overlay = normpath( - self.settings["chroot_path"] + self.settings["local_overlay"]) - if os.path.exists(overlay): - clear_path(overlay) + # Remove our overlays + if "portage_overlay" in self.settings: + for repo_path in self.settings["portage_overlay"]: + repo_name = get_repo_name(repo_path) + + repo_conf = self.get_repo_conf_path(repo_name) + chroot_repo_conf = self.to_chroot(repo_conf) + chroot_repo_conf.unlink() + + location = self.get_repo_location(repo_name) + chroot_location = self.to_chroot(location) + clear_path(str(chroot_location)) if "sticky-config" not in self.settings["options"]: # re-write the make.conf to be sure it is clean |