Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [PATCH 4/7] base/stagebase.py: Seperate out the writing of the make.conf file
Date: Fri, 10 Mar 2017 19:23:19
Message-Id: 20170310112315.26ffd150.dolsen@gentoo.org
1 From 2ca4770bb462f54229a2c84e47d2c7d78794a4c0 Mon Sep 17 00:00:00 2001
2 From: Brian Dolbec <dolsen@g.o>
3 Date: Thu, 9 Mar 2017 01:14:04 -0800
4 Subject: [PATCH 4/7] base/stagebase.py: Seperate out the writing of the
5 make.conf file
6 To: gentoo-catalyst@l.g.o
7
8 By separating out the writing of the make.conf file, it keeps all code
9 to do so in one place. I also fixed the code to correctly set the
10 target chroot directories for PORTDIR, DISTDIR, PKGDIR and
11 PORTDIR_OVERLAY. The same code also re-writes make.conf toggling any
12 PORTDIR_OVERLAY setting during the clean() run.
13
14 Add target_distdir and target_pkgdir settings to defaults and catalyst.conf.
15 This allows for more flexibility between host and target settings. They can be individually
16 configured this way.
17
18 Update target an source mounts from the configured settings.
19 ---
20 catalyst/base/stagebase.py | 194 ++++++++++++++++++++++++---------------------
21 catalyst/defaults.py | 2 +
22 etc/catalyst.conf | 2 +
23 3 files changed, 106 insertions(+), 92 deletions(-)
24
25 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
26 index 677e19dc..31efdf68 100644
27 --- a/catalyst/base/stagebase.py
28 +++ b/catalyst/base/stagebase.py
29 @@ -225,8 +225,13 @@ class StageBase(TargetBase, ClearBase, GenBase):
30 self.mounts = ["proc", "dev", "portdir", "distdir", "port_tmpdir"]
31 # initialize our source mounts
32 self.mountmap = SOURCE_MOUNT_DEFAULTS.copy()
33 - # update them from settings
34 + # update these from settings
35 + self.mountmap["portdir"] = self.settings["portdir"]
36 self.mountmap["distdir"] = self.settings["distdir"]
37 + self.target_mounts["portdir"] = normpath(self.settings["repo_basedir"] +
38 + "/" + self.settings["repo_name"])
39 + self.target_mounts["distdir"] = self.settings["target_distdir"]
40 + self.target_mounts["packagedir"] = self.settings["target_pkgdir"]
41 if "snapcache" not in self.settings["options"]:
42 self.mounts.remove("portdir")
43 self.mountmap["portdir"] = None
44 @@ -1070,96 +1075,106 @@ class StageBase(TargetBase, ClearBase, GenBase):
45 if os.path.exists(hosts_file):
46 os.rename(hosts_file, hosts_file + '.catalyst')
47 shutil.copy('/etc/hosts', hosts_file)
48 + # write out the make.conf
49 + try:
50 + self.write_make_conf(setup=True)
51 + except OSError as e:
52 + raise CatalystError('Could not write %s: %s' % (
53 + normpath(self.settings["chroot_path"] +
54 + self.settings["make_conf"]), e))
55 + self.resume.enable("chroot_setup")
56
57 - # Modify and write out make.conf (for the chroot)
58 - makepath = normpath(self.settings["chroot_path"] +
59 - self.settings["make_conf"])
60 - clear_path(makepath)
61 - myf = open(makepath, "w")
62 - myf.write("# These settings were set by the catalyst build script "
63 - "that automatically\n# built this stage.\n")
64 - myf.write("# Please consult "
65 - "/usr/share/portage/config/make.conf.example "
66 - "for a more\n# detailed example.\n")
67 -
68 - for flags in ["CFLAGS", "CXXFLAGS", "FCFLAGS", "FFLAGS", "LDFLAGS",
69 - "ASFLAGS"]:
70 - if not flags in self.settings:
71 - continue
72 - if flags in ["LDFLAGS", "ASFLAGS"]:
73 - myf.write("# %s is unsupported. USE AT YOUR OWN RISK!\n"
74 - % flags)
75 - if (flags is not "CFLAGS" and
76 - self.settings[flags] == self.settings["CFLAGS"]):
77 - myf.write('%s="${CFLAGS}"\n' % flags)
78 - elif isinstance(self.settings[flags], list):
79 - myf.write('%s="%s"\n'
80 - % (flags, ' '.join(self.settings[flags])))
81 - else:
82 - myf.write('%s="%s"\n'
83 - % (flags, self.settings[flags]))
84 -
85 - if "CBUILD" in self.settings:
86 - myf.write("# This should not be changed unless you know exactly"
87 - " what you are doing. You\n# should probably be "
88 - "using a different stage, instead.\n")
89 - myf.write('CBUILD="' + self.settings["CBUILD"] + '"\n')
90 -
91 - if "CHOST" in self.settings:
92 - myf.write("# WARNING: Changing your CHOST is not something "
93 - "that should be done lightly.\n# Please consult "
94 - "https://wiki.gentoo.org/wiki/Changing_the_CHOST_variable "
95 - "before changing.\n")
96 - myf.write('CHOST="' + self.settings["CHOST"] + '"\n')
97 -
98 - # Figure out what our USE vars are for building
99 - myusevars = []
100 - if "HOSTUSE" in self.settings:
101 - myusevars.extend(self.settings["HOSTUSE"])
102 -
103 - if "use" in self.settings:
104 - myusevars.extend(self.settings["use"])
105 -
106 - if myusevars:
107 - myf.write("# These are the USE and USE_EXPAND flags that were "
108 - "used for\n# building in addition to what is provided "
109 - "by the profile.\n")
110 - myusevars = sorted(set(myusevars))
111 - myf.write('USE="' + ' '.join(myusevars) + '"\n')
112 - if '-*' in myusevars:
113 - log.warning(
114 - 'The use of -* in %s/use will cause portage to ignore\n'
115 - 'package.use in the profile and portage_confdir.\n'
116 - "You've been warned!", self.settings['spec_prefix'])
117 -
118 - myuseexpandvars = {}
119 - if "HOSTUSEEXPAND" in self.settings:
120 - for hostuseexpand in self.settings["HOSTUSEEXPAND"]:
121 - myuseexpandvars.update(
122 - {hostuseexpand:self.settings["HOSTUSEEXPAND"][hostuseexpand]})
123 -
124 - if myuseexpandvars:
125 - for hostuseexpand in myuseexpandvars:
126 - myf.write(hostuseexpand + '="' +
127 - ' '.join(myuseexpandvars[hostuseexpand]) + '"\n')
128 -
129 - myf.write('PORTDIR="%s"\n' % self.settings['portdir'])
130 - myf.write('DISTDIR="%s"\n' % self.settings['distdir'])
131 - myf.write('PKGDIR="%s"\n' % self.settings['packagedir'])
132 -
133 + def write_make_conf(self, setup=True):
134 + # Modify and write out make.conf (for the chroot)
135 + makepath = normpath(self.settings["chroot_path"] +
136 + self.settings["make_conf"])
137 + clear_path(makepath)
138 + myf = open(makepath, "w")
139 + myf.write("# These settings were set by the catalyst build script "
140 + "that automatically\n# built this stage.\n")
141 + myf.write("# Please consult "
142 + "/usr/share/portage/config/make.conf.example "
143 + "for a more\n# detailed example.\n")
144 +
145 + for flags in ["CFLAGS", "CXXFLAGS", "FCFLAGS", "FFLAGS", "LDFLAGS",
146 + "ASFLAGS"]:
147 + if not flags in self.settings:
148 + continue
149 + if flags in ["LDFLAGS", "ASFLAGS"]:
150 + myf.write("# %s is unsupported. USE AT YOUR OWN RISK!\n"
151 + % flags)
152 + if (flags is not "CFLAGS" and
153 + self.settings[flags] == self.settings["CFLAGS"]):
154 + myf.write('%s="${CFLAGS}"\n' % flags)
155 + elif isinstance(self.settings[flags], list):
156 + myf.write('%s="%s"\n'
157 + % (flags, ' '.join(self.settings[flags])))
158 + else:
159 + myf.write('%s="%s"\n'
160 + % (flags, self.settings[flags]))
161 +
162 + if "CBUILD" in self.settings:
163 + myf.write("# This should not be changed unless you know exactly"
164 + " what you are doing. You\n# should probably be "
165 + "using a different stage, instead.\n")
166 + myf.write('CBUILD="' + self.settings["CBUILD"] + '"\n')
167 +
168 + if "CHOST" in self.settings:
169 + myf.write("# WARNING: Changing your CHOST is not something "
170 + "that should be done lightly.\n# Please consult "
171 + "https://wiki.gentoo.org/wiki/Changing_the_CHOST_variable "
172 + "before changing.\n")
173 + myf.write('CHOST="' + self.settings["CHOST"] + '"\n')
174 +
175 + # Figure out what our USE vars are for building
176 + myusevars = []
177 + if "HOSTUSE" in self.settings:
178 + myusevars.extend(self.settings["HOSTUSE"])
179 +
180 + if "use" in self.settings:
181 + myusevars.extend(self.settings["use"])
182 +
183 + if myusevars:
184 + myf.write("# These are the USE and USE_EXPAND flags that were "
185 + "used for\n# building in addition to what is provided "
186 + "by the profile.\n")
187 + myusevars = sorted(set(myusevars))
188 + myf.write('USE="' + ' '.join(myusevars) + '"\n')
189 + if '-*' in myusevars:
190 + log.warning(
191 + 'The use of -* in %s/use will cause portage to ignore\n'
192 + 'package.use in the profile and portage_confdir.\n'
193 + "You've been warned!", self.settings['spec_prefix'])
194 +
195 + myuseexpandvars = {}
196 + if "HOSTUSEEXPAND" in self.settings:
197 + for hostuseexpand in self.settings["HOSTUSEEXPAND"]:
198 + myuseexpandvars.update(
199 + {hostuseexpand:self.settings["HOSTUSEEXPAND"][hostuseexpand]})
200 +
201 + if myuseexpandvars:
202 + for hostuseexpand in myuseexpandvars:
203 + myf.write(hostuseexpand + '="' +
204 + ' '.join(myuseexpandvars[hostuseexpand]) + '"\n')
205 + # write out a shipable version
206 + target_portdir = normpath(self.settings["repo_basedir"] + "/" +
207 + self.settings["repo_name"])
208 +
209 + myf.write('PORTDIR="%s"\n' % target_portdir)
210 + myf.write('DISTDIR="%s"\n' % self.settings['target_distdir'])
211 + myf.write('PKGDIR="%s"\n' % self.settings['target_pkgdir'])
212 + if setup:
213 # Setup the portage overlay
214 if "portage_overlay" in self.settings:
215 myf.write('PORTDIR_OVERLAY="%s"\n' % self.settings["local_overlay"])
216
217 - # Set default locale for system responses. #478382
218 - myf.write(
219 - '\n'
220 - '# This sets the language of build output to English.\n'
221 - '# Please keep this setting intact when reporting bugs.\n'
222 - 'LC_MESSAGES=C\n')
223 -
224 - myf.close()
225 - self.resume.enable("chroot_setup")
226 + # Set default locale for system responses. #478382
227 + myf.write(
228 + '\n'
229 + '# This sets the language of build output to English.\n'
230 + '# Please keep this setting intact when reporting bugs.\n'
231 + 'LC_MESSAGES=C\n')
232 + myf.close()
233
234 def fsscript(self):
235 if "autoresume" in self.settings["options"] \
236 @@ -1202,12 +1217,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
237
238 make_conf = self.settings['chroot_path'] + self.settings['make_conf']
239 try:
240 - with open(make_conf) as f:
241 - data = f.readlines()
242 - data = ''.join(x for x in data
243 - if not x.startswith('PORTDIR_OVERLAY'))
244 - with open(make_conf, 'w') as f:
245 - f.write(data)
246 + self.write_make_conf(setup=False)
247 except OSError as e:
248 raise CatalystError('Could not update %s: %s' % (make_conf, e))
249
250 diff --git a/catalyst/defaults.py b/catalyst/defaults.py
251 index 0bba6f4d..84ed2822 100644
252 --- a/catalyst/defaults.py
253 +++ b/catalyst/defaults.py
254 @@ -59,6 +59,8 @@ confdefaults={
255 "snapshot_name": "portage-",
256 "source_matching": "strict",
257 "storedir": "/var/tmp/catalyst",
258 + "target_distdir": "/var/portage/distfiles",
259 + "target_pkgdir":"/var/portage/packages",
260 }
261
262 DEFAULT_CONFIG_FILE = '/etc/catalyst/catalyst.conf'
263 diff --git a/etc/catalyst.conf b/etc/catalyst.conf
264 index 2e61ea4f..b4db063c 100644
265 --- a/etc/catalyst.conf
266 +++ b/etc/catalyst.conf
267 @@ -85,6 +85,8 @@ portdir="/usr/portage"
268 #
269 repo_basedir="/usr"
270 repo_name="portage"
271 +target_distdir="/usr/portage/distfiles"
272 +target_pkgdir="/usr/portage/packages"
273
274 # sharedir specifies where all of the catalyst runtime executables
275 # and other shared lib objects are.
276 --
277 2.12.0
278
279
280
281 --
282 Brian Dolbec <dolsen>