| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2009-2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009-2011 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Package builder for the dev server.""" | 7 """Package builder for the dev server.""" |
| 8 import os | 8 import os |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 import cherrypy | 12 import cherrypy |
| 13 | 13 |
| 14 | 14 |
| 15 def _OutputOf(command): | 15 def _OutputOf(command): |
| 16 """Runs command, a list of arguments beginning with an executable. | 16 """Runs command, a list of arguments beginning with an executable. |
| 17 | 17 |
| 18 If the executable begins with "scripts/", the path is adjusted to | |
| 19 the scripts directory of this chroot. | |
| 20 | |
| 21 Args: | 18 Args: |
| 22 command: A list of arguments, beginning with the executable | 19 command: A list of arguments, beginning with the executable |
| 23 Returns: | 20 Returns: |
| 24 The output of the command | 21 The output of the command |
| 25 Raises: | 22 Raises: |
| 26 subprocess.CalledProcessError if the command fails | 23 subprocess.CalledProcessError if the command fails |
| 27 """ | 24 """ |
| 28 scripts = 'scripts/' | |
| 29 if command[0].find(scripts) == 0: | |
| 30 server_dir = os.path.dirname(os.path.abspath(sys.argv[0])) | |
| 31 command[0] = command[0].replace(scripts, server_dir + '/../../' + scripts) | |
| 32 command_name = ' '.join(command) | 25 command_name = ' '.join(command) |
| 33 cherrypy.log('Executing: ' + command_name, 'BUILD') | 26 cherrypy.log('Executing: ' + command_name, 'BUILD') |
| 34 | 27 |
| 35 p = subprocess.Popen(command, stdout=subprocess.PIPE) | 28 p = subprocess.Popen(command, stdout=subprocess.PIPE) |
| 36 output_blob = p.communicate()[0] | 29 output_blob = p.communicate()[0] |
| 37 if p.returncode != 0: | 30 if p.returncode != 0: |
| 38 raise subprocess.CalledProcessError(p.returncode, command_name) | 31 raise subprocess.CalledProcessError(p.returncode, command_name) |
| 39 return output_blob | 32 return output_blob |
| 40 | 33 |
| 41 | 34 |
| 42 class Builder(object): | 35 class Builder(object): |
| 43 """Builds packages for the devserver.""" | 36 """Builds packages for the devserver.""" |
| 44 | 37 |
| 45 def _ShouldBeWorkedOn(self, board, pkg): | 38 def _ShouldBeWorkedOn(self, board, pkg): |
| 46 """Is pkg a package that could be worked on, but is not?""" | 39 """Is pkg a package that could be worked on, but is not?""" |
| 47 if pkg in _OutputOf(['scripts/cros_workon', '--board=' + board, 'list']): | 40 if pkg in _OutputOf(['cros_workon', '--board=' + board, 'list']): |
| 48 return False | 41 return False |
| 49 | 42 |
| 50 # If it's in the list of possible workon targets, we should be working on it | 43 # If it's in the list of possible workon targets, we should be working on it |
| 51 return pkg in _OutputOf([ | 44 return pkg in _OutputOf([ |
| 52 'scripts/cros_workon', '--board=' + board, 'list', '--all']) | 45 'cros_workon', '--board=' + board, 'list', '--all']) |
| 53 | 46 |
| 54 def SetError(self, text): | 47 def SetError(self, text): |
| 55 cherrypy.response.status = 500 | 48 cherrypy.response.status = 500 |
| 56 cherrypy.log(text, 'BUILD') | 49 cherrypy.log(text, 'BUILD') |
| 57 return text | 50 return text |
| 58 | 51 |
| 59 def Build(self, board, pkg, additional_args): | 52 def Build(self, board, pkg, additional_args): |
| 60 """Handles a build request from the cherrypy server.""" | 53 """Handles a build request from the cherrypy server.""" |
| 61 cherrypy.log('Additional build request arguments: '+ str(additional_args), | 54 cherrypy.log('Additional build request arguments: '+ str(additional_args), |
| 62 'BUILD') | 55 'BUILD') |
| (...skipping 19 matching lines...) Expand all Loading... |
| 82 rc = subprocess.call(['eclean-' + board, '-d', 'packages']) | 75 rc = subprocess.call(['eclean-' + board, '-d', 'packages']) |
| 83 if rc != 0: | 76 if rc != 0: |
| 84 return self.SetError('eclean failed') | 77 return self.SetError('eclean failed') |
| 85 | 78 |
| 86 cherrypy.log('eclean complete %s' % pkg, 'BUILD') | 79 cherrypy.log('eclean complete %s' % pkg, 'BUILD') |
| 87 return 'Success\n' | 80 return 'Success\n' |
| 88 except OSError, e: | 81 except OSError, e: |
| 89 return self.SetError('Could not execute build command: ' + str(e)) | 82 return self.SetError('Could not execute build command: ' + str(e)) |
| 90 finally: | 83 finally: |
| 91 os.environ['USE'] = original_use | 84 os.environ['USE'] = original_use |
| OLD | NEW |