blob: 5dbbe4aa9f5726eb84ddddcd5f65f71b03924ba3 [file] [log] [blame]
Justin Yun0daf1862022-04-27 16:21:16 +09001# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16import logging
17import os
18
19# default build configuration for each component
20DEFAULT_BUILDCMD = 'm'
21DEFAULT_OUTDIR = 'out'
22
23# yaml fields
24META_BUILDCMD = 'build_cmd'
25META_OUTDIR = 'out_dir'
26META_EXPORTS = 'exports'
27META_IMPORTS = 'imports'
28META_TARGETS = 'lunch_targets'
29META_DEPS = 'deps'
30# fields under 'exports' and 'imports'
31META_LIBS = 'libraries'
32META_APIS = 'APIs'
33META_FILEGROUP = 'filegroup'
34META_MODULES = 'modules'
35# fields under 'libraries'
36META_LIB_NAME = 'name'
37
38# fields for generated metadata file
39SOONG_IMPORTED = 'Imported'
40SOONG_IMPORTED_FILEGROUPS = 'FileGroups'
41SOONG_EXPORTED = 'Exported'
42
43# export map items
44EXP_COMPONENT = 'component'
45EXP_TYPE = 'type'
46EXP_OUTPATHS = 'outpaths'
47
48class BuildContext:
49
50 def __init__(self):
51 self._build_top = os.getenv('BUFFET_BUILD_TOP')
52 self._components_top = os.getenv('BUFFET_COMPONENTS_TOP')
53 self._target_product = os.getenv('BUFFET_TARGET_PRODUCT')
54 self._target_build_variant = os.getenv('BUFFET_TARGET_BUILD_VARIANT')
55 self._target_build_type = os.getenv('BUFFET_TARGET_BUILD_TYPE')
56 self._out_dir = os.path.join(self._build_top, 'out')
57
58 if not self._build_top:
59 raise RuntimeError("Can't find root. Did you run buffet?")
60
61 def build_top(self):
62 return self._build_top
63
64 def components_top(self):
65 return self._components_top
66
67 def target_product(self):
68 return self._target_product
69
70 def target_build_variant(self):
71 return self._target_build_variant
72
73 def target_build_type(self):
74 return self._target_build_type
75
76 def out_dir(self):
77 return self._out_dir
78
79
80def get_build_context():
81 return BuildContext()
82
83
84def set_logging_config(verbose_level):
85 verbose_map = (logging.WARNING, logging.INFO, logging.DEBUG)
86 verbosity = min(verbose_level, 2)
87 logging.basicConfig(
88 format='%(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
89 level=verbose_map[verbosity])