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