| 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 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return pkg in _OutputOf([ | 44 return pkg in _OutputOf([ |
| 45 'cros_workon', '--board=' + board, 'list', '--all']) | 45 'cros_workon', '--board=' + board, 'list', '--all']) |
| 46 | 46 |
| 47 def SetError(self, text): | 47 def SetError(self, text): |
| 48 cherrypy.response.status = 500 | 48 cherrypy.response.status = 500 |
| 49 cherrypy.log(text, 'BUILD') | 49 cherrypy.log(text, 'BUILD') |
| 50 return text | 50 return text |
| 51 | 51 |
| 52 def Build(self, board, pkg, additional_args): | 52 def Build(self, board, pkg, additional_args): |
| 53 """Handles a build request from the cherrypy server.""" | 53 """Handles a build request from the cherrypy server.""" |
| 54 cherrypy.log('Additional build request arguments: '+ str(additional_args), | 54 cherrypy.log('Additional build request arguments: ' + str(additional_args), |
| 55 'BUILD') | 55 'BUILD') |
| 56 | 56 |
| 57 original_use = os.environ.get('USE', '') | 57 def _AppendStrToEnvVar(env, var, additional_string): |
| 58 env[var] = env.get(var, '') + ' ' + additional_string |
| 59 cherrypy.log('%s flags modified to %s' % (var, env[var]), 'BUILD') |
| 60 |
| 61 env_copy = os.environ.copy() |
| 58 if 'use' in additional_args: | 62 if 'use' in additional_args: |
| 59 os.environ['USE'] = original_use + ' ' + additional_args['use'] | 63 _AppendStrToEnvVar(env_copy, 'USE', additional_args['use']) |
| 60 cherrypy.log('USE flags modified to ' + os.environ['USE'], 'BUILD') | 64 |
| 65 if 'features' in additional_args: |
| 66 _AppendStrToEnvVar(env_copy, 'FEATURES', additional_args['features']) |
| 61 | 67 |
| 62 try: | 68 try: |
| 63 if (self._ShouldBeWorkedOn(board, pkg) and | 69 if (self._ShouldBeWorkedOn(board, pkg) and |
| 64 not additional_args.get('accept_stable')): | 70 not additional_args.get('accept_stable')): |
| 65 return self.SetError( | 71 return self.SetError( |
| 66 'Package is not cros_workon\'d on the devserver machine.\n' | 72 'Package is not cros_workon\'d on the devserver machine.\n' |
| 67 'Either start working on the package or pass --accept_stable ' | 73 'Either start working on the package or pass --accept_stable ' |
| 68 'to gmerge') | 74 'to gmerge') |
| 69 | 75 |
| 70 rc = subprocess.call(['emerge-%s' % board, pkg]) | 76 rc = subprocess.call(['emerge-%s' % board, pkg], env=env_copy) |
| 71 if rc != 0: | 77 if rc != 0: |
| 72 return self.SetError('Could not emerge ' + pkg) | 78 return self.SetError('Could not emerge ' + pkg) |
| 73 | 79 |
| 74 cherrypy.log('ecleaning %s' % pkg, 'BUILD') | 80 cherrypy.log('ecleaning %s' % pkg, 'BUILD') |
| 75 rc = subprocess.call(['eclean-' + board, '-d', 'packages']) | 81 rc = subprocess.call(['eclean-' + board, '-d', 'packages']) |
| 76 if rc != 0: | 82 if rc != 0: |
| 77 return self.SetError('eclean failed') | 83 return self.SetError('eclean failed') |
| 78 | 84 |
| 79 cherrypy.log('eclean complete %s' % pkg, 'BUILD') | 85 cherrypy.log('eclean complete %s' % pkg, 'BUILD') |
| 80 return 'Success\n' | 86 return 'Success\n' |
| 81 except OSError, e: | 87 except OSError, e: |
| 82 return self.SetError('Could not execute build command: ' + str(e)) | 88 return self.SetError('Could not execute build command: ' + str(e)) |
| 83 finally: | |
| 84 os.environ['USE'] = original_use | |
| OLD | NEW |