1#!/usr/bin/env python3 2# 3# Copyright 2020 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Native project information.""" 18 19from __future__ import absolute_import 20 21from aidegen.lib import native_module_info 22from aidegen.lib import project_config 23from aidegen.lib import project_info 24 25 26class NativeProjectInfo(): 27 """Native project information. 28 29 Class attributes: 30 modules_info: An AidegenModuleInfo instance whose name_to_module_info is 31 a dictionary of module_bp_cc_deps.json. 32 33 Attributes: 34 module_names: A list of the native project's module names. 35 need_builds: A set of module names need to be built. 36 """ 37 38 modules_info = None 39 40 def __init__(self, target): 41 """ProjectInfo initialize. 42 43 Args: 44 target: A native module or project path from users' input will be 45 checked if they contain include paths need to be generated, 46 e.g., in 'libui' module. 47 'out/soong/../android.frameworks.bufferhub@1.0_genc++_headers/gen' 48 we should call 'm android.frameworks.bufferhub@1.0' to 49 generate the include header files in, 50 'android.frameworks.bufferhub@1.0_genc++_headers/gen' 51 direcotry. 52 """ 53 self.module_names = [target] if self.modules_info.is_module( 54 target) else self.modules_info.get_module_names_in_targets_paths( 55 [target]) 56 self.need_builds = { 57 mod_name 58 for mod_name in self.module_names 59 if self.modules_info.is_module_need_build(mod_name) 60 } 61 62 @classmethod 63 def _init_modules_info(cls): 64 """Initializes the class attribute: modules_info.""" 65 if cls.modules_info: 66 return 67 cls.modules_info = native_module_info.NativeModuleInfo() 68 69 @classmethod 70 def generate_projects(cls, targets): 71 """Generates a list of projects in one time by a list of module names. 72 73 The method will collect all needed to build modules and build their 74 source and include files for them. But if users set the skip build flag 75 it won't build anything. 76 Usage: 77 Call this method before native IDE project files are generated. 78 For example, 79 native_project_info.NativeProjectInfo.generate_projects(targets) 80 native_project_file = native_util.generate_clion_projects(targets) 81 ... 82 83 Args: 84 targets: A list of native modules or project paths which will be 85 checked if they contain source or include paths need to be 86 generated. 87 """ 88 config = project_config.ProjectConfig.get_instance() 89 if config.is_skip_build: 90 return 91 cls._init_modules_info() 92 need_builds = cls._get_need_builds(targets) 93 if need_builds: 94 project_info.batch_build_dependencies(need_builds) 95 96 @classmethod 97 def _get_need_builds(cls, targets): 98 """Gets need to be built modules from targets. 99 100 Args: 101 targets: A list of native modules or project paths which will be 102 checked if they contain source or include paths need to be 103 generated. 104 105 Returns: 106 A set of module names which need to be built. 107 """ 108 need_builds = set() 109 for target in targets: 110 project = NativeProjectInfo(target) 111 if project.need_builds: 112 need_builds.update(project.need_builds) 113 return need_builds 114