blob: 63b4187bad5ac378d6b81d16039b011810129404 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# BitBake Toaster Implementation
6#
7# Copyright (C) 2014 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
23import os
24import sys
25import re
Patrick Williamsf1e5d692016-03-30 15:21:19 -050026import shutil
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027import time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028from django.db import transaction
29from django.db.models import Q
30from bldcontrol.models import BuildEnvironment, BRLayer, BRVariable, BRTarget, BRBitbake
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031from orm.models import CustomImageRecipe, Layer, Layer_Version, ProjectLayer, ToasterSetting
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032import subprocess
33
34from toastermain import settings
35
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036from bldcontrol.bbcontroller import BuildEnvironmentController, ShellCmdException, BuildSetupException, BitbakeController
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38import logging
39logger = logging.getLogger("toaster")
40
41from pprint import pprint, pformat
42
43class LocalhostBEController(BuildEnvironmentController):
44 """ Implementation of the BuildEnvironmentController for the localhost;
45 this controller manages the default build directory,
46 the server setup and system start and stop for the localhost-type build environment
47
48 """
49
50 def __init__(self, be):
51 super(LocalhostBEController, self).__init__(be)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 self.pokydirname = None
53 self.islayerset = False
54
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 def _shellcmd(self, command, cwd=None, nowait=False,env=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 if cwd is None:
57 cwd = self.be.sourcedir
Brad Bishopd7bf8c12018-02-25 22:55:05 -050058 if env is None:
59 env=os.environ.copy()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
Brad Bishopd7bf8c12018-02-25 22:55:05 -050061 logger.debug("lbc_shellcmd: (%s) %s" % (cwd, command))
62 p = subprocess.Popen(command, cwd = cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 if nowait:
64 return
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 (out,err) = p.communicate()
66 p.wait()
67 if p.returncode:
68 if len(err) == 0:
69 err = "command: %s \n%s" % (command, out)
70 else:
71 err = "command: %s \n%s" % (command, err)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060072 logger.warning("localhostbecontroller: shellcmd error %s" % err)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 raise ShellCmdException(err)
74 else:
75 logger.debug("localhostbecontroller: shellcmd success")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060076 return out.decode('utf-8')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 def getGitCloneDirectory(self, url, branch):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050079 """Construct unique clone directory name out of url and branch."""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 if branch != "HEAD":
Patrick Williamsc0f7c042017-02-23 20:41:17 -060081 return "_toaster_clones/_%s_%s" % (re.sub('[:/@+%]', '_', url), branch)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
83 # word of attention; this is a localhost-specific issue; only on the localhost we expect to have "HEAD" releases
84 # which _ALWAYS_ means the current poky checkout
85 from os.path import dirname as DN
86 local_checkout_path = DN(DN(DN(DN(DN(os.path.abspath(__file__))))))
87 #logger.debug("localhostbecontroller: using HEAD checkout in %s" % local_checkout_path)
88 return local_checkout_path
89
90
Brad Bishopd7bf8c12018-02-25 22:55:05 -050091 def setCloneStatus(self,bitbake,status,total,current):
92 bitbake.req.build.repos_cloned=current
93 bitbake.req.build.repos_to_clone=total
94 bitbake.req.build.save()
95
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050096 def setLayers(self, bitbake, layers, targets):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 """ a word of attention: by convention, the first layer for any build will be poky! """
98
99 assert self.be.sourcedir is not None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600100
101 layerlist = []
102 nongitlayerlist = []
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500103 git_env = os.environ.copy()
104 # (note: add custom environment settings here)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600105
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500106 # set layers in the layersource
107
108 # 1. get a list of repos with branches, and map dirpaths for each layer
109 gitrepos = {}
110
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600111 # if we're using a remotely fetched version of bitbake add its git
112 # details to the list of repos to clone
113 if bitbake.giturl and bitbake.commit:
114 gitrepos[(bitbake.giturl, bitbake.commit)] = []
115 gitrepos[(bitbake.giturl, bitbake.commit)].append(
116 ("bitbake", bitbake.dirpath))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117
118 for layer in layers:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500119 # We don't need to git clone the layer for the CustomImageRecipe
120 # as it's generated by us layer on if needed
121 if CustomImageRecipe.LAYER_NAME in layer.name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600123
124 # If we have local layers then we don't need clone them
125 # For local layers giturl will be empty
126 if not layer.giturl:
127 nongitlayerlist.append(layer.layer_version.layer.local_source_dir)
128 continue
129
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 if not (layer.giturl, layer.commit) in gitrepos:
131 gitrepos[(layer.giturl, layer.commit)] = []
132 gitrepos[(layer.giturl, layer.commit)].append( (layer.name, layer.dirpath) )
133
134
135 logger.debug("localhostbecontroller, our git repos are %s" % pformat(gitrepos))
136
137
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500138 # 2. Note for future use if the current source directory is a
139 # checked-out git repos that could match a layer's vcs_url and therefore
140 # be used to speed up cloning (rather than fetching it again).
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141
142 cached_layers = {}
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500143
144 try:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145 for remotes in self._shellcmd("git remote -v", self.be.sourcedir,env=git_env).split("\n"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146 try:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500147 remote = remotes.split("\t")[1].split(" ")[0]
148 if remote not in cached_layers:
149 cached_layers[remote] = self.be.sourcedir
150 except IndexError:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 pass
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500152 except ShellCmdException:
153 # ignore any errors in collecting git remotes this is an optional
154 # step
155 pass
156
157 logger.info("Using pre-checked out source for layer %s", cached_layers)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159 # 3. checkout the repositories
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500160 clone_count=0
161 clone_total=len(gitrepos.keys())
162 self.setCloneStatus(bitbake,'Started',clone_total,clone_count)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163 for giturl, commit in gitrepos.keys():
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164 self.setCloneStatus(bitbake,'progress',clone_total,clone_count)
165 clone_count += 1
166
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167 localdirname = os.path.join(self.be.sourcedir, self.getGitCloneDirectory(giturl, commit))
168 logger.debug("localhostbecontroller: giturl %s:%s checking out in current directory %s" % (giturl, commit, localdirname))
169
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170 # see if our directory is a git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171 if os.path.exists(localdirname):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600172 try:
173 localremotes = self._shellcmd("git remote -v",
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500174 localdirname,env=git_env)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600175 if not giturl in localremotes and commit != 'HEAD':
176 raise BuildSetupException("Existing git repository at %s, but with different remotes ('%s', expected '%s'). Toaster will not continue out of fear of damaging something." % (localdirname, ", ".join(localremotes.split("\n")), giturl))
177 except ShellCmdException:
178 # our localdirname might not be a git repository
179 #- that's fine
180 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181 else:
182 if giturl in cached_layers:
183 logger.debug("localhostbecontroller git-copying %s to %s" % (cached_layers[giturl], localdirname))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500184 self._shellcmd("git clone \"%s\" \"%s\"" % (cached_layers[giturl], localdirname),env=git_env)
185 self._shellcmd("git remote remove origin", localdirname,env=git_env)
186 self._shellcmd("git remote add origin \"%s\"" % giturl, localdirname,env=git_env)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 else:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500188 logger.debug("localhostbecontroller: cloning %s in %s" % (giturl, localdirname))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500189 self._shellcmd('git clone "%s" "%s"' % (giturl, localdirname),env=git_env)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190
191 # branch magic name "HEAD" will inhibit checkout
192 if commit != "HEAD":
193 logger.debug("localhostbecontroller: checking out commit %s to %s " % (commit, localdirname))
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500194 ref = commit if re.match('^[a-fA-F0-9]+$', commit) else 'origin/%s' % commit
Brad Bishop316dfdd2018-06-25 12:45:53 -0400195 self._shellcmd('git fetch && git reset --hard "%s"' % ref, localdirname,env=git_env)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196
197 # take the localdirname as poky dir if we can find the oe-init-build-env
198 if self.pokydirname is None and os.path.exists(os.path.join(localdirname, "oe-init-build-env")):
199 logger.debug("localhostbecontroller: selected poky dir name %s" % localdirname)
200 self.pokydirname = localdirname
201
202 # make sure we have a working bitbake
203 if not os.path.exists(os.path.join(self.pokydirname, 'bitbake')):
204 logger.debug("localhostbecontroller: checking bitbake into the poky dirname %s " % self.pokydirname)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500205 self._shellcmd("git clone -b \"%s\" \"%s\" \"%s\" " % (bitbake.commit, bitbake.giturl, os.path.join(self.pokydirname, 'bitbake')),env=git_env)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206
207 # verify our repositories
208 for name, dirpath in gitrepos[(giturl, commit)]:
209 localdirpath = os.path.join(localdirname, dirpath)
210 logger.debug("localhostbecontroller: localdirpath expected '%s'" % localdirpath)
211 if not os.path.exists(localdirpath):
212 raise BuildSetupException("Cannot find layer git path '%s' in checked out repository '%s:%s'. Aborting." % (localdirpath, giturl, commit))
213
214 if name != "bitbake":
215 layerlist.append(localdirpath.rstrip("/"))
216
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500217 self.setCloneStatus(bitbake,'complete',clone_total,clone_count)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218 logger.debug("localhostbecontroller: current layer list %s " % pformat(layerlist))
219
Brad Bishop5dd7cbb2018-09-05 22:26:40 -0700220 # Resolve self.pokydirname if not resolved yet, consider the scenario
221 # where all layers are local, that's the else clause
222 if self.pokydirname is None:
223 if os.path.exists(os.path.join(self.be.sourcedir, "oe-init-build-env")):
224 logger.debug("localhostbecontroller: selected poky dir name %s" % self.be.sourcedir)
225 self.pokydirname = self.be.sourcedir
226 else:
227 # Alternatively, scan local layers for relative "oe-init-build-env" location
228 for layer in layers:
229 if os.path.exists(os.path.join(layer.layer_version.layer.local_source_dir,"..","oe-init-build-env")):
230 logger.debug("localhostbecontroller, setting pokydirname to %s" % (layer.layer_version.layer.local_source_dir))
231 self.pokydirname = os.path.join(layer.layer_version.layer.local_source_dir,"..")
232 break
233 else:
234 logger.error("pokydirname is not set, you will run into trouble!")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500235
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500236 # 5. create custom layer and add custom recipes to it
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500237 for target in targets:
238 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500239 customrecipe = CustomImageRecipe.objects.get(
240 name=target.target,
241 project=bitbake.req.project)
242
243 custom_layer_path = self.setup_custom_image_recipe(
244 customrecipe, layers)
245
246 if os.path.isdir(custom_layer_path):
247 layerlist.append(custom_layer_path)
248
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500249 except CustomImageRecipe.DoesNotExist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500250 continue # not a custom recipe, skip
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500251
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600252 layerlist.extend(nongitlayerlist)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500253 logger.debug("\n\nset layers gives this list %s" % pformat(layerlist))
254 self.islayerset = True
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500255 return layerlist
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500257 def setup_custom_image_recipe(self, customrecipe, layers):
258 """ Set up toaster-custom-images layer and recipe files """
259 layerpath = os.path.join(self.be.builddir,
260 CustomImageRecipe.LAYER_NAME)
261
262 # create directory structure
263 for name in ("conf", "recipes"):
264 path = os.path.join(layerpath, name)
265 if not os.path.isdir(path):
266 os.makedirs(path)
267
268 # create layer.conf
269 config = os.path.join(layerpath, "conf", "layer.conf")
270 if not os.path.isfile(config):
271 with open(config, "w") as conf:
272 conf.write('BBPATH .= ":${LAYERDIR}"\nBBFILES += "${LAYERDIR}/recipes/*.bb"\n')
273
274 # Update the Layer_Version dirpath that has our base_recipe in
275 # to be able to read the base recipe to then generate the
276 # custom recipe.
277 br_layer_base_recipe = layers.get(
278 layer_version=customrecipe.base_recipe.layer_version)
279
280 # If the layer is one that we've cloned we know where it lives
281 if br_layer_base_recipe.giturl and br_layer_base_recipe.commit:
282 layer_path = self.getGitCloneDirectory(
283 br_layer_base_recipe.giturl,
284 br_layer_base_recipe.commit)
285 # Otherwise it's a local layer
286 elif br_layer_base_recipe.local_source_dir:
287 layer_path = br_layer_base_recipe.local_source_dir
288 else:
289 logger.error("Unable to workout the dir path for the custom"
290 " image recipe")
291
292 br_layer_base_dirpath = os.path.join(
293 self.be.sourcedir,
294 layer_path,
295 customrecipe.base_recipe.layer_version.dirpath)
296
297 customrecipe.base_recipe.layer_version.dirpath = br_layer_base_dirpath
298
299 customrecipe.base_recipe.layer_version.save()
300
301 # create recipe
302 recipe_path = os.path.join(layerpath, "recipes", "%s.bb" %
303 customrecipe.name)
304 with open(recipe_path, "w") as recipef:
305 recipef.write(customrecipe.generate_recipe_file_contents())
306
307 # Update the layer and recipe objects
308 customrecipe.layer_version.dirpath = layerpath
309 customrecipe.layer_version.layer.local_source_dir = layerpath
310 customrecipe.layer_version.layer.save()
311 customrecipe.layer_version.save()
312
313 customrecipe.file_path = recipe_path
314 customrecipe.save()
315
316 return layerpath
317
318
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500319 def readServerLogFile(self):
320 return open(os.path.join(self.be.builddir, "toaster_server.log"), "r").read()
321
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323 def triggerBuild(self, bitbake, layers, variables, targets, brbe):
324 layers = self.setLayers(bitbake, layers, targets)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500326 # init build environment from the clone
327 builddir = '%s-toaster-%d' % (self.be.builddir, bitbake.req.project.id)
328 oe_init = os.path.join(self.pokydirname, 'oe-init-build-env')
329 # init build environment
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500330 try:
331 custom_script = ToasterSetting.objects.get(name="CUSTOM_BUILD_INIT_SCRIPT").value
332 custom_script = custom_script.replace("%BUILDDIR%" ,builddir)
333 self._shellcmd("bash -c 'source %s'" % (custom_script))
334 except ToasterSetting.DoesNotExist:
335 self._shellcmd("bash -c 'source %s %s'" % (oe_init, builddir),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500336 self.be.sourcedir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500337
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500338 # update bblayers.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 bblconfpath = os.path.join(builddir, "conf/toaster-bblayers.conf")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500340 with open(bblconfpath, 'w') as bblayers:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500341 bblayers.write('# line added by toaster build control\n'
342 'BBLAYERS = "%s"' % ' '.join(layers))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500344 # write configuration file
345 confpath = os.path.join(builddir, 'conf/toaster.conf')
346 with open(confpath, 'w') as conf:
347 for var in variables:
348 conf.write('%s="%s"\n' % (var.name, var.value))
349 conf.write('INHERIT+="toaster buildhistory"')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500350
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500351 # clean the Toaster to build environment
352 env_clean = 'unset BBPATH;' # clean BBPATH for <= YP-2.4.0
353
Brad Bishop5dd7cbb2018-09-05 22:26:40 -0700354 # run bitbake server from the clone if available
355 # otherwise pick it from the PATH
356 bitbake = os.path.join(self.pokydirname, 'bitbake', 'bin', 'bitbake')
357 if not os.path.exists(bitbake):
358 logger.info("Bitbake not available under %s, will try to use it from PATH" %
359 self.pokydirname)
360 for path in os.environ["PATH"].split(os.pathsep):
361 if os.path.exists(os.path.join(path, 'bitbake')):
362 bitbake = os.path.join(path, 'bitbake')
Awais Belal34261d62018-09-30 00:31:09 -0700363 logger.info("Found Bitbake at: %s" % path)
Brad Bishop5dd7cbb2018-09-05 22:26:40 -0700364 break
365 else:
366 logger.error("Looks like Bitbake is not available, please fix your environment")
367
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500368 # run bitbake server from the clone
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500369 toasterlayers = os.path.join(builddir,"conf/toaster-bblayers.conf")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500370 self._shellcmd('%s bash -c \"source %s %s; BITBAKE_UI="knotty" %s --read %s --read %s '
371 '--server-only -B 0.0.0.0:0\"' % (env_clean, oe_init,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500372 builddir, bitbake, confpath, toasterlayers), self.be.sourcedir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500374 # read port number from bitbake.lock
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500375 self.be.bbport = -1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500376 bblock = os.path.join(builddir, 'bitbake.lock')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500377 # allow 10 seconds for bb lock file to appear but also be populated
378 for lock_check in range(10):
379 if not os.path.exists(bblock):
380 logger.debug("localhostbecontroller: waiting for bblock file to appear")
381 time.sleep(1)
382 continue
383 if 10 < os.stat(bblock).st_size:
384 break
385 logger.debug("localhostbecontroller: waiting for bblock content to appear")
386 time.sleep(1)
387 else:
388 raise BuildSetupException("Cannot find bitbake server lock file '%s'. Aborting." % bblock)
389
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500390 with open(bblock) as fplock:
391 for line in fplock:
392 if ":" in line:
393 self.be.bbport = line.split(":")[-1].strip()
394 logger.debug("localhostbecontroller: bitbake port %s", self.be.bbport)
395 break
396
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500397 if -1 == self.be.bbport:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500398 raise BuildSetupException("localhostbecontroller: can't read bitbake port from %s" % bblock)
399
400 self.be.bbaddress = "localhost"
401 self.be.bbstate = BuildEnvironment.SERVER_STARTED
402 self.be.lock = BuildEnvironment.LOCK_RUNNING
403 self.be.save()
404
405 bbtargets = ''
406 for target in targets:
407 task = target.task
408 if task:
409 if not task.startswith('do_'):
410 task = 'do_' + task
411 task = ':%s' % task
412 bbtargets += '%s%s ' % (target.target, task)
413
414 # run build with local bitbake. stop the server after the build.
415 log = os.path.join(builddir, 'toaster_ui.log')
416 local_bitbake = os.path.join(os.path.dirname(os.getenv('BBBASEDIR')),
417 'bitbake')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500418 self._shellcmd(['%s bash -c \"(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:%s" '
419 '%s %s -u toasterui --read %s --read %s --token="" >>%s 2>&1;'
420 'BITBAKE_UI="knotty" BBSERVER=0.0.0.0:%s %s -m)&\"' \
421 % (env_clean, brbe, self.be.bbport, local_bitbake, bbtargets, confpath, toasterlayers, log,
422 self.be.bbport, bitbake,)],
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500423 builddir, nowait=True)
424
425 logger.debug('localhostbecontroller: Build launched, exiting. '
426 'Follow build logs at %s' % log)