blob: daeca9bed95cfd9ed8d37b57558a91eafec0d922 [file] [log] [blame]
Alex Kleind0f9e172018-10-17 10:37:54 -06001# -*- coding: utf-8 -*-
Chris Sosa7c931362010-10-11 19:49:01 -07002# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
rtc@google.comded22402009-10-26 22:36:21 +00003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
Don Garrettfb15e322016-06-21 19:12:08 -07006"""Defines a build related helper class."""
7
8from __future__ import print_function
9
Gilad Arnoldabb352e2012-09-23 01:24:27 -070010import os
11import sys
12
Zdenek Behan59d8aa72011-02-24 01:09:02 +010013
Sean O'Connor14b6a0a2010-03-20 23:23:48 -070014class BuildObject(object):
Don Garrettfb15e322016-06-21 19:12:08 -070015 """Common base class that defines key paths in the source tree.
joychen921e1fb2013-06-28 11:12:20 -070016
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.
rtc@google.comded22402009-10-26 22:36:21 +000019 """
Chris Sosa7cd23202013-10-15 17:22:57 -070020 def __init__(self, static_dir):
Zdenek Behan59d8aa72011-02-24 01:09:02 +010021 self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
rtc@google.com64244662009-11-12 00:52:08 +000022 self.static_dir = static_dir
Chris Sosa7cd23202013-10-15 17:22:57 -070023 self.scripts_dir = os.path.join(self.GetSourceRoot(), 'src/scripts')
Alex Kleind0f9e172018-10-17 10:37:54 -060024 self.images_dir = os.path.join(self.GetSourceRoot(), 'src/build/images')
Chris Sosa7cd23202013-10-15 17:22:57 -070025
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)
joychen921e1fb2013-06-28 11:12:20 -070034
Alex Klein77df9352018-10-30 12:01:06 -060035 def GetLatestImageLink(self, board):
36 """Returns the latest image symlink."""
Alex Kleind0f9e172018-10-17 10:37:54 -060037 return os.path.join(self.images_dir, board, 'latest')
joychenb0dfe552013-07-30 10:02:06 -070038
39 def GetDefaultBoardID(self):
joychen562699a2013-08-13 15:22:14 -070040 """Returns the default board id stored in .default_board.
41
42 Default to x86-generic, if that isn't set.
43 """
joychenb0dfe552013-07-30 10:02:06 -070044 board_file = '%s/.default_board' % (self.scripts_dir)
45 try:
joychen562699a2013-08-13 15:22:14 -070046 with open(board_file) as bf:
47 return bf.read().strip()
joychenb0dfe552013-07-30 10:02:06 -070048 except IOError:
49 return 'x86-generic'