blob: daeca9bed95cfd9ed8d37b57558a91eafec0d922 [file] [log] [blame]
Alex Kleind0f9e172018-10-17 16:37:541# -*- coding: utf-8 -*-
Chris Sosa7c931362010-10-12 02:49:012# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
[email protected]ded22402009-10-26 22:36:213# 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-22 02:12:086"""Defines a build related helper class."""
7
8from __future__ import print_function
9
Gilad Arnoldabb352e2012-09-23 08:24:2710import os
11import sys
12
Zdenek Behan59d8aa72011-02-24 00:09:0213
Sean O'Connor14b6a0a2010-03-21 06:23:4814class BuildObject(object):
Don Garrettfb15e322016-06-22 02:12:0815 """Common base class that defines key paths in the source tree.
joychen921e1fb2013-06-28 18:12:2016
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]ded22402009-10-26 22:36:2119 """
Chris Sosa7cd23202013-10-16 00:22:5720 def __init__(self, static_dir):
Zdenek Behan59d8aa72011-02-24 00:09:0221 self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
[email protected]64244662009-11-12 00:52:0822 self.static_dir = static_dir
Chris Sosa7cd23202013-10-16 00:22:5723 self.scripts_dir = os.path.join(self.GetSourceRoot(), 'src/scripts')
Alex Kleind0f9e172018-10-17 16:37:5424 self.images_dir = os.path.join(self.GetSourceRoot(), 'src/build/images')
Chris Sosa7cd23202013-10-16 00:22:5725
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 18:12:2034
Alex Klein77df9352018-10-30 18:01:0635 def GetLatestImageLink(self, board):
36 """Returns the latest image symlink."""
Alex Kleind0f9e172018-10-17 16:37:5437 return os.path.join(self.images_dir, board, 'latest')
joychenb0dfe552013-07-30 17:02:0638
39 def GetDefaultBoardID(self):
joychen562699a2013-08-13 22:22:1440 """Returns the default board id stored in .default_board.
41
42 Default to x86-generic, if that isn't set.
43 """
joychenb0dfe552013-07-30 17:02:0644 board_file = '%s/.default_board' % (self.scripts_dir)
45 try:
joychen562699a2013-08-13 22:22:1446 with open(board_file) as bf:
47 return bf.read().strip()
joychenb0dfe552013-07-30 17:02:0648 except IOError:
49 return 'x86-generic'