Gentoo Archives: gentoo-commits

From: Magnus Granberg <zorry@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/config/, buildbot_gentoo_ci/steps/, buildbot_gentoo_ci/db/
Date: Sun, 31 Jan 2021 17:42:53
Message-Id: 1612114983.c667f7b39ec20d30678e758dc74d669f6634797a.zorry@gentoo
1 commit: c667f7b39ec20d30678e758dc74d669f6634797a
2 Author: Magnus Granberg <zorry <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 31 17:43:03 2021 +0000
4 Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 31 17:43:03 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=c667f7b3
7
8 Add SetMakeConf
9
10 Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org>
11
12 buildbot_gentoo_ci/config/buildfactorys.py | 3 +
13 buildbot_gentoo_ci/db/connector.py | 2 +
14 buildbot_gentoo_ci/db/model.py | 18 ++++++
15 buildbot_gentoo_ci/db/portages.py | 43 ++++++++++++++
16 buildbot_gentoo_ci/db/projects.py | 21 +++++++
17 buildbot_gentoo_ci/steps/builders.py | 95 ++++++++++++++++++++++++++++++
18 6 files changed, 182 insertions(+)
19
20 diff --git a/buildbot_gentoo_ci/config/buildfactorys.py b/buildbot_gentoo_ci/config/buildfactorys.py
21 index 3fad219..861a4e1 100644
22 --- a/buildbot_gentoo_ci/config/buildfactorys.py
23 +++ b/buildbot_gentoo_ci/config/buildfactorys.py
24 @@ -88,6 +88,7 @@ def build_request_check():
25 def run_build_request():
26 f = util.BuildFactory()
27 # FIXME: 5
28 + # Move the etc/portage stuff to is own file
29 # set needed Propertys
30 f.addStep(builders.SetupPropertys())
31 # Clean and add new /etc/portage
32 @@ -105,4 +106,6 @@ def run_build_request():
33 f.addStep(builders.SetReposConf())
34 # update the repositorys listed in project_repository
35 f.addStep(builders.UpdateRepos())
36 + # setup make.conf
37 + f.addStep(builders.SetMakeConf())
38 return f
39
40 diff --git a/buildbot_gentoo_ci/db/connector.py b/buildbot_gentoo_ci/db/connector.py
41 index 35febe6..7d218ab 100644
42 --- a/buildbot_gentoo_ci/db/connector.py
43 +++ b/buildbot_gentoo_ci/db/connector.py
44 @@ -36,6 +36,7 @@ from buildbot_gentoo_ci.db import categorys
45 from buildbot_gentoo_ci.db import packages
46 from buildbot_gentoo_ci.db import versions
47 from buildbot_gentoo_ci.db import keywords
48 +from buildbot_gentoo_ci.db import portages
49
50 upgrade_message = textwrap.dedent("""\
51
52 @@ -81,6 +82,7 @@ class DBConnector(service.ReconfigurableServiceMixin,
53 self.packages = packages.PackagesConnectorComponent(self)
54 self.versions = versions.VersionsConnectorComponent(self)
55 self.keywords = keywords.KeywordsConnectorComponent(self)
56 + self.portages = portages.PortagesConnectorComponent(self)
57
58 @defer.inlineCallbacks
59 def setup(self, config, check_version=True, verbose=True):
60
61 diff --git a/buildbot_gentoo_ci/db/model.py b/buildbot_gentoo_ci/db/model.py
62 index 596d04e..bd111be 100644
63 --- a/buildbot_gentoo_ci/db/model.py
64 +++ b/buildbot_gentoo_ci/db/model.py
65 @@ -143,6 +143,24 @@ class Model(base.DBConnectorComponent):
66 sa.Column('value', sa.String(255), nullable=False),
67 )
68
69 + portages_makeconf = sautils.Table(
70 + "portages_makeconf", metadata,
71 + sa.Column('id', sa.Integer, primary_key=True),
72 + sa.Column('variable', sa.String(255), nullable=False),
73 + )
74 +
75 + projects_portages_makeconf = sautils.Table(
76 + "projects_portages_makeconf", metadata,
77 + sa.Column('id', sa.Integer, primary_key=True),
78 + sa.Column('project_uuid', sa.String(36),
79 + sa.ForeignKey('projects.uuid', ondelete='CASCADE'),
80 + nullable=False),
81 + sa.Column('makeconf_id', sa.String(255),
82 + sa.ForeignKey('portages_makeconf.id', ondelete='CASCADE'),
83 + nullable=False),
84 + sa.Column('value', sa.String(255), nullable=False),
85 + )
86 +
87 keywords = sautils.Table(
88 "keywords", metadata,
89 # unique uuid per keyword
90
91 diff --git a/buildbot_gentoo_ci/db/portages.py b/buildbot_gentoo_ci/db/portages.py
92 new file mode 100644
93 index 0000000..428fb84
94 --- /dev/null
95 +++ b/buildbot_gentoo_ci/db/portages.py
96 @@ -0,0 +1,43 @@
97 +# This file has parts from Buildbot and is modifyed by Gentoo Authors.
98 +# Buildbot is free software: you can redistribute it and/or modify it
99 +# under the terms of the GNU General Public License as published by the
100 +# Free Software Foundation, version 2.
101 +#
102 +# This program is distributed in the hope that it will be useful, but WITHOUT
103 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
104 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
105 +# details.
106 +#
107 +# You should have received a copy of the GNU General Public License along with
108 +# this program; if not, write to the Free Software Foundation, Inc., 51
109 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
110 +#
111 +# Copyright Buildbot Team Members
112 +# Origins: buildbot.db.*
113 +# Modifyed by Gentoo Authors.
114 +# Copyright 2021 Gentoo Authors
115 +
116 +import uuid
117 +import sqlalchemy as sa
118 +
119 +from twisted.internet import defer
120 +
121 +from buildbot.db import base
122 +
123 +class PortagesConnectorComponent(base.DBConnectorComponent):
124 +
125 + @defer.inlineCallbacks
126 + def getVariables(self):
127 + def thd(conn):
128 + tbl = self.db.model.portages_makeconf
129 + q = tbl.select()
130 + return [self._row2dict(conn, row)
131 + for row in conn.execute(q).fetchall()]
132 + res = yield self.db.pool.do(thd)
133 + return res
134 +
135 + def _row2dict(self, conn, row):
136 + return dict(
137 + id=row.id,
138 + variable=row.variable
139 + )
140
141 diff --git a/buildbot_gentoo_ci/db/projects.py b/buildbot_gentoo_ci/db/projects.py
142 index 00e1569..1f19a00 100644
143 --- a/buildbot_gentoo_ci/db/projects.py
144 +++ b/buildbot_gentoo_ci/db/projects.py
145 @@ -118,6 +118,18 @@ class ProjectsConnectorComponent(base.DBConnectorComponent):
146 res = yield self.db.pool.do(thd)
147 return res
148
149 + @defer.inlineCallbacks
150 + def getProjectMakeConfById(self, uuid, id):
151 + def thd(conn):
152 + tbl = self.db.model.projects_portages_makeconf
153 + q = tbl.select()
154 + q = q.where(tbl.c.project_uuid == uuid)
155 + q = q.where(tbl.c.makeconf_id == id)
156 + return [self._row2dict_projects_portages_makeconf(conn, row)
157 + for row in conn.execute(q).fetchall()]
158 + res = yield self.db.pool.do(thd)
159 + return res
160 +
161 def _row2dict(self, conn, row):
162 return dict(
163 uuid=row.uuid,
164 @@ -149,3 +161,12 @@ class ProjectsConnectorComponent(base.DBConnectorComponent):
165 directorys=row.directorys,
166 value=row.value
167 )
168 +
169 + def _row2dict_projects_portages_makeconf(self, conn, row):
170 + return dict(
171 + id=row.id,
172 + project_uuid=row.project_uuid,
173 + makeconf_id=row.makeconf_id,
174 + value=row.value,
175 + build_id=0
176 + )
177
178 diff --git a/buildbot_gentoo_ci/steps/builders.py b/buildbot_gentoo_ci/steps/builders.py
179 index d3b3607..085d096 100644
180 --- a/buildbot_gentoo_ci/steps/builders.py
181 +++ b/buildbot_gentoo_ci/steps/builders.py
182 @@ -219,3 +219,98 @@ class UpdateRepos(BuildStep):
183 workdir=os.path.join(repository_path, ''))
184 ])
185 return SUCCESS
186 +
187 +class SetMakeConf(BuildStep):
188 +
189 + name = 'SetMakeConf'
190 + description = 'Running'
191 + descriptionDone = 'Ran'
192 + descriptionSuffix = None
193 + haltOnFailure = True
194 + flunkOnFailure = True
195 +
196 + def __init__(self, **kwargs):
197 + super().__init__(**kwargs)
198 +
199 + @defer.inlineCallbacks
200 + def run(self):
201 + #FIXME: Make a dict before we pass it to the make.conf
202 + self.gentooci = self.master.namedServices['services'].namedServices['gentooci']
203 + project_data = self.getProperty('project_data')
204 + makeconf_variables_data = yield self.gentooci.db.portages.getVariables()
205 + separator1 = '\n'
206 + separator2 = ' '
207 + makeconf_list = []
208 + for k in makeconf_variables_data:
209 + makeconf_variables_values_data = yield self.gentooci.db.projects.getProjectMakeConfById(project_data['uuid'], k['id'])
210 + makeconf_variable_list = []
211 + # we add some default values
212 + #FIXME:
213 + # we could set them in a config variables
214 + # FEATURES
215 + if k['variable'] == 'FEATURES':
216 + makeconf_variable_list.append('xattr')
217 + makeconf_variable_list.append('cgroup')
218 + makeconf_variable_list.append('-news')
219 + makeconf_variable_list.append('-collision-protect')
220 + # EMERGE_DEFAULT_OPTS
221 + if k['variable'] == 'EMERGE_DEFAULT_OPTS':
222 + makeconf_variable_list.append('--buildpkg=y')
223 + makeconf_variable_list.append('--rebuild-if-new-rev=y')
224 + makeconf_variable_list.append('--rebuilt-binaries=y')
225 + makeconf_variable_list.append('--usepkg=y')
226 + makeconf_variable_list.append('--nospinner')
227 + makeconf_variable_list.append('--color=n')
228 + makeconf_variable_list.append('--ask=n')
229 + # CFLAGS
230 + if k['variable'] == 'CFLAGS' or k['variable'] == 'FCFLAGS':
231 + makeconf_variable_list.append('-O2')
232 + makeconf_variable_list.append('-pipe')
233 + makeconf_variable_list.append('-march=native')
234 + makeconf_variable_list.append('-fno-diagnostics-color')
235 + #FIXME:
236 + # Depend on worker we may have to add a diffrent march
237 + if k['variable'] == 'CXXFLAGS':
238 + makeconf_variable_list.append('${CFLAGS}')
239 + if k['variable'] == 'FFLAGS':
240 + makeconf_variable_list.append('${FCFLAGS}')
241 + if k['variable'] == 'ACCEPT_PROPERTIES':
242 + makeconf_variable_list.append('-interactive')
243 + if k['variable'] == 'ACCEPT_RESTRICT':
244 + makeconf_variable_list.append('-fetch')
245 + for v in makeconf_variables_values_data:
246 + if v['build_id'] is 0:
247 + makeconf_variable_list.append(v['value'])
248 + if k['variable'] == 'ACCEPT_LICENSE' and makeconf_variable_list != []:
249 + makeconf_variable_list.append('ACCEPT_LICENSE="*"')
250 + if makeconf_variable_list != []:
251 + makeconf_variable_string = k['variable'] + '="' + separator2.join(makeconf_variable_list) + '"'
252 + makeconf_list.append(makeconf_variable_string)
253 + # add hardcoded variables and values
254 + #FIXME:
255 + # we could set them in a config variables
256 + makeconf_list.append('LC_MESSAGES=C')
257 + makeconf_list.append('NOCOLOR="true"')
258 + makeconf_list.append('GCC_COLORS=""')
259 + makeconf_list.append('PORTAGE_TMPFS="/dev/shm"')
260 + makeconf_list.append('CLEAN_DELAY=0')
261 + makeconf_list.append('NOCOLOR=true')
262 + makeconf_list.append('PORT_LOGDIR="/var/cache/portage/logs"')
263 + makeconf_list.append('PKGDIR="/var/cache/portage/packages"')
264 + makeconf_list.append('PORTAGE_ELOG_CLASSES="qa"')
265 + makeconf_list.append('PORTAGE_ELOG_SYSTEM="save"')
266 + # add ACCEPT_KEYWORDS from the project_data info
267 + keyword_data = yield self.gentooci.db.keywords.getKeywordById(project_data['keyword_id'])
268 + if project_data['status'] == 'unstable':
269 + makeconf_keyword = '~' + keyword_data['name']
270 + else:
271 + makeconf_keyword = keyword_data['name']
272 + makeconf_list.append('ACCEPT_KEYWORDS="' + makeconf_keyword + '"')
273 + makeconf_string = separator1.join(makeconf_list)
274 + print(makeconf_string)
275 + yield self.build.addStepsAfterCurrentStep([
276 + steps.StringDownload(makeconf_string + separator1,
277 + workerdest="make.conf",
278 + workdir='/etc/portage/')
279 + ])
280 + return SUCCESS