Gentoo Archives: gentoo-commits

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