blob: 0e8f6808b2fccb80cd44561b483fc37078b22b6b [file] [log] [blame]
Chris Sosa7c931362010-10-11 19:49:01 -07001# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
rtc@google.comded22402009-10-26 22:36:21 +00002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Don Garrettfb15e322016-06-21 19:12:08 -07005"""Defines a build related helper class."""
6
7from __future__ import print_function
8
Gilad Arnoldabb352e2012-09-23 01:24:27 -07009import os
10import sys
11
Zdenek Behan59d8aa72011-02-24 01:09:02 +010012
Sean O'Connor14b6a0a2010-03-20 23:23:48 -070013class BuildObject(object):
Don Garrettfb15e322016-06-21 19:12:08 -070014 """Common base class that defines key paths in the source tree.
joychen921e1fb2013-06-28 11:12:20 -070015
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.comded22402009-10-26 22:36:21 +000018 """
Chris Sosa7cd23202013-10-15 17:22:57 -070019 def __init__(self, static_dir):
Zdenek Behan59d8aa72011-02-24 01:09:02 +010020 self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
rtc@google.com64244662009-11-12 00:52:08 +000021 self.static_dir = static_dir
Chris Sosa7cd23202013-10-15 17:22:57 -070022 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)
joychen921e1fb2013-06-28 11:12:20 -070032
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()
joychenb0dfe552013-07-30 10:02:06 -070037
38 def GetDefaultBoardID(self):
joychen562699a2013-08-13 15:22:14 -070039 """Returns the default board id stored in .default_board.
40
41 Default to x86-generic, if that isn't set.
42 """
joychenb0dfe552013-07-30 10:02:06 -070043 board_file = '%s/.default_board' % (self.scripts_dir)
44 try:
joychen562699a2013-08-13 15:22:14 -070045 with open(board_file) as bf:
46 return bf.read().strip()
joychenb0dfe552013-07-30 10:02:06 -070047 except IOError:
48 return 'x86-generic'