Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Build target class and related functionality.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | |
| 13 | class Error(Exception): |
| 14 | """Base module error class.""" |
| 15 | |
| 16 | |
| 17 | class InvalidNameError(Exception): |
| 18 | """Error for invalid target name argument.""" |
| 19 | |
| 20 | |
| 21 | class BuildTarget(object): |
| 22 | """Class to handle the build target information.""" |
| 23 | |
| 24 | def __init__(self, name, profile=None, build_root=None): |
| 25 | """Build Target init. |
| 26 | |
| 27 | Args: |
| 28 | name (str): The full name of the target. |
| 29 | profile (str): The profile name. |
| 30 | build_root (str): The path to the buildroot. |
| 31 | """ |
| 32 | if not name: |
| 33 | raise InvalidNameError('Name is required.') |
| 34 | |
| 35 | self.name = name |
| 36 | self.board, _, self.variant = name.partition('_') |
| 37 | self.profile = profile |
| 38 | |
| 39 | if build_root: |
| 40 | self.root = os.path.normpath(build_root) |
| 41 | else: |
| 42 | self.root = GetDefaultSysrootPath(self.name) |
| 43 | |
| 44 | |
| 45 | def GetDefaultSysrootPath(target_name): |
| 46 | if target_name: |
| 47 | return os.path.join('/build', target_name) |
| 48 | else: |
| 49 | raise InvalidNameError('Target name is required.') |