Gentoo Archives: gentoo-catalyst

From: Felix Bier <Felix.Bier@×××××××××××××.com>
To: "gentoo-catalyst@l.g.o" <gentoo-catalyst@l.g.o>
Subject: [gentoo-catalyst] Re: [PATCH 2/2] Move from PORTDIR_OVERLAY to repos.conf
Date: Sun, 18 Oct 2020 15:15:23
Message-Id: c7763cd2b8f97543c00a39a5b369daf0be4122f3.camel@rohde-schwarz.com
In Reply to: [gentoo-catalyst] [PATCH 2/2] Move from PORTDIR_OVERLAY to repos.conf by Felix Bier
1 This commit fixes the following issues:
2
3 * The PORTDIR_OVERLAY variable has been deprecated by Gentoo.
4
5 With this commit, the variable is no longer written to the
6 generated make.conf. Instead, a config file
7 /etc/portage/repos.conf/<repo-name>.conf
8 is generated for each overlay. The repo name is read from the
9 overlay using the portage API. Internally, portage parses
10 metadata/layout.conf and profiles/repo_name to obtain the name.
11
12 References:
13 https://wiki.gentoo.org/wiki//etc/portage/make.conf
14 https://wiki.gentoo.org/wiki//etc/portage/repos.conf
15
16 * All overlays were copied into the same target directory. If the
17 same file name occurred in multiple overlays, the last overlay
18 would overwrite all previous files with this name. In particular,
19 only the metadata/layout.conf of the last overlay was retained,
20 so it was not possible to reference the other overlays e.g. via
21 the masters entry in the layout.conf or the portage-2 syntax
22 for specifying a parent profile from another overlay. Also,
23 this created problems when the overlays contained ebuilds
24 for the same package, but with differing versions, because
25 after copying, the target directory contained both versions of the
26 ebuild but only the manifest file of the last overlay.
27
28 With this commit, each overlay is copied into a separate
29 sub-directory, e.g. /var/gentoo/repos/local/<repo-name>/.
30 This directory is referenced via the location entry in the
31 generated /etc/portage/repos.conf/<repo-name>.conf.
32 ---
33 catalyst/base/stagebase.py | 72 ++++++++++++++++++++++++++++----------
34 catalyst/defaults.py | 1 +
35 catalyst/support.py | 18 ++++++++++
36 3 files changed, 72 insertions(+), 19 deletions(-)
37
38 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
39 index ac0f4f24..3d4f2a76 100644
40 --- a/catalyst/base/stagebase.py
41 +++ b/catalyst/base/stagebase.py
42 @@ -1,4 +1,5 @@
43
44 +import configparser
45 import copy
46 import os
47 import platform
48 @@ -17,7 +18,8 @@ from DeComp.compress import CompressMap
49 from catalyst import log
50 from catalyst.defaults import (confdefaults, MOUNT_DEFAULTS, PORT_LOGDIR_CLEAN)
51 from catalyst.support import (CatalystError, file_locate, normpath,
52 - cmd, read_makeconf, ismount, file_check)
53 + cmd, read_makeconf, get_repo_name, ismount,
54 + file_check)
55 from catalyst.base.targetbase import TargetBase
56 from catalyst.base.clearbase import ClearBase
57 from catalyst.base.genbase import GenBase
58 @@ -821,17 +823,48 @@ class StageBase(TargetBase, ClearBase, GenBase):
59 env=self.env)
60 self.resume.enable("setup_confdir")
61
62 + def get_repo_conf_path(self, repo_name):
63 + """ Construct repo conf path: /etc/portage/repos.conf/{name}.conf """
64 + return normpath(os.path.join(self.settings['repos_conf'], repo_name + ".conf"))
65 +
66 + def get_overlay_location(self, repo_name):
67 + """ Construct overlay repo path: /var/gentoo/repos/local/{name} """
68 + return normpath(os.path.join(self.settings['local_overlay'], repo_name))
69 +
70 + def write_repo_conf(self, repo_name, config):
71 + """ Write ConfigParser to {chroot}/etc/portage/repo.conf/{name}.conf """
72 + repo_conf = self.get_repo_conf_path(repo_name)
73 + chroot_repo_conf = self.settings['chroot_path'] + repo_conf
74 + log.info('Creating repo config %s.', chroot_repo_conf)
75 + ensure_dirs(os.path.dirname(chroot_repo_conf))
76 +
77 + try:
78 + with open(chroot_repo_conf, 'w') as myf:
79 + config.write(myf)
80 + except OSError as e:
81 + raise CatalystError('Could not write {}: {}'.format(
82 + chroot_repo_conf, e)) from e
83 +
84 def portage_overlay(self):
85 - """ We copy the contents of our overlays to /usr/local/portage """
86 + """ We copy the contents of our overlays to /var/gentoo/repos/local/{name} """
87 if "portage_overlay" in self.settings:
88 for x in self.settings["portage_overlay"]:
89 if os.path.exists(x):
90 - log.info('Copying overlay dir %s', x)
91 - ensure_dirs(
92 - self.settings['chroot_path'] + self.settings['local_overlay'])
93 - cmd("cp -a " + x + "/* " + self.settings["chroot_path"] +
94 - self.settings["local_overlay"],
95 - env=self.env)
96 + name = get_repo_name(x)
97 +
98 + location = self.get_overlay_location(name)
99 + config = configparser.ConfigParser()
100 + config[name] = {'location': location}
101 + self.write_repo_conf(name, config)
102 +
103 + chroot_location = normpath(
104 + self.settings['chroot_path'] + location)
105 + log.info('Copying overlay dir %s to %s',
106 + x, chroot_location)
107 + ensure_dirs(chroot_location)
108 + cmd('cp -a ' + x + '/* ' + chroot_location, env=self.env)
109 + else:
110 + log.warning('Skipping missing overlay %s.', x)
111
112 def root_overlay(self):
113 """ Copy over the root_overlay """
114 @@ -1080,12 +1113,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
115 varname = x.split('_')[1].upper()
116 myf.write(f'{varname}="{self.settings[x]}"\n')
117
118 - if setup:
119 - # Setup the portage overlay
120 - if "portage_overlay" in self.settings:
121 - myf.write('PORTDIR_OVERLAY="%s"\n' %
122 - self.settings["local_overlay"])
123 -
124 # Set default locale for system responses. #478382
125 myf.write(
126 '\n'
127 @@ -1157,11 +1184,18 @@ class StageBase(TargetBase, ClearBase, GenBase):
128 log.warning("You've been hacking. Clearing target patches: %s", target)
129 clear_path(target)
130
131 - # Remove our overlay
132 - overlay = normpath(
133 - self.settings["chroot_path"] + self.settings["local_overlay"])
134 - if os.path.exists(overlay):
135 - clear_path(overlay)
136 + # Remove our overlays
137 + if "portage_overlay" in self.settings:
138 + for repo_path in self.settings["portage_overlay"]:
139 + repo_name = get_repo_name(repo_path)
140 +
141 + repo_conf = self.get_repo_conf_path(repo_name)
142 + chroot_repo_conf = self.settings["chroot_path"] + repo_conf
143 + clear_path(chroot_repo_conf)
144 +
145 + location = self.get_overlay_location(repo_name)
146 + chroot_location = self.settings['chroot_path'] + location
147 + clear_path(chroot_location)
148
149 if "sticky-config" not in self.settings["options"]:
150 # re-write the make.conf to be sure it is clean
151 diff --git a/catalyst/defaults.py b/catalyst/defaults.py
152 index c153fcc4..9660a7f3 100644
153 --- a/catalyst/defaults.py
154 +++ b/catalyst/defaults.py
155 @@ -38,6 +38,7 @@ confdefaults = {
156 "local_overlay": "/var/db/repos/local",
157 "port_conf": "/etc/portage",
158 "make_conf": "%(port_conf)s/make.conf",
159 + "repos_conf": "%(port_conf)s/repos.conf",
160 "options": set(),
161 "pkgdir": "/var/cache/binpkgs",
162 "port_tmpdir": "/var/tmp/portage",
163 diff --git a/catalyst/support.py b/catalyst/support.py
164 index a6a6854a..b8069c7d 100644
165 --- a/catalyst/support.py
166 +++ b/catalyst/support.py
167 @@ -7,6 +7,8 @@ import shutil
168 import time
169 from subprocess import Popen
170
171 +from portage.repository.config import RepoConfig
172 +
173 from catalyst import log
174
175 BASH_BINARY = "/bin/bash"
176 @@ -179,6 +181,22 @@ def read_makeconf(mymakeconffile):
177 return makeconf
178
179
180 +def get_repo_name(repo_path):
181 + """ Get the name of the repo at the given repo_path.
182 +
183 + References:
184 + https://wiki.gentoo.org/wiki/Repository_format/profiles/repo_name
185 + https://wiki.gentoo.org/wiki/Repository_format/metadata/layout.conf#repo-name
186 + """
187 +
188 + repo_config = RepoConfig(None, {"location": repo_path})
189 +
190 + if repo_config.missing_repo_name:
191 + raise CatalystError("Missing name in repository {}".format(repo_path))
192 +
193 + return repo_config.name
194 +
195 +
196 def pathcompare(path1, path2):
197 # Change double slashes to slash
198 path1 = re.sub(r"//", r"/", path1)
199 --
200 2.28.0

Replies