summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-07-15 12:35:43 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-07-23 20:06:57 +0100
commit6cfb76fa8bd1c192e6a0524b7670e2172e5d8e26 (patch)
tree8210bd00ecda985d8498c3d4ebc41bf38fb65540
parent5ba68f32a86a20b3f3544903fea2a24f2e59afbf (diff)
downloadpoky-6cfb76fa8bd1c192e6a0524b7670e2172e5d8e26.tar.gz
bitbake: toaster: add fields for sourcedir and builddir paths
We add explicit absolute paths for a directory where the layer sources will be checked out (sourcedir) and where the build activities will take place. Adding minimal checking when starting the application in order to make sure that BuildEnvironment (BE) settings are usable. This check is ran by the toaster script at startup. Modify the localhost bbcontroller to use the BE settings instead of trying to self-configure on checked out sources. (Bitbake rev: d17500d3f73fdeeef5f11fb3773a65e927be3f02) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xbitbake/bin/toaster1
-rw-r--r--bitbake/lib/toaster/bldcontrol/bbcontroller.py51
-rw-r--r--bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py33
-rw-r--r--bitbake/lib/toaster/bldcontrol/migrations/0002_auto__add_field_buildenvironment_sourcedir__add_field_buildenvironment.py106
-rw-r--r--bitbake/lib/toaster/bldcontrol/models.py2
5 files changed, 167 insertions, 26 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 90cd982876..1f90362b1f 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -64,6 +64,7 @@ function webserverStartAll()
64 python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1 64 python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
65 fi 65 fi
66 python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol || retval=1 66 python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol || retval=1
67 python $BBBASEDIR/lib/toaster/manage.py checksettings || retval=1
67 68
68 if [ $retval -eq 0 ]; then 69 if [ $retval -eq 0 ]; then
69 python $BBBASEDIR/lib/toaster/manage.py runserver 0.0.0.0:8000 </dev/null >${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid 70 python $BBBASEDIR/lib/toaster/manage.py runserver 0.0.0.0:8000 </dev/null >${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid
diff --git a/bitbake/lib/toaster/bldcontrol/bbcontroller.py b/bitbake/lib/toaster/bldcontrol/bbcontroller.py
index d2b2a236bd..c3beba96f0 100644
--- a/bitbake/lib/toaster/bldcontrol/bbcontroller.py
+++ b/bitbake/lib/toaster/bldcontrol/bbcontroller.py
@@ -170,27 +170,16 @@ class LocalhostBEController(BuildEnvironmentController):
170 this controller manages the default build directory, 170 this controller manages the default build directory,
171 the server setup and system start and stop for the localhost-type build environment 171 the server setup and system start and stop for the localhost-type build environment
172 172
173 The address field is used as working directory; if not set, the build/ directory
174 is created
175 """ 173 """
174 from os.path import dirname as DN
176 175
177 def __init__(self, be): 176 def __init__(self, be):
178 super(LocalhostBEController, self).__init__(be) 177 super(LocalhostBEController, self).__init__(be)
179 from os.path import dirname as DN 178 from os.path import dirname as DN
180 self.cwd = DN(DN(DN(DN(DN(os.path.realpath(__file__))))))
181 if self.be.address is None or len(self.be.address) == 0:
182 self.be.address = "build"
183 self.be.save()
184 self.bwd = self.be.address
185 self.dburl = settings.getDATABASE_URL() 179 self.dburl = settings.getDATABASE_URL()
186 180
187 # transform relative paths to absolute ones
188 if not self.bwd.startswith("/"):
189 self.bwd = os.path.join(self.cwd, self.bwd)
190 self._createBE()
191
192 def _shellcmd(self, command): 181 def _shellcmd(self, command):
193 p = subprocess.Popen(command, cwd=self.cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 182 p = subprocess.Popen(command, cwd=self.be.sourcedir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
194 (out,err) = p.communicate() 183 (out,err) = p.communicate()
195 if p.returncode: 184 if p.returncode:
196 if len(err) == 0: 185 if len(err) == 0:
@@ -201,39 +190,49 @@ class LocalhostBEController(BuildEnvironmentController):
201 else: 190 else:
202 return out 191 return out
203 192
204 def _createBE(self): 193 def _createdirpath(self, path):
205 assert self.cwd and os.path.exists(self.cwd) 194 if not os.path.exists(DN(path)):
206 self._shellcmd("bash -c \"source %s/oe-init-build-env %s\"" % (self.cwd, self.bwd)) 195 self._createdirpath(DN(path))
196 if not os.path.exists(path):
197 os.mkdir(path, 0755)
198
199 def _startBE(self):
200 assert self.be.sourcedir and os.path.exists(self.be.sourcedir)
201 self._createdirpath(self.be.builddir)
202 self._shellcmd("bash -c \"source %s/oe-init-build-env %s\"" % (self.be.sourcedir, self.be.builddir))
207 203
208 def startBBServer(self): 204 def startBBServer(self):
209 assert self.cwd and os.path.exists(self.cwd) 205 assert self.be.sourcedir and os.path.exists(self.be.sourcedir)
210 print self._shellcmd("bash -c \"source %s/oe-init-build-env %s && DATABASE_URL=%s source toaster start noweb && sleep 1\"" % (self.cwd, self.bwd, self.dburl)) 206
207 self._startBE()
208
209 print self._shellcmd("bash -c \"source %s/oe-init-build-env %s && DATABASE_URL=%s source toaster start noweb && sleep 1\"" % (self.be.sourcedir, self.be.builddir, self.dburl))
211 # FIXME unfortunate sleep 1 - we need to make sure that bbserver is started and the toaster ui is connected 210 # FIXME unfortunate sleep 1 - we need to make sure that bbserver is started and the toaster ui is connected
212 # but since they start async without any return, we just wait a bit 211 # but since they start async without any return, we just wait a bit
213 print "Started server" 212 print "Started server"
214 assert self.cwd and os.path.exists(self.bwd) 213 assert self.be.sourcedir and os.path.exists(self.be.builddir)
215 self.be.bbaddress = "localhost" 214 self.be.bbaddress = "localhost"
216 self.be.bbport = "8200" 215 self.be.bbport = "8200"
217 self.be.bbstate = BuildEnvironment.SERVER_STARTED 216 self.be.bbstate = BuildEnvironment.SERVER_STARTED
218 self.be.save() 217 self.be.save()
219 218
220 def stopBBServer(self): 219 def stopBBServer(self):
221 assert self.cwd 220 assert self.be.sourcedir
222 print self._shellcmd("bash -c \"source %s/oe-init-build-env %s && %s source toaster stop\"" % 221 print self._shellcmd("bash -c \"source %s/oe-init-build-env %s && %s source toaster stop\"" %
223 (self.cwd, self.bwd, (lambda: "" if self.be.bbtoken is None else "BBTOKEN=%s" % self.be.bbtoken)())) 222 (self.be.sourcedir, self.be.builddir, (lambda: "" if self.be.bbtoken is None else "BBTOKEN=%s" % self.be.bbtoken)()))
224 self.be.bbstate = BuildEnvironment.SERVER_STOPPED 223 self.be.bbstate = BuildEnvironment.SERVER_STOPPED
225 self.be.save() 224 self.be.save()
226 print "Stopped server" 225 print "Stopped server"
227 226
228 def setLayers(self, layers): 227 def setLayers(self, layers):
229 assert self.cwd is not None 228 assert self.be.sourcedir is not None
230 layerconf = os.path.join(self.bwd, "conf/bblayers.conf") 229 layerconf = os.path.join(self.be.builddir, "conf/bblayers.conf")
231 if not os.path.exists(layerconf): 230 if not os.path.exists(layerconf):
232 raise Exception("BE is not consistent: bblayers.conf file missing at ", layerconf) 231 raise Exception("BE is not consistent: bblayers.conf file missing at ", layerconf)
233 return True 232 return True
234 233
235 def release(self): 234 def release(self):
236 assert self.cwd and os.path.exists(self.bwd) 235 assert self.be.sourcedir and os.path.exists(self.be.builddir)
237 import shutil 236 import shutil
238 shutil.rmtree(os.path.join(self.cwd, "build")) 237 shutil.rmtree(os.path.join(self.be.sourcedir, "build"))
239 assert not os.path.exists(self.bwd) 238 assert not os.path.exists(self.be.builddir)
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py b/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py
new file mode 100644
index 0000000000..0e8260e6c9
--- /dev/null
+++ b/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py
@@ -0,0 +1,33 @@
1from django.core.management.base import NoArgsCommand, CommandError
2from django.db import transaction
3from orm.models import Build
4from bldcontrol.bbcontroller import getBuildEnvironmentController, ShellCmdException
5from bldcontrol.models import BuildRequest, BuildEnvironment
6import os
7
8class Command(NoArgsCommand):
9 args = ""
10 help = "Verifies thid %dthe configured settings are valid and usable, or prompts the user to fix the settings."
11
12 def handle(self, **options):
13 # we make sure we have builddir and sourcedir for all defined build envionments
14 for be in BuildEnvironment.objects.all():
15 def _verify_be():
16 is_changed = False
17 print("Verifying the Build Environment type %s id %d." % (be.get_betype_display(), be.pk))
18 if len(be.sourcedir) == 0:
19 be.sourcedir = raw_input(" -- sourcedir may not be empty:")
20 is_changed = True
21 if not be.sourcedir.startswith("/"):
22 be.sourcedir = raw_input(" -- sourcedir must be an absolute path:")
23 is_changed = True
24 if len(be.builddir) == 0:
25 be.builddir = raw_input(" -- builddir may not be empty:")
26 is_changed = True
27 if not be.builddir.startswith("/"):
28 be.builddir = raw_input(" -- builddir must be an absolute path:")
29 is_changed = True
30 return is_changed
31
32 while (_verify_be()):
33 pass
diff --git a/bitbake/lib/toaster/bldcontrol/migrations/0002_auto__add_field_buildenvironment_sourcedir__add_field_buildenvironment.py b/bitbake/lib/toaster/bldcontrol/migrations/0002_auto__add_field_buildenvironment_sourcedir__add_field_buildenvironment.py
new file mode 100644
index 0000000000..f522a500b6
--- /dev/null
+++ b/bitbake/lib/toaster/bldcontrol/migrations/0002_auto__add_field_buildenvironment_sourcedir__add_field_buildenvironment.py
@@ -0,0 +1,106 @@
1# -*- coding: utf-8 -*-
2from south.utils import datetime_utils as datetime
3from south.db import db
4from south.v2 import SchemaMigration
5from django.db import models
6
7
8class Migration(SchemaMigration):
9
10 def forwards(self, orm):
11 # Adding field 'BuildEnvironment.sourcedir'
12 db.add_column(u'bldcontrol_buildenvironment', 'sourcedir',
13 self.gf('django.db.models.fields.CharField')(default='', max_length=512, blank=True),
14 keep_default=False)
15
16 # Adding field 'BuildEnvironment.builddir'
17 db.add_column(u'bldcontrol_buildenvironment', 'builddir',
18 self.gf('django.db.models.fields.CharField')(default='', max_length=512, blank=True),
19 keep_default=False)
20
21
22 def backwards(self, orm):
23 # Deleting field 'BuildEnvironment.sourcedir'
24 db.delete_column(u'bldcontrol_buildenvironment', 'sourcedir')
25
26 # Deleting field 'BuildEnvironment.builddir'
27 db.delete_column(u'bldcontrol_buildenvironment', 'builddir')
28
29
30 models = {
31 u'bldcontrol.brlayer': {
32 'Meta': {'object_name': 'BRLayer'},
33 'commit': ('django.db.models.fields.CharField', [], {'max_length': '254'}),
34 'giturl': ('django.db.models.fields.CharField', [], {'max_length': '254'}),
35 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
36 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
37 'req': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['bldcontrol.BuildRequest']"})
38 },
39 u'bldcontrol.brtarget': {
40 'Meta': {'object_name': 'BRTarget'},
41 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
42 'req': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['bldcontrol.BuildRequest']"}),
43 'target': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
44 'task': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'})
45 },
46 u'bldcontrol.brvariable': {
47 'Meta': {'object_name': 'BRVariable'},
48 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
49 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
50 'req': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['bldcontrol.BuildRequest']"}),
51 'value': ('django.db.models.fields.TextField', [], {'blank': 'True'})
52 },
53 u'bldcontrol.buildenvironment': {
54 'Meta': {'object_name': 'BuildEnvironment'},
55 'address': ('django.db.models.fields.CharField', [], {'max_length': '254'}),
56 'bbaddress': ('django.db.models.fields.CharField', [], {'max_length': '254', 'blank': 'True'}),
57 'bbport': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
58 'bbstate': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
59 'bbtoken': ('django.db.models.fields.CharField', [], {'max_length': '126', 'blank': 'True'}),
60 'betype': ('django.db.models.fields.IntegerField', [], {}),
61 'builddir': ('django.db.models.fields.CharField', [], {'max_length': '512', 'blank': 'True'}),
62 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
63 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
64 'lock': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
65 'sourcedir': ('django.db.models.fields.CharField', [], {'max_length': '512', 'blank': 'True'}),
66 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
67 },
68 u'bldcontrol.buildrequest': {
69 'Meta': {'object_name': 'BuildRequest'},
70 'build': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['orm.Build']", 'null': 'True'}),
71 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
72 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
73 'project': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['orm.Project']"}),
74 'state': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
75 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
76 },
77 u'orm.build': {
78 'Meta': {'object_name': 'Build'},
79 'bitbake_version': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
80 'build_name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
81 'completed_on': ('django.db.models.fields.DateTimeField', [], {}),
82 'cooker_log_path': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
83 'distro': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
84 'distro_version': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
85 'errors_no': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
86 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
87 'machine': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
88 'outcome': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
89 'project': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['orm.Project']", 'null': 'True'}),
90 'started_on': ('django.db.models.fields.DateTimeField', [], {}),
91 'timespent': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
92 'warnings_no': ('django.db.models.fields.IntegerField', [], {'default': '0'})
93 },
94 u'orm.project': {
95 'Meta': {'object_name': 'Project'},
96 'branch': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
97 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
98 u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
99 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
100 'short_description': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
101 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
102 'user_id': ('django.db.models.fields.IntegerField', [], {'null': 'True'})
103 }
104 }
105
106 complete_apps = ['bldcontrol'] \ No newline at end of file
diff --git a/bitbake/lib/toaster/bldcontrol/models.py b/bitbake/lib/toaster/bldcontrol/models.py
index 158874f393..8285257c8e 100644
--- a/bitbake/lib/toaster/bldcontrol/models.py
+++ b/bitbake/lib/toaster/bldcontrol/models.py
@@ -33,6 +33,8 @@ class BuildEnvironment(models.Model):
33 bbport = models.IntegerField(default = -1) 33 bbport = models.IntegerField(default = -1)
34 bbtoken = models.CharField(max_length = 126, blank = True) 34 bbtoken = models.CharField(max_length = 126, blank = True)
35 bbstate = models.IntegerField(choices = SERVER_STATE, default = SERVER_STOPPED) 35 bbstate = models.IntegerField(choices = SERVER_STATE, default = SERVER_STOPPED)
36 sourcedir = models.CharField(max_length = 512, blank = True)
37 builddir = models.CharField(max_length = 512, blank = True)
36 lock = models.IntegerField(choices = LOCK_STATE, default = LOCK_FREE) 38 lock = models.IntegerField(choices = LOCK_STATE, default = LOCK_FREE)
37 created = models.DateTimeField(auto_now_add = True) 39 created = models.DateTimeField(auto_now_add = True)
38 updated = models.DateTimeField(auto_now = True) 40 updated = models.DateTimeField(auto_now = True)