toaster: don't start bitbake server
PATCH 1/38 toaster: don't start bitbake server
In reply to a message not in the archiveFrom: Ed Bartosh <[email protected]>
From now on toaster script will not run bitbake server. It will be started by runbuilds and stopped after the build.
--- bin/toaster | 67 ++++++------------------------------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-)
bin/toaster +6 -61
@@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -# Usage: source toaster [start|stop|restart-bitbake] +# Usage: source toaster [start|stop] # [webport=<port>] [noui] [noweb] # Helper function to kill a background toaster development server
@@ -95,7 +95,6 @@ stop_system() kill `cat ${BUILDDIR}/.toasterui.pid` 2>/dev/null rm ${BUILDDIR}/.toasterui.pid fi - stop_bitbake webserverKillAll # unset exported variables unset DATABASE_URL
@@ -106,31 +105,6 @@ stop_system() INSTOPSYSTEM=0 } -start_bitbake() { - unset BBSERVER - bitbake --read conf/toaster.conf --server-only -t xmlrpc -B 0.0.0.0:0 - if [ $? -ne 0 ]; then - echo "Bitbake server start failed" - return 1 - fi - export BBSERVER=0.0.0.0:-1 - export DATABASE_URL=`$MANAGE get-dburl` - # we start the TOASTERUI only if not inhibited - if [ $NOTOASTERUI -eq 0 ]; then - bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \ - >>${BUILDDIR}/toaster_ui.log 2>&1 \ - & echo $! >${BUILDDIR}/.toasterui.pid - fi - return 0 -} - -stop_bitbake() { - BBSERVER=0.0.0.0:-1 bitbake -m - unset BBSERVER - # force stop any misbehaving bitbake server - lsof -t bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill -} - verify_prereq() { # Verify Django version reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")
@@ -229,15 +203,6 @@ if [ `basename \"$0\"` = `basename \"${TOASTER}\"` ]; then return 1 fi -if [ "$1" = 'restart-bitbake' ] ; then - stop_bitbake - sleep 1 - start_bitbake - rc=$? - sleep 3 - return $rc -fi - verify_prereq || return 1 # We make sure we're running in the current shell and in a good environment
@@ -281,16 +246,6 @@ case $CMD in $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1 fi - # Make sure it's safe to start by checking bitbake lock - if [ -e $BUILDDIR/bitbake.lock ]; then - python -c "import fcntl; fcntl.flock(open(\"$BUILDDIR/bitbake.lock\"), fcntl.LOCK_EX|fcntl.LOCK_NB)" 2>/dev/null - if [ $? -ne 0 ] ; then - echo "Error: bitbake lock state error. File locks show that the system is on." 1>&2 - echo "Please wait for the current build to finish, stop and then start the system again." 1>&2 - return 3 - fi - fi - # kill Toaster web server if it's alive if [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then echo "Warning: bitbake appears to be dead, but the Toaster web server is running." 1>&2
@@ -308,22 +263,12 @@ case $CMD in echo "Failed ${CMD}." return 4 fi - start_bitbake - if [ $? -eq 0 ]; then - $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid - # set fail safe stop system on terminal exit - trap stop_system SIGHUP - echo "Successful ${CMD}." - return 0 - else - # failed start, do stop - stop_system - echo "Failed ${CMD}." - return 1 - fi - # stop system on terminal exit - set -o monitor + export DATABASE_URL=`$MANAGE get-dburl` + $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid + # set fail safe stop system on terminal exit trap stop_system SIGHUP + echo "Successful ${CMD}." + return 0 ;; stop ) stop_system
Signature · 1 line
2.1.4
PATCH 2/38 toaster: get rid of noui option
From: Ed Bartosh <[email protected]>
noui command line option doesn't makes sense anymore as toaster doesn't run bitbake. It should be safe to to remove it.
The purpose of this option was to skip running bitbake observer process. This was never used before as it's not possible to run toaster build without running observer.
--- bin/toaster | 4 ---- 1 file changed, 4 deletions(-)
bin/toaster +0 -4
@@ -175,15 +175,11 @@ fi # make sure that the toaster.sqlite file doesn't default to `pwd` like it currently does. export TOASTER_DIR=`pwd` -NOTOASTERUI=0 WEBSERVER=1 WEB_PORT="8000" unset CMD for param in $*; do case $param in - noui ) - NOTOASTERUI=1 - ;; noweb ) WEBSERVER=0 ;;
Signature · 1 line
2.1.4
PATCH 3/38 toaster: set BITBAKE_UI environment variable
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Set BITBAKE_UI variable to 'toastergui' for command line builds to use toasterui as a default ui module for bitbake.
--- bin/toaster | 2 ++ 1 file changed, 2 insertions(+)
bin/toaster +2 -0
@@ -100,6 +100,7 @@ stop_system() unset DATABASE_URL unset TOASTER_CONF unset TOASTER_DIR + unset BITBAKE_UI trap - SIGHUP #trap - SIGCHLD INSTOPSYSTEM=0
@@ -259,6 +260,7 @@ case $CMD in echo "Failed ${CMD}." return 4 fi + export BITBAKE_UI='toasterui' export DATABASE_URL=`$MANAGE get-dburl` $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid # set fail safe stop system on terminal exit
Signature · 1 line
2.1.4
PATCH 4/38 toasterui: add brbe parameter to buildinfohelper
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
In current toaster code BRBE(build request:build environment) value is passed from toaster to buildinfohelper through the 'SetBRBE' event.
Passing it through environment variable is easier as it doesn't involve rpc communication between toaster and bitbake server. It also eliminates the need in running bitbake observer process.
Added parameter 'brbe' to BuildInfoHelper.__init__ Used environment variable TOASTER_BRBE to set brbe for buildinfohelper object.
--- lib/bb/ui/buildinfohelper.py | 4 ++-- lib/bb/ui/toasterui.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
lib/bb/ui/buildinfohelper.py +2 -2
@@ -851,7 +851,7 @@ class BuildInfoHelper(object): # pylint: disable=bad-continuation # we do not follow the python conventions for continuation indentation due to long lines here - def __init__(self, server, has_build_history = False): + def __init__(self, server, has_build_history = False, brbe = None): self.internal_state = {} self.internal_state['taskdata'] = {} self.internal_state['targets'] = []
@@ -867,7 +867,7 @@ class BuildInfoHelper(object): # this is set for Toaster-triggered builds by localhostbecontroller # via toasterui - self.brbe = None + self.brbe = brbe self.project = None
lib/bb/ui/toasterui.py +2 -1
@@ -195,7 +195,8 @@ def main(server, eventHandler, params): taskfailures = [] first = True - buildinfohelper = BuildInfoHelper(server, build_history_enabled) + buildinfohelper = BuildInfoHelper(server, build_history_enabled, + os.getenv('TOASTER_BRBE')) # write our own log files into bitbake's log directory; # we're only interested in the path to the parent directory of
Signature · 1 line
2.1.4
PATCH 5/38 uievent: improve BBUIEventQueue code
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Return value of self.BBServer.registerEventHandler differs between jethro and master. To be able to build jethro toaster should be able to communicate with jethro bitbake server i.e. it must work with both old and new registerEventHandler call.
--- lib/bb/ui/uievent.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
lib/bb/ui/uievent.py +8 -2
@@ -24,7 +24,7 @@ server and queue them for the UI to process. This process must be used to avoid client/server deadlocks. """ -import socket, threading, pickle +import socket, threading, pickle, collections from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler class BBUIEventQueue:
@@ -51,7 +51,13 @@ class BBUIEventQueue: # giving up for count_tries in range(5): - self.EventHandle, error = self.BBServer.registerEventHandler(self.host, self.port) + ret = self.BBServer.registerEventHandler(self.host, self.port) + + if isinstance(ret, collections.Iterable): + self.EventHandle, error = ret + else: + self.EventHandle = ret + error = "" if self.EventHandle != None: break
Signature · 1 line
2.1.4
PATCH 6/38 buildinfohelper: improve handling of providermap
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
DepTreeGenerated event doesn't contain 'providermap' data in jethro. Modified buildinfohelper to handle events without this data. This should make it possible to handle jethro events coming from jethro bitbake server by the latest buildinfohelper.
--- lib/bb/ui/buildinfohelper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/bb/ui/buildinfohelper.py +1 -2
@@ -1246,7 +1246,6 @@ class BuildInfoHelper(object): assert 'layer-priorities' in event._depgraph assert 'pn' in event._depgraph assert 'tdepends' in event._depgraph - assert 'providermap' in event._depgraph errormsg = ""
@@ -1332,7 +1331,7 @@ class BuildInfoHelper(object): if dep in assume_provided: continue via = None - if dep in event._depgraph['providermap']: + if 'providermap' in event._depgraph and dep in event._depgraph['providermap']: deprecipe = event._depgraph['providermap'][dep][0] dependency = self.internal_state['recipes'][deprecipe] via = Provides.objects.get_or_create(name=dep,
Signature · 1 line
2.1.4
PATCH 7/38 toasterui: fix brbe reporting
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
buildinfohelper.brbe is lost when buildinfohelper is closed. This causes incorrect report of brbe when build is done.
Saved brbe attribute before closing buildinfohelper and used it to report correct brbe.
Got rid of useless and confusing 'ToasterUI build done 1' log message.
--- lib/bb/ui/toasterui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/ui/toasterui.py +3 -3
@@ -372,9 +372,9 @@ def main(server, eventHandler, params): # update the build info helper on BuildCompleted, not on CommandXXX buildinfohelper.update_build_information(event, errors, warnings, taskfailures) + + brbe = buildinfohelper.brbe buildinfohelper.close(errorcode) - # mark the log output; controllers may kill the toasterUI after seeing this log - logger.info("ToasterUI build done 1, brbe: %s", buildinfohelper.brbe ) # we start a new build info logger.debug("ToasterUI prepared for new build")
@@ -383,7 +383,7 @@ def main(server, eventHandler, params): taskfailures = [] buildinfohelper = BuildInfoHelper(server, build_history_enabled) - logger.info("ToasterUI build done 2") + logger.info("ToasterUI build done, brbe: %s", brbe) continue if isinstance(event, (bb.command.CommandCompleted,
Signature · 1 line
2.1.4
PATCH 8/38 toaster: remove startBBServer API
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
We still will have to run bitbake server, but it will be done different way and the code will be in triggerBuild function.
Removed startBBServer API from BuildEnvironmentController and LocalhostBEController classes.
--- lib/toaster/bldcontrol/bbcontroller.py | 9 ------- lib/toaster/bldcontrol/localhostbecontroller.py | 32 ------------------------- 2 files changed, 41 deletions(-)
lib/toaster/bldcontrol/bbcontroller.py +0 -9
@@ -127,14 +127,6 @@ class BuildEnvironmentController(object): bblayerconffile.write("# line added by toaster build control\nBBLAYERS = \"" + " ".join(layerlist) + "\"") bblayerconffile.close() - def startBBServer(self): - """ Starts a BB server with Toaster toasterui set up to record the builds, an no controlling UI. - After this method executes, self.be bbaddress/bbport MUST point to a running and free server, - and the bbstate MUST be updated to "started". - """ - raise NotImplementedError("FIXME: Must override in order to actually start the BB server") - - def setLayers(self, bitbake, ls): """ Checks-out bitbake executor and layers from git repositories. Sets the layer variables in the config file, after validating local layer paths.
@@ -151,7 +143,6 @@ class BuildEnvironmentController(object): starts if needed; or reconnects to the server if we can """ if not self.connection: - self.startBBServer() self.be.lock = BuildEnvironment.LOCK_RUNNING self.be.save()
lib/toaster/bldcontrol/localhostbecontroller.py +0 -32
@@ -70,38 +70,6 @@ class LocalhostBEController(BuildEnvironmentController): logger.debug("localhostbecontroller: shellcmd success") return out - def startBBServer(self): - assert self.pokydirname and os.path.exists(self.pokydirname) - assert self.islayerset - - # find our own toasterui listener/bitbake - from toaster.bldcontrol.management.commands.loadconf import _reduce_canon_path - - toaster = _reduce_canon_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../bin/toaster")) - assert os.path.exists(toaster) and os.path.isfile(toaster) - - # restart bitbake server and toastergui observer - self._shellcmd("bash -c 'source %s restart-bitbake'" % toaster, self.be.builddir) - logger.debug("localhostbecontroller: restarted bitbake server") - - # read port number from bitbake.lock - self.be.bbport = "" - bblock = os.path.join(self.be.builddir, 'bitbake.lock') - if os.path.exists(bblock): - with open(bblock) as fplock: - for line in fplock: - if ":" in line: - self.be.bbport = line.split(":")[-1].strip() - logger.debug("localhostbecontroller: bitbake port %s", self.be.bbport) - break - - if not self.be.bbport: - raise BuildSetupException("localhostbecontroller: can't read bitbake port from %s" % bblock) - - self.be.bbaddress = "localhost" - self.be.bbstate = BuildEnvironment.SERVER_STARTED - self.be.save() - def getGitCloneDirectory(self, url, branch): """Construct unique clone directory name out of url and branch.""" if branch != "HEAD":
Signature · 1 line
2.1.4
PATCH 9/38 toaster: remove release API
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
This API is quite dangerous as it removes build directory. It's not used anywhere and most probably will not be used in future as toaster is going to have one build directory per project.
--- lib/toaster/bldcontrol/bbcontroller.py | 6 ------ lib/toaster/bldcontrol/localhostbecontroller.py | 6 ------ 2 files changed, 12 deletions(-)
lib/toaster/bldcontrol/bbcontroller.py +0 -6
@@ -163,12 +163,6 @@ class BuildEnvironmentController(object): """ raise NotImplementedError("Must return the REST URL of the artifact") - def release(self): - """ This stops the server and releases any resources. After this point, all resources - are un-available for further reference - """ - raise NotImplementedError("Must override BE release") - def triggerBuild(self, bitbake, layers, variables, targets): raise NotImplementedError("Must override BE release")
lib/toaster/bldcontrol/localhostbecontroller.py +0 -6
@@ -255,12 +255,6 @@ class LocalhostBEController(BuildEnvironmentController): def readServerLogFile(self): return open(os.path.join(self.be.builddir, "toaster_server.log"), "r").read() - def release(self): - assert self.be.sourcedir and os.path.exists(self.be.builddir) - import shutil - shutil.rmtree(os.path.join(self.be.sourcedir, "build")) - assert not os.path.exists(self.be.builddir) - def triggerBuild(self, bitbake, layers, variables, targets): # set up the build environment with the needed layers
Signature · 1 line
2.1.4
PATCH 10/38 toaster: add brbe parameter to triggerBuild
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Called triggerBuild with brbe parameter instead of adding TOASTER_BRBE variable to the database and fetching it in triggerBuild.
--- lib/toaster/bldcontrol/localhostbecontroller.py | 2 +- lib/toaster/bldcontrol/management/commands/runbuilds.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-)
lib/toaster/bldcontrol/localhostbecontroller.py +1 -1
@@ -256,7 +256,7 @@ class LocalhostBEController(BuildEnvironmentController): return open(os.path.join(self.be.builddir, "toaster_server.log"), "r").read() - def triggerBuild(self, bitbake, layers, variables, targets): + def triggerBuild(self, bitbake, layers, variables, targets, brbe): # set up the build environment with the needed layers self.setLayers(bitbake, layers, targets)
lib/toaster/bldcontrol/management/commands/runbuilds.py +2 -4
@@ -49,15 +49,13 @@ class Command(NoArgsCommand): logger.debug("runbuilds: starting build %s, environment %s" % (str(br).decode('utf-8'), bec.be)) - # write the build identification variable - BRVariable.objects.create(req = br, name="TOASTER_BRBE", value="%d:%d" % (br.pk, bec.be.pk)) - # let the build request know where it is being executed br.environment = bec.be br.save() # this triggers an async build - bec.triggerBuild(br.brbitbake, br.brlayer_set.all(), br.brvariable_set.all(), br.brtarget_set.all()) + bec.triggerBuild(br.brbitbake, br.brlayer_set.all(), br.brvariable_set.all(), + br.brtarget_set.all(), "%d:%d" % (br.pk, bec.be.pk)) except Exception as e: logger.error("runbuilds: Error launching build %s" % e)
Signature · 1 line
2.1.4
PATCH 11/38 toaster: modified setLayers API
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Removed updating of bblayers.conf. It will be done in runBuild method. Changed return value: return list of layers.
Removed _updateBBLayers method.
--- lib/toaster/bldcontrol/bbcontroller.py | 18 ------------------ lib/toaster/bldcontrol/localhostbecontroller.py | 9 +-------- 2 files changed, 1 insertion(+), 26 deletions(-)
lib/toaster/bldcontrol/bbcontroller.py +0 -18
@@ -109,24 +109,6 @@ class BuildEnvironmentController(object): self.be = be self.connection = None - @staticmethod - def _updateBBLayers(bblayerconf, layerlist): - conflines = open(bblayerconf, "r").readlines() - - bblayerconffile = open(bblayerconf, "w") - skip = 0 - for i in xrange(len(conflines)): - if skip > 0: - skip =- 1 - continue - if conflines[i].startswith("# line added by toaster"): - skip = 1 - else: - bblayerconffile.write(conflines[i]) - - bblayerconffile.write("# line added by toaster build control\nBBLAYERS = \"" + " ".join(layerlist) + "\"") - bblayerconffile.close() - def setLayers(self, bitbake, ls): """ Checks-out bitbake executor and layers from git repositories. Sets the layer variables in the config file, after validating local layer paths.
lib/toaster/bldcontrol/localhostbecontroller.py +1 -8
@@ -180,11 +180,6 @@ class LocalhostBEController(BuildEnvironmentController): logger.debug("localhostbecontroller: current layer list %s " % pformat(layerlist)) - # 4. update the bblayers.conf - bblayerconf = os.path.join(self.be.builddir, "conf/bblayers.conf") - if not os.path.exists(bblayerconf): - raise BuildSetupException("BE is not consistent: bblayers.conf file missing at %s" % bblayerconf) - # 5. create custom layer and add custom recipes to it layerpath = os.path.join(self.be.builddir, CustomImageRecipe.LAYER_NAME)
@@ -247,10 +242,8 @@ class LocalhostBEController(BuildEnvironmentController): if os.path.isdir(layerpath): layerlist.append(layerpath) - BuildEnvironmentController._updateBBLayers(bblayerconf, layerlist) - self.islayerset = True - return True + return layerlist def readServerLogFile(self): return open(os.path.join(self.be.builddir, "toaster_server.log"), "r").read()
Signature · 1 line
2.1.4
PATCH 12/38 toaster: reimplement triggerBuild
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Reimplemented triggerBuild method to support one build directory per project:
- start bitbake server from the cloned repository
- don't run observer
- run bitbake build directly instead of triggering it through xmlrpc
[YOCTO #7880]
[YOCTO #9058]
[YOCTO #8958]
--- lib/toaster/bldcontrol/localhostbecontroller.py | 102 ++++++++++++++++-------- 1 file changed, 67 insertions(+), 35 deletions(-)
lib/toaster/bldcontrol/localhostbecontroller.py +67 -35
@@ -250,44 +250,76 @@ class LocalhostBEController(BuildEnvironmentController): def triggerBuild(self, bitbake, layers, variables, targets, brbe): - # set up the build environment with the needed layers - self.setLayers(bitbake, layers, targets) + layers = self.setLayers(bitbake, layers, targets) + + # init build environment from the clone + builddir = '%s-toaster-%d' % (self.be.builddir, bitbake.req.project.id) + oe_init = os.path.join(self.pokydirname, 'oe-init-build-env') + # init build environment + self._shellcmd('source %s %s' % (oe_init, builddir), self.be.sourcedir) + + # update bblayers.conf + bblconfpath = os.path.join(builddir, "conf/bblayers.conf") + conflines = open(bblconfpath, "r").readlines() + skip = False + with open(bblconfpath, 'w') as bblayers: + for line in conflines: + if line.startswith("# line added by toaster"): + skip = True + continue + if skip: + skip = False + else: + bblayers.write(line) + + bblayers.write('# line added by toaster build control\n' + 'BBLAYERS = "%s"' % ' '.join(layers)) # write configuration file - filepath = os.path.join(self.be.builddir, "conf/toaster.conf") - with open(filepath, 'w') as conf: + confpath = os.path.join(builddir, 'conf/toaster.conf') + with open(confpath, 'w') as conf: for var in variables: conf.write('%s="%s"\n' % (var.name, var.value)) conf.write('INHERIT+="toaster buildhistory"') - # get the bb server running with the build req id and build env id - bbctrl = self.getBBController() - - # set variables; TOASTER_BRBE is not set on the server, as this - # causes events from command-line builds to be attached to the last - # Toaster-triggered build; instead, TOASTER_BRBE is fired as an event so - # that toasterui can set it on the buildinfohelper; - # see https://bugzilla.yoctoproject.org/show_bug.cgi?id=9021 - for var in variables: - if var.name == 'TOASTER_BRBE': - bbctrl.triggerEvent('bb.event.MetadataEvent("SetBRBE", "%s")' \ - % var.value) - else: - bbctrl.setVariable(var.name, var.value) - - # Add 'toaster' and 'buildhistory' to INHERIT variable - inherit = {item.strip() for item in bbctrl.getVariable('INHERIT').split()} - inherit = inherit.union(["toaster", "buildhistory"]) - bbctrl.setVariable('INHERIT', ' '.join(inherit)) - - # trigger the build command - task = reduce(lambda x, y: x if len(y)== 0 else y, map(lambda y: y.task, targets)) - if len(task) == 0: - task = None - - bbctrl.build(list(map(lambda x:x.target, targets)), task) - - logger.debug("localhostbecontroller: Build launched, exiting. Follow build logs at %s/toaster_ui.log" % self.be.builddir) - - # disconnect from the server - bbctrl.disconnect() + # run bitbake server from the clone + bitbake = os.path.join(self.pokydirname, 'bitbake', 'bin', 'bitbake') + self._shellcmd('source %s %s; BITBAKE_UI="" %s --read %s ' + '--server-only -t xmlrpc -B 0.0.0.0:0' % (oe_init, builddir, + bitbake, confpath), self.be.sourcedir) + + # read port number from bitbake.lock + self.be.bbport = "" + bblock = os.path.join(builddir, 'bitbake.lock') + with open(bblock) as fplock: + for line in fplock: + if ":" in line: + self.be.bbport = line.split(":")[-1].strip() + logger.debug("localhostbecontroller: bitbake port %s", self.be.bbport) + break + + if not self.be.bbport: + raise BuildSetupException("localhostbecontroller: can't read bitbake port from %s" % bblock) + + self.be.bbaddress = "localhost" + self.be.bbstate = BuildEnvironment.SERVER_STARTED + self.be.lock = BuildEnvironment.LOCK_RUNNING + self.be.save() + + bbtargets = '' + for target in targets: + task = target.task + if task: + if not task.startswith('do_'): + task = 'do_' + task + task = ':%s' % task + bbtargets += '%s%s ' % (target.target, task) + + # run build with local bitbake + log = os.path.join(builddir, 'toaster_ui.log') + self._shellcmd('TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' + '../bitbake/bin/bitbake %s -u toasterui ' + '>>%s 2>&1 &' % (brbe, bbtargets, log), builddir) + + logger.debug('localhostbecontroller: Build launched, exiting. ' + 'Follow build logs at %s' % log)
Signature · 1 line
2.1.4
PATCH 13/38 toaster: add new parameter to _shellcmd
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Added 'nowait' parameter to _shellcmd method to support running chain of commands in a subshell.
This is going to be used to stop bitbake server after the build.
--- lib/toaster/bldcontrol/localhostbecontroller.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/toaster/bldcontrol/localhostbecontroller.py +3 -1
@@ -51,12 +51,14 @@ class LocalhostBEController(BuildEnvironmentController): self.pokydirname = None self.islayerset = False - def _shellcmd(self, command, cwd = None): + def _shellcmd(self, command, cwd=None, nowait=False): if cwd is None: cwd = self.be.sourcedir logger.debug("lbc_shellcmmd: (%s) %s" % (cwd, command)) p = subprocess.Popen(command, cwd = cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if nowait: + return (out,err) = p.communicate() p.wait() if p.returncode:
Signature · 1 line
2.1.4
PATCH 14/38 toaster: stop bitbake server after the build
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Bitbake server is used only during the build. There is no need in keeping server running after the build.
Running bitbake -m in the subshell after the build should stop the server.
--- lib/toaster/bldcontrol/localhostbecontroller.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
lib/toaster/bldcontrol/localhostbecontroller.py +6 -4
@@ -317,11 +317,13 @@ class LocalhostBEController(BuildEnvironmentController): task = ':%s' % task bbtargets += '%s%s ' % (target.target, task) - # run build with local bitbake + # run build with local bitbake. stop the server after the build. log = os.path.join(builddir, 'toaster_ui.log') - self._shellcmd('TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' - '../bitbake/bin/bitbake %s -u toasterui ' - '>>%s 2>&1 &' % (brbe, bbtargets, log), builddir) + self._shellcmd(['(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' + '../bitbake/bin/bitbake %s -u toasterui >>%s 2>&1;' + 'BITBAKE_UI="" BBSERVER=0.0.0.0:-1 %s -m)&' \ + % (brbe, bbtargets, log, bitbake)], builddir, + nowait=True) logger.debug('localhostbecontroller: Build launched, exiting. ' 'Follow build logs at %s' % log)
Signature · 1 line
2.1.4
PATCH 15/38 toaster: update conf/local.conf
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Added 'INHERIT+="toaster buildhistory"' line to the conf/local conf when Toaster starts. It should make commandline builds to provide all required information to Toaster backend.
--- bin/toaster | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
bin/toaster +3 -3
@@ -252,9 +252,9 @@ case $CMD in fi # Create configuration file - conf=${BUILDDIR}/conf/toaster.conf - echo "# Created by toaster start script" > $conf - echo "INHERIT+=\"toaster buildhistory\"" >> $conf + conf=${BUILDDIR}/conf/local.conf + line='INHERIT+="toaster buildhistory"' + grep -q "$line" $conf || echo $line >> $conf if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then echo "Failed ${CMD}."
Signature · 1 line
2.1.4
PATCH 16/38 toaster: fix jethro build
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
The keys 'started', 'ended', 'cpu_time_user', 'disk_io_read' and 'disk_io_write' were added to the event recently, so they don't exist in the events generated by bitbake server from older releases.
Checking if task_to_update structure has these keys before using them should fix build of older releases.
--- lib/bb/ui/buildinfohelper.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
lib/bb/ui/buildinfohelper.py +10 -8
@@ -241,14 +241,16 @@ class ORMWrapper(object): recipe__name = recipe_name ) - task_to_update.started = self._timestamp_to_datetime(task_stats['started']) - task_to_update.ended = self._timestamp_to_datetime(task_stats['ended']) - task_to_update.elapsed_time = (task_stats['ended'] - task_stats['started']) - task_to_update.cpu_time_user = task_stats['cpu_time_user'] - task_to_update.cpu_time_system = task_stats['cpu_time_system'] - task_to_update.disk_io_read = task_stats['disk_io_read'] - task_to_update.disk_io_write = task_stats['disk_io_write'] - task_to_update.disk_io = task_stats['disk_io_read'] + task_stats['disk_io_write'] + if 'started' in task_stats and 'ended' in task_stats: + task_to_update.started = self._timestamp_to_datetime(task_stats['started']) + task_to_update.ended = self._timestamp_to_datetime(task_stats['ended']) + task_to_update.elapsed_time = (task_stats['ended'] - task_stats['started']) + task_to_update.cpu_time_user = task_stats.get('cpu_time_user') + task_to_update.cpu_time_system = task_stats.get('cpu_time_system') + if 'disk_io_read' in task_stats and 'disk_io_write' in task_stats: + task_to_update.disk_io_read = task_stats['disk_io_read'] + task_to_update.disk_io_write = task_stats['disk_io_write'] + task_to_update.disk_io = task_stats['disk_io_read'] + task_stats['disk_io_write'] task_to_update.save()
Signature · 1 line
2.1.4
PATCH 17/38 toaster: use bash explicitly
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
Toaster can't run builds on Ubuntu as default /bin/sh points to dash there. The reason is that oe-init-build-env can't be sourced under dash for various reasons. It can be fixed or work arounded, but it wouldn't fix builds for older releases. Explicitly using bash to start builds should fix the issue.
--- lib/toaster/bldcontrol/localhostbecontroller.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
lib/toaster/bldcontrol/localhostbecontroller.py +7 -6
@@ -258,7 +258,8 @@ class LocalhostBEController(BuildEnvironmentController): builddir = '%s-toaster-%d' % (self.be.builddir, bitbake.req.project.id) oe_init = os.path.join(self.pokydirname, 'oe-init-build-env') # init build environment - self._shellcmd('source %s %s' % (oe_init, builddir), self.be.sourcedir) + self._shellcmd("bash -c 'source %s %s'" % (oe_init, builddir), + self.be.sourcedir) # update bblayers.conf bblconfpath = os.path.join(builddir, "conf/bblayers.conf")
@@ -286,9 +287,9 @@ class LocalhostBEController(BuildEnvironmentController): # run bitbake server from the clone bitbake = os.path.join(self.pokydirname, 'bitbake', 'bin', 'bitbake') - self._shellcmd('source %s %s; BITBAKE_UI="" %s --read %s ' - '--server-only -t xmlrpc -B 0.0.0.0:0' % (oe_init, builddir, - bitbake, confpath), self.be.sourcedir) + self._shellcmd('bash -c \"source %s %s; BITBAKE_UI="" %s --read %s ' + '--server-only -t xmlrpc -B 0.0.0.0:0\"' % (oe_init, + builddir, bitbake, confpath), self.be.sourcedir) # read port number from bitbake.lock self.be.bbport = ""
@@ -319,9 +320,9 @@ class LocalhostBEController(BuildEnvironmentController): # run build with local bitbake. stop the server after the build. log = os.path.join(builddir, 'toaster_ui.log') - self._shellcmd(['(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' + self._shellcmd(['bash -c \"(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' '../bitbake/bin/bitbake %s -u toasterui >>%s 2>&1;' - 'BITBAKE_UI="" BBSERVER=0.0.0.0:-1 %s -m)&' \ + 'BITBAKE_UI="" BBSERVER=0.0.0.0:-1 %s -m)&\"' \ % (brbe, bbtargets, log, bitbake)], builddir, nowait=True)
Signature · 1 line
2.1.4
PATCH 18/38 toasterui: shutdown on BuildCompleted event
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
toasterui exits event loop on one of the following events:
CommandCompleted, CommandFailed or CommandExit. Unfortunately none of them come from bitbake when build fails. This is normai if toasterui runs in observer mode. However, if it's in build mode this causes toasterui to stuck in the infinite loop waiting for new events.
The only event we can rely on is BuildCompleted as it always comes from bitbake unlike 3 above mentioned events.
Modified the code to always shutdown toasterui in build mode on BuildCompleted event.
--- lib/bb/ui/toasterui.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
lib/bb/ui/toasterui.py +8 -5
@@ -377,11 +377,14 @@ def main(server, eventHandler, params): buildinfohelper.close(errorcode) # we start a new build info - logger.debug("ToasterUI prepared for new build") - errors = 0 - warnings = 0 - taskfailures = [] - buildinfohelper = BuildInfoHelper(server, build_history_enabled) + if params.observe_only: + logger.debug("ToasterUI prepared for new build") + errors = 0 + warnings = 0 + taskfailures = [] + buildinfohelper = BuildInfoHelper(server, build_history_enabled) + else: + main.shutdown = 1 logger.info("ToasterUI build done, brbe: %s", brbe) continue
Signature · 1 line
2.1.4
PATCH 19/38 toaster: bldcontrol Add forceShutDown function to BitbakeController
In reply to Michael WoodFrom: Sujith H <[email protected]>
Add forceShutDown function to BitbakeController class. This function provides a mechanism to cancel the build from toaster. An API which can be used safely to cancel build and hence shutdown running bitbake server.
[YOCTO #6787]
--- lib/toaster/bldcontrol/bbcontroller.py | 3 +++ 1 file changed, 3 insertions(+)
lib/toaster/bldcontrol/bbcontroller.py +3 -0
@@ -63,6 +63,9 @@ class BitbakeController(object): task = "build" return self._runCommand(["buildTargets", targets, task]) + def forceShutDown(self): + return self._runCommand(["stateForceShutdown"]) + def getBuildEnvironmentController(**kwargs):
Signature · 1 line
2.1.4
PATCH 20/38 toaster: Move xhr calls for starting and stopping builds
In reply to Michael WoodMove the backend xhr implementation of the build request changes into it's own file and out of the ToasterTable definition.
It used to live in the views.py but in a hope of starting to collate logical groups of views move this to a new file called api.
--- lib/toaster/toastergui/api.py | 74 ++++++++++++++++++++++++++++++++++++++++ lib/toaster/toastergui/tables.py | 43 +---------------------- lib/toaster/toastergui/urls.py | 5 +++ 3 files changed, 80 insertions(+), 42 deletions(-) create mode 100644 bitbake/lib/toaster/toastergui/api.py
lib/toaster/toastergui/api.py new file +74 -0
@@ -0,0 +1,74 @@ +# +# BitBake Toaster Implementation +# +# Copyright (C) 2016 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +# Temporary home for the UI's misc API + +from orm.models import Project, ProjectTarget +from bldcontrol.models import BuildRequest +from bldcontrol import bbcontroller +from django.http import HttpResponse, JsonResponse +from django.views.generic import View + + +class XhrBuildRequest(View): + + def get(self, request, *args, **kwargs): + return HttpResponse() + + def post(self, request, *args, **kwargs): + """ Process HTTP POSTs which make build requests """ + + project = Project.objects.get(pk=kwargs['pid']) + + if 'buildCancel' in request.POST: + for i in request.POST['buildCancel'].strip().split(" "): + try: + br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED) + br.state = BuildRequest.REQ_DELETED + br.save() + except BuildRequest.DoesNotExist: + pass + + if 'buildDelete' in request.POST: + for i in request.POST['buildDelete'].strip().split(" "): + try: + BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() + except BuildRequest.DoesNotExist: + pass + + if 'targets' in request.POST: + ProjectTarget.objects.filter(project = project).delete() + s = str(request.POST['targets']) + for t in s.translate(None, ";%|\"").split(" "): + if ":" in t: + target, task = t.split(":") + else: + target = t + task = "" + ProjectTarget.objects.create(project = project, + target = target, + task = task) + project.schedule_build() + + # redirect back to builds page so any new builds in progress etc. + # are visible + response = HttpResponse() + response.status_code = 302 + response['Location'] = request.build_absolute_uri() + return response
lib/toaster/toastergui/tables.py +1 -42
55 lines not on this page · raw message
lib/toaster/toastergui/urls.py +5 -0
@@ -22,6 +22,7 @@ from django.views.generic import RedirectView, TemplateView from django.http import HttpResponseBadRequest from toastergui import tables from toastergui import typeaheads +from toastergui import api urlpatterns = patterns('toastergui.views', # landing page
@@ -180,6 +181,10 @@ urlpatterns = patterns('toastergui.views', url(r'^xhr_customrecipe/', 'xhr_customrecipe', name='xhr_customrecipe'), + url(r'^xhr_buildrequest/project/(?P<pid>\d+)$', + api.XhrBuildRequest.as_view(), + name='xhr_buildrequest'), + # default redirection url(r'^$', RedirectView.as_view(url='landing', permanent=True)), )
Signature · 1 line
2.1.4
PATCH 21/38 toaster: xhr Update the implementation of the build cancellation request
In reply to Michael WoodUpdate the implementation of the backend api for cancelling builds with the new cancelling BuildRequest state and cancelled Build state. Also added some docstring about general usage.
Co-Author: Sujith H <[email protected]>
--- lib/toaster/toastergui/api.py | 54 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-)
lib/toaster/toastergui/api.py +45 -9
@@ -19,7 +19,7 @@ # Temporary home for the UI's misc API -from orm.models import Project, ProjectTarget +from orm.models import Project, ProjectTarget, Build from bldcontrol.models import BuildRequest from bldcontrol import bbcontroller from django.http import HttpResponse, JsonResponse
@@ -32,18 +32,54 @@ class XhrBuildRequest(View): return HttpResponse() def post(self, request, *args, **kwargs): - """ Process HTTP POSTs which make build requests """ + """ + Build control + + Entry point: /xhr_buildrequest/<project_id> + Method: POST + + Args: + id: id of build to change + buildCancel = build_request_id ... + buildDelete = id ... + targets = recipe_name ... + + Returns: + {"error": "ok"} + or + {"error": <error message>} + """ project = Project.objects.get(pk=kwargs['pid']) if 'buildCancel' in request.POST: for i in request.POST['buildCancel'].strip().split(" "): try: - br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED) - br.state = BuildRequest.REQ_DELETED + br = BuildRequest.objects.get(project=project, pk=i) + + try: + bbctrl = bbcontroller.BitbakeController(br.environment) + bbctrl.forceShutDown() + except: + # We catch a bunch of exceptions here because + # this is where the server has not had time to start up + # and the build request or build is in transit between + # processes. + # We can safely just set the build as cancelled + # already as it never got started + build = br.build + build.outcome = Build.CANCELLED + build.save() + + # We now hand over to the buildinfohelper to update the + # build state once we've finished cancelling + br.state = BuildRequest.REQ_CANCELLING br.save() + except BuildRequest.DoesNotExist: - pass + return JsonResponse({'error':'No such build id %s' % i}) + + return JsonResponse({'error': 'ok'}) if 'buildDelete' in request.POST: for i in request.POST['buildDelete'].strip().split(" "):
@@ -51,6 +87,7 @@ class XhrBuildRequest(View): BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() except BuildRequest.DoesNotExist: pass + return JsonResponse({'error': 'ok' }) if 'targets' in request.POST: ProjectTarget.objects.filter(project = project).delete()
@@ -66,9 +103,8 @@ class XhrBuildRequest(View): task = task) project.schedule_build() - # redirect back to builds page so any new builds in progress etc. - # are visible + return JsonResponse({'error': 'ok' }) + response = HttpResponse() - response.status_code = 302 - response['Location'] = request.build_absolute_uri() + response.status_code = 500 return response
Signature · 1 line
2.1.4
PATCH 22/38 toaster: libtoaster Update implementation of startABuild and cancelABuild
In reply to Michael WoodUpdate the implementation of startABuild and cancelAbuild to reflect changes to the backend api. We now have a dedicated endpoint to make calls into so add this url to libtoaster.ctx and allow passing null in as a url value to indicate that we want to use the current project
Also:
- Fix some documentation comments
- Add the convenience of passing in an array of targets to startABuild
--- lib/toaster/toastergui/static/js/customrecipe.js | 4 +-- lib/toaster/toastergui/static/js/layerBtn.js | 3 +- lib/toaster/toastergui/static/js/libtoaster.js | 41 ++++++++++++++--------- lib/toaster/toastergui/static/js/projectpage.js | 4 +-- lib/toaster/toastergui/static/js/projecttopbar.js | 6 ++-- lib/toaster/toastergui/static/js/recipedetails.js | 4 +-- lib/toaster/toastergui/templates/base.html | 1 + 7 files changed, 34 insertions(+), 29 deletions(-)
lib/toaster/toastergui/static/js/customrecipe.js +1 -3
@@ -267,9 +267,7 @@ function customRecipePageInit(ctx) { /* Trigger a build of your custom image */ $(".build-custom-image").click(function(){ - libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl, - libtoaster.ctx.projectId, - ctx.recipe.name, + libtoaster.startABuild(null, ctx.recipe.name, function(){ window.location.replace(libtoaster.ctx.projectBuildsUrl); });
lib/toaster/toastergui/static/js/layerBtn.js +1 -2
@@ -60,8 +60,7 @@ function layerBtnsInit() { e.preventDefault(); var recipe = $(this).data('recipe-name'); - libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl, - libtoaster.ctx.projectId, recipe, + libtoaster.startABuild(null, recipe, function(){ /* Success */ window.location.replace(libtoaster.ctx.projectBuildsUrl);
lib/toaster/toastergui/static/js/libtoaster.js +26 -15
75 lines not on this page · raw message
lib/toaster/toastergui/static/js/projectpage.js +1 -3
@@ -232,9 +232,7 @@ function projectPageInit(ctx) { toBuild = toBuild.trim(); - libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl, - libtoaster.ctx.projectId, - toBuild, + libtoaster.startABuild(null, toBuild, function(){ /* Build request started */ window.location.replace(libtoaster.ctx.projectBuildsUrl);
lib/toaster/toastergui/static/js/projecttopbar.js +3 -3
@@ -82,9 +82,9 @@ function projectTopBarInit(ctx) { selectedTarget = { name: newBuildTargetInput.val() }; /* Fire off the build */ - libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl, - null, selectedTarget.name, function(){ - window.location.replace(libtoaster.ctx.projectBuildsUrl); + libtoaster.startABuild(null, selectedTarget.name, + function(){ + window.location.replace(libtoaster.ctx.projectBuildsUrl); }, null); }); }
lib/toaster/toastergui/static/js/recipedetails.js +1 -3
@@ -42,9 +42,7 @@ function recipeDetailsPageInit(ctx){ /* Trigger a build of your custom image */ $(".build-recipe-btn").click(function(){ - libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl, - libtoaster.ctx.projectId, - ctx.recipe.name, + libtoaster.startABuild(null, ctx.recipe.name, function(){ window.location.replace(libtoaster.ctx.projectBuildsUrl); });
lib/toaster/toastergui/templates/base.html +1 -0
@@ -47,6 +47,7 @@ projectBuildsUrl: {% url 'projectbuilds' project.id as pburl %}{{pburl|json}}, xhrCustomRecipeUrl : "{% url 'xhr_customrecipe' %}", projectId : {{project.id}}, + xhrBuildRequestUrl: "{% url 'xhr_buildrequest' project.id %}", {% else %} projectId : undefined, projectPageUrl : undefined,
Signature · 1 line
2.1.4
PATCH 23/38 toaster: update BuildEnvironmentController and BitbakeController
In reply to Michael WoodFrom: Sujith H <[email protected]>
Remove getBBController function from BuildEnvironmentController. The constructor of BitbakeController is updated appropriately so that call can be made to connect to running server.
The call to startBBServer is removed from bbcontroller and handledin localhostbecontroller.
[YOCTO #6787]
--- lib/toaster/bldcontrol/bbcontroller.py | 26 ++++--------------------- lib/toaster/bldcontrol/localhostbecontroller.py | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-)
lib/toaster/bldcontrol/bbcontroller.py +4 -22
@@ -37,11 +37,12 @@ class BitbakeController(object): It is outside the scope of this class on how the server is started and aquired """ - def __init__(self, connection): - self.connection = connection + def __init__(self, be): + self.connection = bb.server.xmlrpc._create_server(be.bbaddress, + int(be.bbport))[0] def _runCommand(self, command): - result, error = self.connection.connection.runCommand(command) + result, error = self.connection.runCommand(command) if error: raise Exception(error) return result
@@ -122,25 +123,6 @@ class BuildEnvironmentController(object): """ raise NotImplementedError("FIXME: Must override setLayers") - - def getBBController(self): - """ returns a BitbakeController to an already started server; this is the point where the server - starts if needed; or reconnects to the server if we can - """ - if not self.connection: - self.be.lock = BuildEnvironment.LOCK_RUNNING - self.be.save() - - server = bb.server.xmlrpc.BitBakeXMLRPCClient() - server.initServer() - server.saveConnectionDetails("%s:%s" % (self.be.bbaddress, self.be.bbport)) - self.connection = server.establishConnection([]) - - self.be.bbtoken = self.connection.transport.connection_token - self.be.save() - - return BitbakeController(self.connection) - def getArtifact(self, path): """ This call returns an artifact identified by the 'path'. How 'path' is interpreted as up to the implementing BEC. The return MUST be a REST URL where a GET will actually return
lib/toaster/bldcontrol/localhostbecontroller.py +1 -1
@@ -32,7 +32,7 @@ import subprocess from toastermain import settings -from bbcontroller import BuildEnvironmentController, ShellCmdException, BuildSetupException +from bbcontroller import BuildEnvironmentController, ShellCmdException, BuildSetupException, BitbakeController import logging logger = logging.getLogger("toaster")
Signature · 1 line
2.1.4
PATCH 24/38 toaster: models Add cancelled state to build outcome
In reply to Michael WoodFrom: Sujith H <[email protected]>
A new state CANCELLED is introduced to, distinguish the state of build.
[YOCTO #6787]
--- .../orm/migrations/0006_add_cancelled_state.py | 19 +++++++++++++++++++ lib/toaster/orm/models.py | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 bitbake/lib/toaster/orm/migrations/0006_add_cancelled_state.py
lib/toaster/orm/migrations/0006_add_cancelled_state.py new file +19 -0
@@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orm', '0005_task_field_separation'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='outcome', + field=models.IntegerField(default=2, choices=[(0, b'Succeeded'), (1, b'Failed'), (2, b'In Progress'), (3, b'Cancelled')]), + ), + ]
lib/toaster/orm/models.py +6 -1
@@ -358,11 +358,13 @@ class Build(models.Model): SUCCEEDED = 0 FAILED = 1 IN_PROGRESS = 2 + CANCELLED = 3 BUILD_OUTCOME = ( (SUCCEEDED, 'Succeeded'), (FAILED, 'Failed'), (IN_PROGRESS, 'In Progress'), + (CANCELLED, 'Cancelled'), ) search_allowed_fields = ['machine', 'cooker_log_path', "target__target", "target__target_image_file__file_name"]
@@ -390,7 +392,10 @@ class Build(models.Model): if project: builds = builds.filter(project=project) - finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED) + finished_criteria = \ + Q(outcome=Build.SUCCEEDED) | \ + Q(outcome=Build.FAILED) | \ + Q(outcome=Build.CANCELLED) recent_builds = list(itertools.chain( builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"),
Signature · 1 line
2.1.4
PATCH 25/38 toaster: bldcontrol models Add a cancelling state the BuildRequest
In reply to Michael WoodTo accurately reflect the state of a build request we also need a cancelling state. This is set when we've started a build and then for whatever reason cancel it, cancelling is not instantaneous so we have this state to indicate that a cancel is in progress.
Also add a state transition guard. As the state of a BuildRequest can currently be modified by three processes; Toastergui, Runbuilds/bldcontrol and the buildinofhelper we cannot say for sure which process will be running at the time of cancellation so in order to avoid one of these processes making an incorrect transition only allow transitions of state to increase.
e.g. CREATED -> QUEUED -> INPROGRESS
And to ignore such requested changes such as
INPROGRESS -> CREATED
--- .../migrations/0003_add_cancelling_state.py | 19 +++++++++++++++ lib/toaster/bldcontrol/models.py | 27 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py
lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py new file +19 -0
@@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bldcontrol', '0002_auto_20160120_1250'), + ] + + operations = [ + migrations.AlterField( + model_name='buildrequest', + name='state', + field=models.IntegerField(default=0, choices=[(0, b'created'), (1, b'queued'), (2, b'in progress'), (3, b'completed'), (4, b'failed'), (5, b'deleted'), (6, b'cancelling'), (7, b'archive')]), + ), + ]
lib/toaster/bldcontrol/models.py +26 -1
@@ -4,6 +4,8 @@ from django.core.validators import MaxValueValidator, MinValueValidator from django.utils.encoding import force_bytes from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version +import logging +logger = logging.getLogger("toaster") # a BuildEnvironment is the equivalent of the "build/" directory on the localhost class BuildEnvironment(models.Model): SERVER_STOPPED = 0
@@ -64,7 +66,8 @@ class BuildRequest(models.Model): REQ_COMPLETED = 3 REQ_FAILED = 4 REQ_DELETED = 5 - REQ_ARCHIVE = 6 + REQ_CANCELLING = 6 + REQ_ARCHIVE = 7 REQUEST_STATE = ( (REQ_CREATED, "created"),
@@ -73,6 +76,7 @@ class BuildRequest(models.Model): (REQ_COMPLETED, "completed"), (REQ_FAILED, "failed"), (REQ_DELETED, "deleted"), + (REQ_CANCELLING, "cancelling"), (REQ_ARCHIVE, "archive"), )
@@ -85,6 +89,27 @@ class BuildRequest(models.Model): created = models.DateTimeField(auto_now_add = True) updated = models.DateTimeField(auto_now = True) + def __init__(self, *args, **kwargs): + super(BuildRequest, self).__init__(*args, **kwargs) + # Save the old state incase it's about to be modified + self.old_state = self.state + + def save(self, *args, **kwargs): + # Check that the state we're trying to set is not going backwards + # e.g. from REQ_FAILED to REQ_INPROGRESS + if self.old_state != self.state and self.old_state > self.state: + logger.warn("Invalid state change requested: " + "Cannot go from %s to %s - ignoring request" % + (BuildRequest.REQUEST_STATE[self.old_state][1], + BuildRequest.REQUEST_STATE[self.state][1]) + ) + # Set property back to the old value + self.state = self.old_state + return + + super(BuildRequest, self).save(*args, **kwargs) + + def get_duration(self): return (self.updated - self.created).total_seconds()
Signature · 1 line
2.1.4
PATCH 26/38 buildinfohelper: Add handler for cancelling a build
In reply to Michael WoodWhen a build is cancelled the build (action) is complete if it has been caused the request being cancelled then update the build outcome accordingly.
--- lib/bb/ui/buildinfohelper.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
lib/bb/ui/buildinfohelper.py +18 -1
@@ -218,6 +218,15 @@ class ORMWrapper(object): assert isinstance(errors, int) assert isinstance(warnings, int) + if build.outcome == Build.CANCELLED: + return + try: + if build.buildrequest.state == BuildRequest.REQ_CANCELLING: + return + except AttributeError: + # We may not have a buildrequest if this is a command line build + pass + outcome = Build.SUCCEEDED if errors or taskfailures: outcome = Build.FAILED
@@ -1407,9 +1416,17 @@ class BuildInfoHelper(object): be.lock = BuildEnvironment.LOCK_LOCK be.save() br = BuildRequest.objects.get(pk = br_id) + + # if we're 'done' because we got cancelled update the build outcome + if br.state == BuildRequest.REQ_CANCELLING: + logger.info("Build cancelled") + br.build.outcome = Build.CANCELLED + br.build.save() + errorcode = 0 + if errorcode == 0: # request archival of the project artifacts - br.state = BuildRequest.REQ_ARCHIVE + br.state = BuildRequest.REQ_COMPLETED else: br.state = BuildRequest.REQ_FAILED br.save()
Signature · 1 line
2.1.4
PATCH 27/38 toaster: tables BuildsTable exclude cancelled builds
In reply to Michael WoodFrom: Sujith H <[email protected]>
Exclude cancelled builds from showing in the builds table
[YOCTO #6787]
--- lib/toaster/toastergui/tables.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/toaster/toastergui/tables.py +3 -2
@@ -1086,8 +1086,9 @@ class BuildsTable(ToasterTable): """ queryset = self.get_builds() - # don't include in progress builds - queryset = queryset.exclude(outcome=Build.IN_PROGRESS) + # Don't include in progress builds pr cancelled builds + queryset = queryset.exclude(Q(outcome=Build.IN_PROGRESS) | + Q(outcome=Build.CANCELLED)) # sort queryset = queryset.order_by(self.default_orderby)
Signature · 1 line
2.1.4
PATCH 28/38 toaster: mrb_section template Add build cancel button
In reply to Michael WoodAdd the cancel build button to the mrb section template and add the event handlers to cancelABuild.
Also clean up the calls to startABuild to use the updated libtoaster methods and to make the code consistent with it's cancelABuild counterpart.
Co-Author: Sujith H <[email protected]>
--- lib/toaster/toastergui/static/js/mrbsection.js | 95 ++++++++++++++ lib/toaster/toastergui/templates/mrb_section.html | 148 ++++++++-------------- 2 files changed, 149 insertions(+), 94 deletions(-) create mode 100644 bitbake/lib/toaster/toastergui/static/js/mrbsection.js
lib/toaster/toastergui/static/js/mrbsection.js new file +95 -0
@@ -0,0 +1,95 @@ + +function mrbSectionInit(ctx){ + + var projectBuilds; + + if (ctx.mrbType === 'project') + projectBuilds = true; + + $(".cancel-build-btn").click(function(e){ + e.preventDefault(); + + var url = $(this).data('request-url'); + var buildReqIds = $(this).data('buildrequest-id'); + var banner = $(this).parents(".alert"); + + banner.find(".progress-info").fadeOut().promise().done(function(){ + $("#cancelling-msg-" + buildReqIds).show(); + console.log("cancel build"); + libtoaster.cancelABuild(url, buildReqIds, function(){ + if (projectBuilds == false){ + /* the all builds page is not 'self updating' like thei + * project Builds + */ + window.location.reload(); + } + }, null); + }); + }); + + $(".run-again-btn").click(function(e){ + e.preventDefault(); + + var url = $(this).data('request-url'); + var target = $(this).data('target'); + + libtoaster.startABuild(url, target, function(){ + window.location.reload(); + }, null); + }); + + + var progressTimer; + + if (projectBuilds === true){ + progressTimer = window.setInterval(function() { + libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, + function(prjInfo){ + /* These two are needed because a build can be 100% and still + * in progress due to the fact that the % done is updated at the + * start of a task so it can be doing the last task at 100% + */ + var inProgress = 0; + var allPercentDone = 0; + if (prjInfo.builds.length === 0) + return + + for (var i in prjInfo.builds){ + var build = prjInfo.builds[i]; + + if (build.outcome === "In Progress" || + $(".progress .bar").length > 0){ + /* Update the build progress */ + var percentDone; + + if (build.outcome !== "In Progress"){ + /* We have to ignore the value when it's Succeeded because it + * goes back to 0 + */ + percentDone = 100; + } else { + percentDone = build.percentDone; + inProgress++; + } + + $("#build-pc-done-" + build.id).text(percentDone); + $("#build-pc-done-title-" + build.id).attr("title", percentDone); + $("#build-pc-done-bar-" + build.id).css("width", + String(percentDone) + "%"); + + allPercentDone += percentDone; + } + } + + if (allPercentDone === (100 * prjInfo.builds.length) && !inProgress) + window.location.reload(); + + /* Our progress bar is not still showing so shutdown the polling. */ + if ($(".progress .bar").length === 0) + window.clearInterval(progressTimer); + + }); + }, 1500); + } +} +
lib/toaster/toastergui/templates/mrb_section.html +54 -94
177 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 29/38 toaster: models Exclude the CANCELLED builds from get_number_of_builds
In reply to Michael WoodDon't count CANCELLED builds when returning the number of builds.
--- lib/toaster/orm/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/toaster/orm/models.py +4 -1
@@ -197,7 +197,10 @@ class Project(models.Model): def get_number_of_builds(self): """Return the number of builds which have ended""" - return self.build_set.filter(~Q(outcome=Build.IN_PROGRESS)).count() + return self.build_set.exclude( + Q(outcome=Build.IN_PROGRESS) | + Q(outcome=Build.CANCELLED) + ).count() def get_last_build_id(self): try:
Signature · 1 line
2.1.4
PATCH 30/38 toaster: runbuilds Make runbuilds aware of the build CANCELLED state
In reply to Michael WoodAdd handlers to make sure we remove the BuildEnvironment LOCK when we have cancelled a build.
--- .../bldcontrol/management/commands/runbuilds.py | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
lib/toaster/bldcontrol/management/commands/runbuilds.py +22 -4
@@ -1,5 +1,7 @@ from django.core.management.base import NoArgsCommand, CommandError from django.db import transaction +from django.db.models import Q + from orm.models import Build, ToasterSetting, LogMessage, Target from bldcontrol.bbcontroller import getBuildEnvironmentController, ShellCmdException, BuildSetupException from bldcontrol.models import BuildRequest, BuildEnvironment, BRError, BRVariable
@@ -86,13 +88,20 @@ class Command(NoArgsCommand): def cleanup(self): from django.utils import timezone from datetime import timedelta - # environments locked for more than 30 seconds - they should be unlocked - BuildEnvironment.objects.filter(buildrequest__state__in=[BuildRequest.REQ_FAILED, BuildRequest.REQ_COMPLETED]).filter(lock=BuildEnvironment.LOCK_LOCK).filter(updated__lt = timezone.now() - timedelta(seconds = 30)).update(lock = BuildEnvironment.LOCK_FREE) - - # update all Builds that failed to start for br in BuildRequest.objects.filter(state = BuildRequest.REQ_FAILED, build__outcome = Build.IN_PROGRESS): + # environments locked for more than 30 seconds + # they should be unlocked + BuildEnvironment.objects.filter( + Q(buildrequest__state__in=[BuildRequest.REQ_FAILED, + BuildRequest.REQ_COMPLETED, + BuildRequest.REQ_CANCELLING]) & + Q(lock=BuildEnvironment.LOCK_LOCK) & + Q(updated__lt=timezone.now() - timedelta(seconds = 30)) + ).update(lock=BuildEnvironment.LOCK_FREE) + + # transpose the launch errors in ToasterExceptions br.build.outcome = Build.FAILED for brerror in br.brerror_set.all():
@@ -125,6 +134,15 @@ class Command(NoArgsCommand): br.build.save() pass + # Make sure the LOCK is removed for builds which have been fully + # cancelled + for br in BuildRequest.objects.filter( + Q(build__outcome=Build.CANCELLED) & + Q(state=BuildRequest.REQ_CANCELLING) & + ~Q(environment=None)): + br.environment.lock = BuildEnvironment.LOCK_FREE + br.environment.save() + def handle_noargs(self, **options): while True:
Signature · 1 line
2.1.4
PATCH 31/38 toaster: runbuilds Clean up runbuilds
In reply to Michael Wood- Organise the imports into logical groups
- Fix 80 col wrapping
- Remove catch all exceptions
- Log to the toaster log
- Use QuerySet functions such as .first() and Q()
--- .../bldcontrol/management/commands/runbuilds.py | 81 ++++++++++++++-------- 1 file changed, 52 insertions(+), 29 deletions(-)
lib/toaster/bldcontrol/management/commands/runbuilds.py +52 -29
@@ -2,18 +2,25 @@ from django.core.management.base import NoArgsCommand, CommandError from django.db import transaction from django.db.models import Q +from bldcontrol.bbcontroller import getBuildEnvironmentController +from bldcontrol.bbcontroller import ShellCmdException, BuildSetupException +from bldcontrol.models import BuildRequest, BuildEnvironment +from bldcontrol.models import BRError, BRVariable + from orm.models import Build, ToasterSetting, LogMessage, Target -from bldcontrol.bbcontroller import getBuildEnvironmentController, ShellCmdException, BuildSetupException -from bldcontrol.models import BuildRequest, BuildEnvironment, BRError, BRVariable + import os import logging import time +import sys +import traceback -logger = logging.getLogger("ToasterScheduler") +logger = logging.getLogger("toaster") class Command(NoArgsCommand): args = "" - help = "Schedules and executes build requests as possible. Does not return (interrupt with Ctrl-C)" + help = "Schedules and executes build requests as possible." + "Does not return (interrupt with Ctrl-C)" @transaction.atomic
@@ -25,21 +32,19 @@ class Command(NoArgsCommand): @transaction.atomic def _selectBuildRequest(self): - br = BuildRequest.objects.filter(state = BuildRequest.REQ_QUEUED).order_by('pk')[0] - br.state = BuildRequest.REQ_INPROGRESS - br.save() + br = BuildRequest.objects.filter(state=BuildRequest.REQ_QUEUED).first() return br def schedule(self): - import traceback try: - br = None - try: - # select the build environment and the request to build - br = self._selectBuildRequest() - except IndexError as e: - #logger.debug("runbuilds: No build request") + # select the build environment and the request to build + br = self._selectBuildRequest() + if br: + br.state = BuildRequest.REQ_INPROGRESS + br.save() + else: return + try: bec = self._selectBuildEnvironment() except IndexError as e:
@@ -49,15 +54,17 @@ class Command(NoArgsCommand): logger.debug("runbuilds: No build env") return - logger.debug("runbuilds: starting build %s, environment %s" % (str(br).decode('utf-8'), bec.be)) + logger.debug("runbuilds: starting build %s, environment %s" % \ + (str(br).decode('utf-8'), bec.be)) # let the build request know where it is being executed br.environment = bec.be br.save() # this triggers an async build - bec.triggerBuild(br.brbitbake, br.brlayer_set.all(), br.brvariable_set.all(), - br.brtarget_set.all(), "%d:%d" % (br.pk, bec.be.pk)) + bec.triggerBuild(br.brbitbake, br.brlayer_set.all(), + br.brvariable_set.all(), br.brtarget_set.all(), + "%d:%d" % (br.pk, bec.be.pk)) except Exception as e: logger.error("runbuilds: Error launching build %s" % e)
@@ -88,9 +95,6 @@ class Command(NoArgsCommand): def cleanup(self): from django.utils import timezone from datetime import timedelta - # update all Builds that failed to start - - for br in BuildRequest.objects.filter(state = BuildRequest.REQ_FAILED, build__outcome = Build.IN_PROGRESS): # environments locked for more than 30 seconds # they should be unlocked BuildEnvironment.objects.filter(
@@ -102,22 +106,30 @@ class Command(NoArgsCommand): ).update(lock=BuildEnvironment.LOCK_FREE) + # update all Builds that were in progress and failed to start + for br in BuildRequest.objects.filter( + state=BuildRequest.REQ_FAILED, + build__outcome=Build.IN_PROGRESS): # transpose the launch errors in ToasterExceptions br.build.outcome = Build.FAILED for brerror in br.brerror_set.all(): logger.debug("Saving error %s" % brerror) - LogMessage.objects.create(build = br.build, level = LogMessage.EXCEPTION, message = brerror.errmsg) + LogMessage.objects.create(build=br.build, + level=LogMessage.EXCEPTION, + message=brerror.errmsg) br.build.save() - # we don't have a true build object here; hence, toasterui didn't have a change to release the BE lock + # we don't have a true build object here; hence, toasterui + # didn't have a change to release the BE lock br.environment.lock = BuildEnvironment.LOCK_FREE br.environment.save() - # update all BuildRequests without a build created for br in BuildRequest.objects.filter(build = None): - br.build = Build.objects.create(project = br.project, completed_on = br.updated, started_on = br.created) + br.build = Build.objects.create(project=br.project, + completed_on=br.updated, + started_on=br.created) br.build.outcome = Build.FAILED try: br.build.machine = br.brvariable_set.get(name='MACHINE').value
@@ -126,13 +138,16 @@ class Command(NoArgsCommand): br.save() # transpose target information for brtarget in br.brtarget_set.all(): - Target.objects.create(build=br.build, target=brtarget.target, task=brtarget.task) + Target.objects.create(build=br.build, + target=brtarget.target, + task=brtarget.task) # transpose the launch errors in ToasterExceptions for brerror in br.brerror_set.all(): - LogMessage.objects.create(build = br.build, level = LogMessage.EXCEPTION, message = brerror.errmsg) + LogMessage.objects.create(build=br.build, + level=LogMessage.EXCEPTION, + message=brerror.errmsg) br.build.save() - pass # Make sure the LOCK is removed for builds which have been fully # cancelled
@@ -148,9 +163,17 @@ class Command(NoArgsCommand): while True: try: self.cleanup() + except Exception as e: + logger.warn("runbuilds: cleanup exception %s" % str(e)) + + try: self.archive() + except Exception as e: + logger.warn("runbuilds: archive exception %s" % str(e)) + + try: self.schedule() - except: - pass + except Exception as e: + logger.warn("runbuilds: schedule exception %s" % str(e)) time.sleep(1)
Signature · 1 line
2.1.4
PATCH 32/38 toaster: use empty token
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
If client xmlrpc token is not provided in the command line, bitbake generates random token. Server token in --server-only mode is always empty. This doesn't allow clients with non-empty tokens to connect to the server. Specifying empty token should stop generation of random token and make it possible for clients to communicate with the server.
--- lib/toaster/bldcontrol/localhostbecontroller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/toaster/bldcontrol/localhostbecontroller.py +1 -1
@@ -321,7 +321,7 @@ class LocalhostBEController(BuildEnvironmentController): # run build with local bitbake. stop the server after the build. log = os.path.join(builddir, 'toaster_ui.log') self._shellcmd(['bash -c \"(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' - '../bitbake/bin/bitbake %s -u toasterui >>%s 2>&1;' + '../bitbake/bin/bitbake %s -u toasterui --token="" >>%s 2>&1;' 'BITBAKE_UI="" BBSERVER=0.0.0.0:-1 %s -m)&\"' \ % (brbe, bbtargets, log, bitbake)], builddir, nowait=True)
Signature · 1 line
2.1.4
PATCH 33/38 toaster: update view to support DL_DIR and SSTATE_DIR
In reply to Michael WoodFrom: Sujith H <[email protected]>
Update toaster's views.py to support DL_DIR and SSTATE_DIR for page projectconf.html. Removed DL_DIR and SSTATE_DIR from blacklist. Initial value of DL_DIR and SSTATE_DIR comes from BuildEnvironment.
[YOCTO #8422]
--- lib/toaster/toastergui/views.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
lib/toaster/toastergui/views.py +38 -2
@@ -45,6 +45,7 @@ from django.utils import formats from toastergui.templatetags.projecttags import json as jsonfilter from decimal import Decimal import json +import os from os.path import dirname from functools import wraps import itertools
@@ -1875,6 +1876,7 @@ def managedcontextprocessor(request): import toastermain.settings from orm.models import Project, ProjectLayer, ProjectTarget, ProjectVariable +from bldcontrol.models import BuildEnvironment # we have a set of functions if we're in managed mode, or # a default "page not available" simple functions for interactive mode
@@ -2187,6 +2189,10 @@ if True: except ProjectVariable.DoesNotExist: pass try: + return_data['dl_dir'] = ProjectVariable.objects.get(project = prj, name = "DL_DIR").value, + except ProjectVariable.DoesNotExist: + pass + try: return_data['fstypes'] = ProjectVariable.objects.get(project = prj, name = "IMAGE_FSTYPES").value, except ProjectVariable.DoesNotExist: pass
@@ -2198,6 +2204,10 @@ if True: return_data['package_classes'] = ProjectVariable.objects.get(project = prj, name = "PACKAGE_CLASSES").value, except ProjectVariable.DoesNotExist: pass + try: + return_data['sstate_dir'] = ProjectVariable.objects.get(project = prj, name = "SSTATE_DIR").value, + except ProjectVariable.DoesNotExist: + pass return HttpResponse(json.dumps( return_data ), content_type = "application/json")
@@ -2805,9 +2815,9 @@ if True: } vars_blacklist = { - 'DL_DR','PARALLEL_MAKE','BB_NUMBER_THREADS','SSTATE_DIR', + 'PARALLEL_MAKE','BB_NUMBER_THREADS', 'BB_DISKMON_DIRS','BB_NUMBER_THREADS','CVS_PROXY_HOST','CVS_PROXY_PORT', - 'DL_DIR','PARALLEL_MAKE','SSTATE_DIR','SSTATE_DIR','SSTATE_MIRRORS','TMPDIR', + 'PARALLEL_MAKE','SSTATE_MIRRORS','TMPDIR', 'all_proxy','ftp_proxy','http_proxy ','https_proxy' }
@@ -2845,6 +2855,19 @@ if True: except ProjectVariable.DoesNotExist: pass try: + if ProjectVariable.objects.get(project = prj, name = "DL_DIR").value == "${TOPDIR}/../downloads": + be = BuildEnvironment.objects.get(pk = str(1)) + dl_dir = os.path.join(dirname(be.builddir), "downloads") + context['dl_dir'] = dl_dir + pv, created = ProjectVariable.objects.get_or_create(project = prj, name = "DL_DIR") + pv.value = dl_dir + pv.save() + else: + context['dl_dir'] = ProjectVariable.objects.get(project = prj, name = "DL_DIR").value + context['dl_dir_defined'] = "1" + except ProjectVariable.DoesNotExist,BuildEnvironment.DoesNotExist: + pass + try: context['fstypes'] = ProjectVariable.objects.get(project = prj, name = "IMAGE_FSTYPES").value context['fstypes_defined'] = "1" except ProjectVariable.DoesNotExist:
@@ -2859,6 +2882,19 @@ if True: context['package_classes_defined'] = "1" except ProjectVariable.DoesNotExist: pass + try: + if ProjectVariable.objects.get(project = prj, name = "SSTATE_DIR").value == "${TOPDIR}/../sstate-cache": + be = BuildEnvironment.objects.get(pk = str(1)) + sstate_dir = os.path.join(dirname(be.builddir), "sstate-cache") + context['sstate_dir'] = sstate_dir + pv, created = ProjectVariable.objects.get_or_create(project = prj, name = "SSTATE_DIR") + pv.value = sstate_dir + pv.save() + else: + context['sstate_dir'] = ProjectVariable.objects.get(project = prj, name = "SSTATE_DIR").value + context['sstate_dir_defined'] = "1" + except ProjectVariable.DoesNotExist, BuildEnvironment.DoesNotExist: + pass return context
Signature · 1 line
2.1.4
PATCH 34/38 toaster: update projectconf.html for DL_DIR and SSTATE_DIR
In reply to Michael WoodFrom: Sujith H <[email protected]>
Modified the projectconf.html to include DL_DIR and SSTATE_DIR. Updated the script section in the html to handle the changes made by the user on DL_DIR and SSTATE_DIR. Included validation check for the folder names.
[YOCTO #8422]
--- lib/toaster/toastergui/templates/projectconf.html | 160 +++++++++++++++++++++- 1 file changed, 157 insertions(+), 3 deletions(-)
lib/toaster/toastergui/templates/projectconf.html +157 -3
@@ -31,6 +31,28 @@ </dd> {% endif %} + {% if dl_dir_defined %} + <dt> + <span class="js-config-var-name js-config-var-managed-name">DL_DIR</span> + <i class="icon-question-sign get-help" title="Absolute path to the directory used to store downloads required for your builds. By default, Toaster projects share the same downloads directory.<br /><a href='http://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html#var-DL_DIR' target='_blank'>Read more in the manual</a>"></i> + </dt> + <dd class="lead"> + <span id="dl_dir"{% if dl_dir %}{%else%} class="muted"{%endif%}>{% if dl_dir %}{{dl_dir}}{%else%}Not set{%endif%}</span> + <i class="icon-pencil" id="change-dl_dir-icon"></i> + <form id="change-dl_dir-form" style="display:none;"> + <div class="row-fluid"> + <span class="help-block span4">To set DL_DIR type the absolute path of the download folder.</span> + </div> + <div class="input-append" id="validate-dl_dir"> + <input type="text" class="input-xlarge" id="new-dl_dir" placeholder="Type absolute path of the DL_DIR folder"> + <button id="apply-change-dl_dir" class="btn" type="button">Save</button> + <button id="cancel-change-dl_dir" type="button" class="btn btn-link">Cancel</button> + </br><span class="help-block error" id="hintError-dl_dir">A valid directory cannot include spaces or any of these characters: . \ ? % * : | " " < ></span> + </div> + </form> + </dd> + {% endif %} + {% if fstypes_defined %} <dt> <span class="js-config-var-name js-config-var-managed-name">IMAGE_FSTYPES</span>
@@ -107,6 +129,29 @@ </form> </dd> {% endif %} + + {% if sstate_dir_defined %} + <dt> + <span class="js-config-var-name js-config-var-managed-name">SSTATE_DIR</span> + <i class="icon-question-sign get-help" title="Absolute path to the directory used to store shared state cache files. These files are reused across the builds, which makes the builds faster. By default, Toaster projects share the same cache directory.<br /><a href='http://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html#var-SSTATE_DIR' target='_blank'>Read more in the manual</a>"></i> + </dt> + <dd class="lead"> + <span id="sstate_dir"{% if sstate_dir %}{%else%} class="muted"{%endif%}>{% if sstate_dir %}{{sstate_dir}}{%else%}Not set{%endif%}</span> + <i class="icon-pencil" id="change-sstate_dir-icon"></i> + <form id="change-sstate_dir-form" style="display:none;"> + <div class="row-fluid"> + <span class="help-block span4">To set SSTATE_DIR type the absolute path of the download folder.</span> + </div> + <div class="input-append" id="validate-sstate_dir"> + <input type="text" class="input-xlarge" id="new-sstate_dir" placeholder="Type absolute path of the SSTATE_DIR folder"> + <span class="error">A valid directory name required</span> + <button id="apply-change-sstate_dir" class="btn" type="button">Save</button> + <button id="cancel-change-sstate_dir" type="button" class="btn btn-link">Cancel</button> + </br><p class="help-block error" id="hintError-sstate_dir">A valid directory cannot include spaces or any of these characters: . \ ? % * : | " " < ></span> + </div> + </form> + </dd> + {% endif %} </dl> <!-- <ul class="unstyled configuration-list" id="configvar-list"> -->
@@ -156,9 +201,7 @@ <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-BB_NUMBER_THREADS" target="_blank">BB_NUMBER_THREADS</a></code> <code>CVS_PROXY_HOST</code> <code>CVS_PROXY_PORT</code> - <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-DL_DIR" target="_blank">DL_DIR</a></code> <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-PARALLEL_MAKE" target="_blank">PARALLEL_MAKE</a></code> - <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-SSTATE_DIR" target="_blank">SSTATE_DIR</a></code> <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-SSTATE_MIRRORS" target="_blank">SSTATE_MIRRORS</a></code> <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-TMPDIR" target="_blank">TMPDIR</a></code></p> <p>Plus the following standard shell environment variables:</p>
@@ -501,6 +544,61 @@ }); {% endif %} + {% if dl_dir_defined %} + + // change DL_DIR variable + $('#change-dl_dir-icon').click(function() { + $('#hintError-dl_dir').hide(); + // preset the edit value + var current_val = $("span#dl_dir").text().trim(); + if (current_val == "Not set") { + current_val=""; + $("#apply-change-dl_dir").attr("disabled","disabled"); + } + $("input#new-dl_dir").val(current_val); + + $('#change-dl_dir-icon, #dl_dir').hide(); + $("#change-dl_dir-form").slideDown(); + }); + + $('#cancel-change-dl_dir').click(function(){ + $("#change-dl_dir-form").slideUp(function() { + $('#dl_dir, #change-dl_dir-icon').show(); + }); + }); + + $("#new-dl_dir").on('input', function(){ + if ($(this).val().trim().length == 0) { + $("#apply-change-dl_dir").attr("disabled","disabled"); + } + else { + var input = $(this); + var re = /^\/([^ <>\\|":\.%\?\*]+)$/; + var invalidDir = re.test(input.val()); + console.log(invalidDir); + if ( invalidDir ) { + $('#validate-dl_dir').removeClass('control-group error'); + $("#apply-change-dl_dir").removeAttr("disabled"); + $('#hintError-dl_dir').hide(); + } else { + $('#validate-dl_dir').addClass('control-group error'); + $("#apply-change-dl_dir").attr("disabled","disabled"); + $('#hintError-dl_dir').show(); + } + } + }); + + $('#apply-change-dl_dir').click(function(){ + var value = $('#new-dl_dir').val().trim(); + postEditAjaxRequest({"configvarChange" : 'DL_DIR:'+value}); + $('#dl_dir').text(value); + $('#dl_dir').removeClass('muted'); + $("#change-dl_dir-form").slideUp(function () { + $('#dl_dir, #change-dl_dir-icon').show(); + }); + }); + + {% endif %} {% if fstypes_defined %} // change IMAGE_FSTYPES variable
@@ -748,6 +846,62 @@ }); {% endif %} + {% if sstate_dir_defined %} + + // change SSTATE_DIR variable + $('#change-sstate_dir-icon').click(function() { + $('#hintError-sstate_dir').hide(); + // preset the edit value + var current_val = $("span#sstate_dir").text().trim(); + if (current_val == "Not set") { + current_val=""; + $("#apply-change-sstate_dir").attr("disabled","disabled"); + } + $("input#new-sstate_dir").val(current_val); + + $('#change-sstate_dir-icon, #sstate_dir').hide(); + $("#change-sstate_dir-form").slideDown(); + }); + + $('#cancel-change-sstate_dir').click(function(){ + $("#change-sstate_dir-form").slideUp(function() { + $('#sstate_dir, #change-sstate_dir-icon').show(); + }); + }); + + $("#new-sstate_dir").on('input', function(){ + if ($(this).val().trim().length == 0) { + $("#apply-change-sstate_dir").attr("disabled","disabled"); + } + else { + var input = $(this); + var re = /^\/([^ <>\\|":\.%\?\*]+)$/; + var invalidDir = re.test(input.val()); + console.log(invalidDir); + if ( invalidDir ) { + $('#validate-sstate_dir').removeClass('control-group error'); + $("#apply-change-sstate_dir").removeAttr("disabled"); + $('#hintError-sstate_dir').hide(); + } else { + $('#validate-sstate_dir').addClass('control-group error'); + $("#apply-change-sstate_dir").attr("disabled","disabled"); + $('#hintError-sstate_dir').show(); + } + } + }); + + $('#apply-change-sstate_dir').click(function(){ + var value = $('#new-sstate_dir').val().trim(); + postEditAjaxRequest({"configvarChange" : 'SSTATE_DIR:'+value}); + $('#sstate_dir').text(value); + $('#sstate_dir').removeClass('muted'); + $("#change-sstate_dir-form").slideUp(function () { + $('#sstate_dir, #change-sstate_dir-icon').show(); + }); + }); + + {% endif %} + // add new variable $("button#add-configvar-button").click( function (evt) { var variable = $("input#variable").val();
@@ -762,7 +916,7 @@ $(".save").attr("disabled","disabled"); // Reload page if admin-removed core managed value is manually added back in - if (0 <= " DISTRO IMAGE_FSTYPES IMAGE_INSTALL_append PACKAGE_CLASSES ".indexOf( " "+variable+" " )) { + if (0 <= " DISTRO DL_DIR IMAGE_FSTYPES IMAGE_INSTALL_append PACKAGE_CLASSES SSTATE_DIR ".indexOf( " "+variable+" " )) { // delayed reload to avoid race condition with postEditAjaxRequest do_reload=true; }
Signature · 1 line
2.1.4
PATCH 35/38 toaster: export BBBASEDIR variable
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
This variable will be used in localhost controller code to determine correct bitbake location, so it has to be exported.
--- bin/toaster | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
bin/toaster +2 -1
@@ -101,6 +101,7 @@ stop_system() unset TOASTER_CONF unset TOASTER_DIR unset BITBAKE_UI + unset BBBASEDIR trap - SIGHUP #trap - SIGCHLD INSTOPSYSTEM=0
@@ -131,7 +132,7 @@ else TOASTER=$0 fi -BBBASEDIR=`dirname $TOASTER`/.. +export BBBASEDIR=`dirname $TOASTER`/.. MANAGE=$BBBASEDIR/lib/toaster/manage.py OEROOT=`dirname $TOASTER`/../..
Signature · 1 line
2.1.4
PATCH 36/38 toaster: get bitbake location from BBBASEDIR
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
It was incorrectly assumed in the current code that bitbake is in ../bitbake/bin/ directory. It's not always the case. Using bitbake from $BBBASEDIR should be .
--- lib/toaster/bldcontrol/localhostbecontroller.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/toaster/bldcontrol/localhostbecontroller.py +5 -3
@@ -320,11 +320,13 @@ class LocalhostBEController(BuildEnvironmentController): # run build with local bitbake. stop the server after the build. log = os.path.join(builddir, 'toaster_ui.log') + local_bitbake = os.path.join(os.path.dirname(os.getenv('BBBASEDIR')), + 'bitbake') self._shellcmd(['bash -c \"(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:-1" ' - '../bitbake/bin/bitbake %s -u toasterui --token="" >>%s 2>&1;' + '%s %s -u toasterui --token="" >>%s 2>&1;' 'BITBAKE_UI="" BBSERVER=0.0.0.0:-1 %s -m)&\"' \ - % (brbe, bbtargets, log, bitbake)], builddir, - nowait=True) + % (brbe, local_bitbake, bbtargets, log, bitbake)], + builddir, nowait=True) logger.debug('localhostbecontroller: Build launched, exiting. ' 'Follow build logs at %s' % log)
Signature · 1 line
2.1.4
PATCH 37/38 buildinfohelper: fix KeyError
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
When bitbake doesn't need to build anything it still sends ImagePkgList event with empty 'pkgdata', 'imgdata' and 'filedata' fields. This causes crash in buildinfohelper code as it's assumed that above mentioned fields always have data keyed by build target:
ERROR: u'core-image-minimal'
Traceback (most recent call last):
File "toasterui.py", line 423, in main
buildinfohelper.store_target_package_data(event)
File "buildinfohelper.py", line 1218, in store_target_package_data
imgdata = BuildInfoHelper._get_data_from_event(event)['imgdata'][target.target]
KeyError: u'core-image-minimal'
Fixed this by using dict.get method with empty dictionary as default return value instead of trying to get value without checking if target key is in the data.
--- lib/bb/ui/buildinfohelper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bb/ui/buildinfohelper.py +2 -2
@@ -1233,8 +1233,8 @@ class BuildInfoHelper(object): for target in self.internal_state['targets']: if target.is_image: pkgdata = BuildInfoHelper._get_data_from_event(event)['pkgdata'] - imgdata = BuildInfoHelper._get_data_from_event(event)['imgdata'][target.target] - filedata = BuildInfoHelper._get_data_from_event(event)['filedata'][target.target] + imgdata = BuildInfoHelper._get_data_from_event(event)['imgdata'].get(target.target, {}) + filedata = BuildInfoHelper._get_data_from_event(event)['filedata'].get(target.target, {}) try: self.orm_wrapper.save_target_package_information(self.internal_state['build'], target, imgdata, pkgdata, self.internal_state['recipes'], built_package=True)
Signature · 1 line
2.1.4
PATCH 38/38 toasterui: update build in internal state
In reply to Michael WoodFrom: Ed Bartosh <[email protected]>
buildinfohelper stores current Build object in its internal state. Any changes to Build object will be lost if internal state is not updated as current buildinfohelper code saves Build object from internal state when build is completed.
This bug causes incorrect build state when build is cancelled. Updating internal state should fix it.
Note, that this commit updates internal state after status of the build is changed to Build.CANCELLED. There are several other places in the code where Build object is updated without updating internal state. They should be carefully analyzed and fixed.
--- lib/bb/ui/buildinfohelper.py | 1 + 1 file changed, 1 insertion(+)
lib/bb/ui/buildinfohelper.py +1 -0
@@ -1422,6 +1422,7 @@ class BuildInfoHelper(object): logger.info("Build cancelled") br.build.outcome = Build.CANCELLED br.build.save() + self.internal_state['build'] = br.build errorcode = 0 if errorcode == 0:
Signature · 1 line
2.1.4