bbcontroller.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #
  2. # BitBake Toaster Implementation
  3. #
  4. # Copyright (C) 2014 Intel Corporation
  5. #
  6. # SPDX-License-Identifier: GPL-2.0-only
  7. #
  8. import os
  9. import sys
  10. import re
  11. from django.db import transaction
  12. from django.db.models import Q
  13. from bldcontrol.models import BuildEnvironment, BRLayer, BRVariable, BRTarget, BRBitbake
  14. # load Bitbake components
  15. path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
  16. sys.path.insert(0, path)
  17. class BitbakeController(object):
  18. """ This is the basic class that controlls a bitbake server.
  19. It is outside the scope of this class on how the server is started and aquired
  20. """
  21. def __init__(self, be):
  22. import bb.server.xmlrpcclient
  23. self.connection = bb.server.xmlrpcclient._create_server(be.bbaddress,
  24. int(be.bbport))[0]
  25. def _runCommand(self, command):
  26. result, error = self.connection.runCommand(command)
  27. if error:
  28. raise Exception(error)
  29. return result
  30. def disconnect(self):
  31. return self.connection.removeClient()
  32. def setVariable(self, name, value):
  33. return self._runCommand(["setVariable", name, value])
  34. def getVariable(self, name):
  35. return self._runCommand(["getVariable", name])
  36. def triggerEvent(self, event):
  37. return self._runCommand(["triggerEvent", event])
  38. def build(self, targets, task = None):
  39. if task is None:
  40. task = "build"
  41. return self._runCommand(["buildTargets", targets, task])
  42. def forceShutDown(self):
  43. return self._runCommand(["stateForceShutdown"])
  44. def getBuildEnvironmentController(**kwargs):
  45. """ Gets you a BuildEnvironmentController that encapsulates a build environment,
  46. based on the query dictionary sent in.
  47. This is used to retrieve, for example, the currently running BE from inside
  48. the toaster UI, or find a new BE to start a new build in it.
  49. The return object MUST always be a BuildEnvironmentController.
  50. """
  51. from bldcontrol.localhostbecontroller import LocalhostBEController
  52. be = BuildEnvironment.objects.filter(Q(**kwargs))[0]
  53. if be.betype == BuildEnvironment.TYPE_LOCAL:
  54. return LocalhostBEController(be)
  55. else:
  56. raise Exception("FIXME: Implement BEC for type %s" % str(be.betype))
  57. class BuildEnvironmentController(object):
  58. """ BuildEnvironmentController (BEC) is the abstract class that defines the operations that MUST
  59. or SHOULD be supported by a Build Environment. It is used to establish the framework, and must
  60. not be instantiated directly by the user.
  61. Use the "getBuildEnvironmentController()" function to get a working BEC for your remote.
  62. How the BuildEnvironments are discovered is outside the scope of this class.
  63. You must derive this class to teach Toaster how to operate in your own infrastructure.
  64. We provide some specific BuildEnvironmentController classes that can be used either to
  65. directly set-up Toaster infrastructure, or as a model for your own infrastructure set:
  66. * Localhost controller will run the Toaster BE on the same account as the web server
  67. (current user if you are using the the Django development web server)
  68. on the local machine, with the "build/" directory under the "poky/" source checkout directory.
  69. Bash is expected to be available.
  70. """
  71. def __init__(self, be):
  72. """ Takes a BuildEnvironment object as parameter that points to the settings of the BE.
  73. """
  74. self.be = be
  75. self.connection = None
  76. def setLayers(self, bitbake, ls):
  77. """ Checks-out bitbake executor and layers from git repositories.
  78. Sets the layer variables in the config file, after validating local layer paths.
  79. bitbake must be a single BRBitbake instance
  80. The layer paths must be in a list of BRLayer object
  81. a word of attention: by convention, the first layer for any build will be poky!
  82. """
  83. raise NotImplementedError("FIXME: Must override setLayers")
  84. def getArtifact(self, path):
  85. """ This call returns an artifact identified by the 'path'. How 'path' is interpreted as
  86. up to the implementing BEC. The return MUST be a REST URL where a GET will actually return
  87. the content of the artifact, e.g. for use as a "download link" in a web UI.
  88. """
  89. raise NotImplementedError("Must return the REST URL of the artifact")
  90. def triggerBuild(self, bitbake, layers, variables, targets):
  91. raise NotImplementedError("Must override BE release")
  92. class ShellCmdException(Exception):
  93. pass
  94. class BuildSetupException(Exception):
  95. pass