Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 1 | # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Don Garrett | fb15e32 | 2016-06-21 19:12:08 -0700 | [diff] [blame] | 5 | """Defines a build related helper class.""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | |
Gilad Arnold | abb352e | 2012-09-23 01:24:27 -0700 | [diff] [blame] | 9 | import os |
| 10 | import sys |
| 11 | |
Zdenek Behan | 59d8aa7 | 2011-02-24 01:09:02 +0100 | [diff] [blame] | 12 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 13 | class BuildObject(object): |
Don Garrett | fb15e32 | 2016-06-21 19:12:08 -0700 | [diff] [blame] | 14 | """Common base class that defines key paths in the source tree. |
joychen | 921e1fb | 2013-06-28 11:12:20 -0700 | [diff] [blame] | 15 | |
| 16 | Classes that inherit from BuildObject can access scripts in the src/scripts |
| 17 | directory, and have a handle to the static directory of the devserver. |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 18 | """ |
Chris Sosa | 7cd2320 | 2013-10-15 17:22:57 -0700 | [diff] [blame] | 19 | def __init__(self, static_dir): |
Zdenek Behan | 59d8aa7 | 2011-02-24 01:09:02 +0100 | [diff] [blame] | 20 | self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 21 | self.static_dir = static_dir |
Chris Sosa | 7cd2320 | 2013-10-15 17:22:57 -0700 | [diff] [blame] | 22 | self.scripts_dir = os.path.join(self.GetSourceRoot(), 'src/scripts') |
| 23 | |
| 24 | @staticmethod |
| 25 | def GetSourceRoot(): |
| 26 | """Returns the path to the source root.""" |
| 27 | src_root = os.environ.get('CROS_WORKON_SRCROOT') |
| 28 | if not src_root: |
| 29 | src_root = os.path.join(os.path.dirname(__file__), '..', '..', '..') |
| 30 | |
| 31 | return os.path.realpath(src_root) |
joychen | 921e1fb | 2013-06-28 11:12:20 -0700 | [diff] [blame] | 32 | |
| 33 | def GetLatestImageDir(self, board): |
| 34 | """Returns the latest image dir based on shell script.""" |
| 35 | cmd = '%s/get_latest_image.sh --board %s' % (self.scripts_dir, board) |
| 36 | return os.popen(cmd).read().strip() |
joychen | b0dfe55 | 2013-07-30 10:02:06 -0700 | [diff] [blame] | 37 | |
| 38 | def GetDefaultBoardID(self): |
joychen | 562699a | 2013-08-13 15:22:14 -0700 | [diff] [blame] | 39 | """Returns the default board id stored in .default_board. |
| 40 | |
| 41 | Default to x86-generic, if that isn't set. |
| 42 | """ |
joychen | b0dfe55 | 2013-07-30 10:02:06 -0700 | [diff] [blame] | 43 | board_file = '%s/.default_board' % (self.scripts_dir) |
| 44 | try: |
joychen | 562699a | 2013-08-13 15:22:14 -0700 | [diff] [blame] | 45 | with open(board_file) as bf: |
| 46 | return bf.read().strip() |
joychen | b0dfe55 | 2013-07-30 10:02:06 -0700 | [diff] [blame] | 47 | except IOError: |
| 48 | return 'x86-generic' |