1 |
This commit unifies the handling of the main repo and the other repos.
|
2 |
All are stored in one common list. A mount entry is created for
|
3 |
each entry in the list (previously a mount entry was only created
|
4 |
for the main repo and the other repos were copied into the chroot).
|
5 |
This means each non-main repo can now be either a directory or a
|
6 |
squash files (previously the non-main repos had to be directories).
|
7 |
The existing mount logic will bind-mount the repos that are stored as
|
8 |
directories, removing the need for copying.
|
9 |
|
10 |
A repos.conf entry will be created for each entry in the list.
|
11 |
This means a repos.conf entry for the main repo can now be created
|
12 |
(previously repos.conf entries were only created for the non-main
|
13 |
repos). The repos.conf entry will only be created if the target
|
14 |
location for the main repo is non-default, i.e. unequal to
|
15 |
/var/db/repos/gentoo. This mirrors the behavior of write_make_conf,
|
16 |
which only writes the PORTDIR variable to make.conf if the location
|
17 |
of the main repo is non-default.
|
18 |
|
19 |
As a side effect, the PORTDIR variable is now no longer needed,
|
20 |
and will be removed from write_make_conf in a separate commit.
|
21 |
|
22 |
Signed-off-by: Felix Bier <felix.bier@×××××××××××××.com>
|
23 |
---
|
24 |
catalyst/base/stagebase.py | 88 ++++++++++++++++++++++++++------------
|
25 |
catalyst/defaults.py | 5 ---
|
26 |
2 files changed, 60 insertions(+), 33 deletions(-)
|
27 |
|
28 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
|
29 |
index fedc8f87..97e2318c 100644
|
30 |
--- a/catalyst/base/stagebase.py
|
31 |
+++ b/catalyst/base/stagebase.py
|
32 |
@@ -219,8 +219,17 @@ class StageBase(TargetBase, ClearBase, GenBase):
|
33 |
# Setup our mount points.
|
34 |
self.mount = copy.deepcopy(MOUNT_DEFAULTS)
|
35 |
|
36 |
- self.mount['portdir']['source'] = self.snapshot
|
37 |
- self.mount['portdir']['target'] = self.settings['repo_basedir'] + '/' + self.settings['repo_name']
|
38 |
+ # Create mount entry for each repository
|
39 |
+ for path, name, _ in self.repos:
|
40 |
+ name = get_repo_name(path)
|
41 |
+ mount_id = f'repo_{name}'
|
42 |
+
|
43 |
+ self.mount[mount_id] = {
|
44 |
+ 'enable': True,
|
45 |
+ 'source': path,
|
46 |
+ 'target': self.get_repo_location(name)
|
47 |
+ }
|
48 |
+
|
49 |
self.mount['distdir']['source'] = self.settings['distdir']
|
50 |
self.mount["distdir"]['target'] = self.settings['target_distdir']
|
51 |
|
52 |
@@ -587,13 +596,41 @@ class StageBase(TargetBase, ClearBase, GenBase):
|
53 |
"/busybox_config"]
|
54 |
|
55 |
def set_repos(self):
|
56 |
+
|
57 |
+ # Each entry in this list will be a tuple of the form
|
58 |
+ # (source, name, default)
|
59 |
+ #
|
60 |
+ # source: the location of the repo on the host system,
|
61 |
+ # either a directory or a squashfs file.
|
62 |
+ #
|
63 |
+ # name: the repository name parsed from the repo.
|
64 |
+ # This is just a caching mechanism to avoid parsing the name
|
65 |
+ # every time the source is processed.
|
66 |
+ #
|
67 |
+ # default: Default location where the repo is expected in the
|
68 |
+ # target system. If this matches the path where we mount the repo to
|
69 |
+ # (as per get_repo_location), then we can skip generating a repos.conf
|
70 |
+ # entry for that repo. Currently this mechanism is only used for
|
71 |
+ # the main repo, which has a default location hard-coded in
|
72 |
+ # /usr/share/portage/config/repos.conf. For the other repos,
|
73 |
+ # the default is set to None.
|
74 |
+ self.repos = []
|
75 |
+
|
76 |
+ # Create entry for snapshot
|
77 |
+ default_location = Path(confdefaults['repo_basedir'], confdefaults['repo_name'])
|
78 |
+ self.repos.append((self.snapshot, get_repo_name(self.snapshot), default_location))
|
79 |
+
|
80 |
+ # Create entry for every other repo
|
81 |
if 'repos' in self.settings:
|
82 |
if isinstance(self.settings['repos'], str):
|
83 |
self.settings['repos'] = \
|
84 |
self.settings['repos'].split()
|
85 |
- log.info('repos directories are set to: %s',
|
86 |
+ log.info('repos are set to: %s',
|
87 |
' '.join(self.settings['repos']))
|
88 |
|
89 |
+ get_info = lambda repo: (repo, get_repo_name(repo), None)
|
90 |
+ self.repos.extend(map(get_info, self.settings['repos']))
|
91 |
+
|
92 |
def set_overlay(self):
|
93 |
if self.settings["spec_prefix"] + "/overlay" in self.settings:
|
94 |
if isinstance(self.settings[self.settings['spec_prefix'] + '/overlay'], str):
|
95 |
@@ -832,24 +869,19 @@ class StageBase(TargetBase, ClearBase, GenBase):
|
96 |
raise CatalystError(f'Could not write {repo_conf_chroot}: {e}') from e
|
97 |
|
98 |
def process_repos(self):
|
99 |
- """ We copy the contents of our repos to get_repo_location(repo_name) """
|
100 |
- if 'repos' in self.settings:
|
101 |
- for x in self.settings['repos']:
|
102 |
- if os.path.exists(x):
|
103 |
- name = get_repo_name(x)
|
104 |
+ """ Create repos.conf entry for every repo """
|
105 |
|
106 |
- location = self.get_repo_location(name)
|
107 |
- config = configparser.ConfigParser()
|
108 |
- config[name] = {'location': location}
|
109 |
- self.write_repo_conf(name, config)
|
110 |
+ for _, name, default in self.repos:
|
111 |
+ location = self.get_repo_location(name)
|
112 |
|
113 |
- location_chroot = self.to_chroot(location)
|
114 |
- location_chroot.mkdir(mode=0o755, parents=True, exist_ok=True)
|
115 |
+ if default == location:
|
116 |
+ log.debug('Skipping repos.conf entry for repo %s '
|
117 |
+ 'with default location %s.', name, location)
|
118 |
+ continue
|
119 |
|
120 |
- log.info('Copying overlay dir %s to %s', x, location_chroot)
|
121 |
- cmd(f'cp -a {x}/* {location_chroot}', env=self.env)
|
122 |
- else:
|
123 |
- log.warning('Skipping missing overlay %s.', x)
|
124 |
+ config = configparser.ConfigParser()
|
125 |
+ config[name] = {'location': location}
|
126 |
+ self.write_repo_conf(name, config)
|
127 |
|
128 |
def root_overlay(self):
|
129 |
""" Copy over the root_overlay """
|
130 |
@@ -1144,18 +1176,18 @@ class StageBase(TargetBase, ClearBase, GenBase):
|
131 |
log.warning("You've been hacking. Clearing target patches: %s", target)
|
132 |
clear_path(target)
|
133 |
|
134 |
- # Remove our overlays
|
135 |
- if 'repos' in self.settings:
|
136 |
- for repo_path in self.settings['repos']:
|
137 |
- repo_name = get_repo_name(repo_path)
|
138 |
+ # Remove repo data
|
139 |
+ for _, name, _ in self.repos:
|
140 |
|
141 |
- repo_conf = self.get_repo_conf_path(repo_name)
|
142 |
- chroot_repo_conf = self.to_chroot(repo_conf)
|
143 |
- chroot_repo_conf.unlink()
|
144 |
+ # Remove repos.conf entry
|
145 |
+ repo_conf = self.get_repo_conf_path(name)
|
146 |
+ chroot_repo_conf = self.to_chroot(repo_conf)
|
147 |
+ chroot_repo_conf.unlink(missing_ok=True)
|
148 |
|
149 |
- location = self.get_repo_location(repo_name)
|
150 |
- chroot_location = self.to_chroot(location)
|
151 |
- clear_path(str(chroot_location))
|
152 |
+ # The repo has already been unmounted, remove the mount point
|
153 |
+ location = self.get_repo_location(name)
|
154 |
+ chroot_location = self.to_chroot(location)
|
155 |
+ clear_path(str(chroot_location))
|
156 |
|
157 |
if "sticky-config" not in self.settings["options"]:
|
158 |
# re-write the make.conf to be sure it is clean
|
159 |
diff --git a/catalyst/defaults.py b/catalyst/defaults.py
|
160 |
index 3d5c0a7f..ccb0a584 100644
|
161 |
--- a/catalyst/defaults.py
|
162 |
+++ b/catalyst/defaults.py
|
163 |
@@ -85,11 +85,6 @@ MOUNT_DEFAULTS = OrderedDict([
|
164 |
'source': 'tmpfs',
|
165 |
'target': '/run',
|
166 |
}),
|
167 |
- ('portdir', {
|
168 |
- 'enable': True,
|
169 |
- 'source': 'config',
|
170 |
- 'target': 'config',
|
171 |
- }),
|
172 |
('distdir', {
|
173 |
'enable': True,
|
174 |
'source': 'config',
|
175 |
--
|
176 |
2.30.0 |