Justin Yun | 0daf186 | 2022-04-27 16:21:16 +0900 | [diff] [blame] | 1 | # 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 | |
| 16 | import logging |
| 17 | import os |
| 18 | |
| 19 | # default build configuration for each component |
| 20 | DEFAULT_BUILDCMD = 'm' |
| 21 | DEFAULT_OUTDIR = 'out' |
| 22 | |
| 23 | # yaml fields |
| 24 | META_BUILDCMD = 'build_cmd' |
| 25 | META_OUTDIR = 'out_dir' |
| 26 | META_EXPORTS = 'exports' |
| 27 | META_IMPORTS = 'imports' |
| 28 | META_TARGETS = 'lunch_targets' |
| 29 | META_DEPS = 'deps' |
| 30 | # fields under 'exports' and 'imports' |
| 31 | META_LIBS = 'libraries' |
| 32 | META_APIS = 'APIs' |
| 33 | META_FILEGROUP = 'filegroup' |
| 34 | META_MODULES = 'modules' |
| 35 | # fields under 'libraries' |
| 36 | META_LIB_NAME = 'name' |
| 37 | |
| 38 | # fields for generated metadata file |
| 39 | SOONG_IMPORTED = 'Imported' |
| 40 | SOONG_IMPORTED_FILEGROUPS = 'FileGroups' |
| 41 | SOONG_EXPORTED = 'Exported' |
| 42 | |
| 43 | # export map items |
| 44 | EXP_COMPONENT = 'component' |
| 45 | EXP_TYPE = 'type' |
| 46 | EXP_OUTPATHS = 'outpaths' |
| 47 | |
| 48 | class 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 | |
| 80 | def get_build_context(): |
| 81 | return BuildContext() |
| 82 | |
| 83 | |
| 84 | def 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]) |