diff options
Diffstat (limited to 'bitbake/lib/toaster/bldcontrol/localhostbecontroller.py')
-rw-r--r-- | bitbake/lib/toaster/bldcontrol/localhostbecontroller.py | 90 |
1 files changed, 18 insertions, 72 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py index 15c0ff9e82..44a9136733 100644 --- a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py +++ b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py | |||
@@ -88,82 +88,28 @@ class LocalhostBEController(BuildEnvironmentController): | |||
88 | # find our own toasterui listener/bitbake | 88 | # find our own toasterui listener/bitbake |
89 | from toaster.bldcontrol.management.commands.loadconf import _reduce_canon_path | 89 | from toaster.bldcontrol.management.commands.loadconf import _reduce_canon_path |
90 | 90 | ||
91 | own_bitbake = _reduce_canon_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../bin/bitbake")) | 91 | toaster = _reduce_canon_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../bin/toaster")) |
92 | 92 | assert os.path.exists(toaster) and os.path.isfile(toaster) | |
93 | assert os.path.exists(own_bitbake) and os.path.isfile(own_bitbake) | 93 | |
94 | 94 | # restart bitbake server and toastergui observer | |
95 | logger.debug("localhostbecontroller: running the listener at %s" % own_bitbake) | 95 | self._shellcmd("bash -c 'source %s restart-bitbake'" % toaster, self.be.builddir) |
96 | 96 | logger.debug("localhostbecontroller: restarted bitbake server") | |
97 | toaster_ui_log_filepath = os.path.join(self.be.builddir, "toaster_ui.log") | 97 | |
98 | # get the file length; we need to detect the _last_ start of the toaster UI, not the first | 98 | # read port number from bitbake.lock |
99 | toaster_ui_log_filelength = 0 | 99 | self.be.bbport = "" |
100 | if os.path.exists(toaster_ui_log_filepath): | 100 | bblock = os.path.join(self.be.builddir, 'bitbake.lock') |
101 | with open(toaster_ui_log_filepath, "w") as f: | 101 | if os.path.exists(bblock): |
102 | f.seek(0, 2) # jump to the end | 102 | with open(bblock) as fplock: |
103 | toaster_ui_log_filelength = f.tell() | 103 | for line in fplock: |
104 | |||
105 | cmd = "bash -c \"source %s/oe-init-build-env %s 2>&1 >toaster_server.log && bitbake --read %s/conf/toaster-pre.conf --postread %s/conf/toaster.conf --server-only -t xmlrpc -B 0.0.0.0:0 2>&1 >>toaster_server.log \"" % (self.pokydirname, self.be.builddir, self.be.builddir, self.be.builddir) | ||
106 | |||
107 | port = "-1" | ||
108 | logger.debug("localhostbecontroller: starting builder \n%s\n" % cmd) | ||
109 | |||
110 | cmdoutput = self._shellcmd(cmd) | ||
111 | with open(self.be.builddir + "/toaster_server.log", "r") as f: | ||
112 | for i in f.readlines(): | ||
113 | if i.startswith("Bitbake server address"): | ||
114 | port = i.split(" ")[-1] | ||
115 | logger.debug("localhostbecontroller: Found bitbake server port %s" % port) | ||
116 | |||
117 | cmd = "bash -c \"source %s/oe-init-build-env-memres -1 %s && %s --observe-only -u toasterui --remote-server=0.0.0.0:-1 -t xmlrpc\"" % \ | ||
118 | (self.pokydirname, self.be.builddir, own_bitbake) | ||
119 | |||
120 | # Use a copy of the current environment and add the DATABASE_URL | ||
121 | # for the bitbake observer process. | ||
122 | env = os.environ.copy() | ||
123 | env['DATABASE_URL'] = settings.getDATABASE_URL() | ||
124 | |||
125 | with open(toaster_ui_log_filepath, "a+") as f: | ||
126 | p = subprocess.Popen(cmd, cwd = self.be.builddir, shell=True, | ||
127 | stdout=f, stderr=f, env=env) | ||
128 | |||
129 | def _toaster_ui_started(filepath, filepos = 0): | ||
130 | if not os.path.exists(filepath): | ||
131 | return False | ||
132 | with open(filepath, "r") as f: | ||
133 | f.seek(filepos) | ||
134 | for line in f: | ||
135 | if line.startswith("NOTE: ToasterUI waiting for events"): | ||
136 | return True | ||
137 | return False | ||
138 | |||
139 | retries = 0 | ||
140 | started = False | ||
141 | while not started and retries < 50: | ||
142 | started = _toaster_ui_started(toaster_ui_log_filepath, toaster_ui_log_filelength) | ||
143 | import time | ||
144 | logger.debug("localhostbecontroller: Waiting bitbake server to start") | ||
145 | time.sleep(0.5) | ||
146 | retries += 1 | ||
147 | |||
148 | if not started: | ||
149 | toaster_ui_log = open(os.path.join(self.be.builddir, "toaster_ui.log"), "r").read() | ||
150 | toaster_server_log = open(os.path.join(self.be.builddir, "toaster_server.log"), "r").read() | ||
151 | raise BuildSetupException("localhostbecontroller: Bitbake server did not start in 25 seconds, aborting (Error: '%s' '%s')" % (toaster_ui_log, toaster_server_log)) | ||
152 | |||
153 | logger.debug("localhostbecontroller: Started bitbake server") | ||
154 | |||
155 | while port == "-1": | ||
156 | # the port specification is "autodetect"; read the bitbake.lock file | ||
157 | with open("%s/bitbake.lock" % self.be.builddir, "r") as f: | ||
158 | for line in f.readlines(): | ||
159 | if ":" in line: | 104 | if ":" in line: |
160 | port = line.split(":")[1].strip() | 105 | self.be.bbport = line.split(":")[-1].strip() |
161 | logger.debug("localhostbecontroller: Autodetected bitbake port %s", port) | 106 | logger.debug("localhostbecontroller: bitbake port %s", self.be.bbport) |
162 | break | 107 | break |
163 | 108 | ||
164 | assert self.be.sourcedir and os.path.exists(self.be.builddir) | 109 | if not self.be.bbport: |
110 | raise BuildSetupException("localhostbecontroller: can't read bitbake port from %s" % bblock) | ||
111 | |||
165 | self.be.bbaddress = "localhost" | 112 | self.be.bbaddress = "localhost" |
166 | self.be.bbport = port | ||
167 | self.be.bbstate = BuildEnvironment.SERVER_STARTED | 113 | self.be.bbstate = BuildEnvironment.SERVER_STARTED |
168 | self.be.save() | 114 | self.be.save() |
169 | 115 | ||