diff --git a/hb_new/main.py b/hb_new/main.py index 0fd3fd609ffb8735795887c144c647ce1c42a62e..28739091a90e1659f46a1bc246a0a52a7f479a2b 100755 --- a/hb_new/main.py +++ b/hb_new/main.py @@ -76,7 +76,7 @@ class Main(): config = Config() - preloader = PreloaderAdapt(config) + preloader = OHOSPreloader(config) preload = Preload(preloader) loader = OHOSLoader(config) diff --git a/hb_new/services/preloader.py b/hb_new/services/preloader.py index 3b1e7e9908f32c9763491f52d1becdeaf07f971a..169efe3c0de034c8e65694950919162d78a22d5b 100644 --- a/hb_new/services/preloader.py +++ b/hb_new/services/preloader.py @@ -15,12 +15,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os from containers.statusCode import StatusCode from services.interface.preloadInterface import PreloadInterface from resources.config import Config +from util.ioUtil import IoUtil +from util.preloader.preloader_process_data import Dirs, Outputs, Product +from util.preloader.parse_lite_subsystems_config import parse_lite_subsystem_config +from util.preloader.parse_vendor_product_config import get_vendor_parts_list + from lite.hb_internal.preloader.preloader import Preloader -from hb_internal.common.config import Config as _Config +from lite.hb_internal.common.config import Config as _Config + class PreloaderAdapt(PreloadInterface): @@ -38,7 +45,57 @@ class OHOSPreloader(PreloadInterface): def __init__(self, config: Config): super().__init__(config) + self._dirs = Dirs(config) + + #preloader_output_dir + self.preloader_output_dir = os.path.join(config.root_path, 'out/preloader', config.product) + + # All kinds of output files + os.makedirs(self._dirs.preloader_output_dir, exist_ok=True) + self._outputs = Outputs(self._dirs.preloader_output_dir) # 可以解决掉,然后全部作为成员 + + # Product & device + self._product = Product(config.product, self._dirs, config.product_json) # 用于配置产品 + + def __post_init__(self): + + #product parse + self._product._do_parse() + + #get device information + self._device = self._product._device + + #get all parts + self._all_parts = self._product._parts + + #get build config info + self._build_vars = self._product._build_vars + + if self._device: + device_info = self._device.get_device_info() + if device_info: + if self._config.target_cpu: + device_info["target_cpu"] = self._config.target_cpu + if self._config.compile_config: + device_info[self._config.compile_config] = True + self._build_vars.update(device_info) + + # generate toolchain + self._os_level = self._build_vars.get('os_level') + self._target_os = self._build_vars.get('target_os') + self._target_cpu = self._build_vars.get('target_cpu') + self._toolchain_label = self._get_toolchain_label() + + # add toolchain label + self._build_vars['product_toolchain_label'] = self._toolchain_label + + #subsystem info + self._subsystem_info = self._get_org_subsystem_info() + + def _internel_run(self) -> StatusCode: + self.__post_init__() + self._generate_build_prop() self._generate_build_config_json() self._generate_parts_json() @@ -48,37 +105,144 @@ class OHOSPreloader(PreloadInterface): self._generate_syscap_json() self._generate_exclusion_modules_json() self._generate_platforms_build() + self._generate_subsystem_config_json() self._generate_systemcapability_json() - def _generate_build_prop(self) -> StatusCode: - pass - - def _generate_build_config_json(self) -> StatusCode: - pass - - def _generate_parts_json(self) -> StatusCode: - pass - - def _generate_parts_config_json(self) -> StatusCode: - pass +#generate method + # generate platforms build info to out/preloader/product_name/platforms.build + def _generate_platforms_build(self) -> StatusCode: + config = { + 'target_os': self._target_os, + "target_cpu": self._target_cpu, + "toolchain": self._toolchain_label, + "parts_config": os.path.relpath(self._outputs.parts_json, + self._dirs.preloader_output_dir) + } + platform_config = {'version': 2, 'platforms': {'phone': config}} + IoUtil.dump_json_file(self._outputs.platforms_build, platform_config) + + # generate build gnargs prop info to out/preloader/product_name/build_gnargs.prop def _generate_build_gnargs_prop(self) -> StatusCode: - pass - + all_features = {} + for _part_name, vals in self._all_parts.items(): + _features = vals.get('features') + if _features: + all_features.update(_features) + attr_list = [] + for key, val in all_features.items(): + _item = '' + if isinstance(val, bool): + _item = f'{key}={str(val).lower()}' + elif isinstance(val, int): + _item = f'{key}={val}' + elif isinstance(val, str): + _item = f'{key}="{val}"' + else: + raise Exception("part feature '{key}:{val}' type not support.") + attr_list.append(_item) + with open(self._outputs.build_gnargs_prop, 'w') as fobj: + fobj.write('\n'.join(attr_list)) + + # generate features to out/preloader/product_name/features.json def _generate_features_json(self) -> StatusCode: - pass - + all_features = {} + part_feature_map = {} + for _part_name, vals in self._all_parts.items(): + _features = vals.get('features') + if _features: + all_features.update(_features) + if _features: + part_feature_map[_part_name.split(':')[1]] = list(_features.keys()) + parts_feature_info = { + "features": all_features, + "part_to_feature": part_feature_map + } + IoUtil.dump_json_file(self._outputs.features_json, parts_feature_info) + + # generate syscap to out/preloader/product_name/syscap.json def _generate_syscap_json(self) -> StatusCode: - pass - + all_syscap = {} + part_syscap_map = {} + for _part_name, vals in self._all_parts.items(): + _syscap = vals.get('syscap') + if _syscap: + all_syscap.update(_syscap) + part_syscap_map[_part_name.split(':')[1]] = _syscap + parts_syscap_info = { + "syscap": all_syscap, + "part_to_syscap": part_syscap_map + } + IoUtil.dump_json_file(self._outputs.syscap_json, parts_syscap_info) + + # generate exclusion modules info to out/preloader/product_name/exclusion_modules.json def _generate_exclusion_modules_json(self) -> StatusCode: - pass + exclusions = {} + for _part_name, vals in self._all_parts.items(): + _exclusions = vals.get('exclusions') + if _exclusions: + pair = dict() + pair[_part_name] = _exclusions + exclusions.update(pair) + IoUtil.dump_json_file(self._outputs.exclusion_modules_json, exclusions) + + # generate build config info to out/preloader/product_name/build_config.json + def _generate_build_config_json(self) -> StatusCode: + IoUtil.dump_json_file(self._outputs.build_config_json, self._build_vars) - def _generate_subsystem_config_json(self) -> StatusCode: - pass + # generate build prop info to out/preloader/product_name/build.prop + def _generate_build_prop(self) -> StatusCode: + build_vars_list = [] + for k, v in self._build_vars.items(): + build_vars_list.append('{}={}'.format(k, v)) + with open(self._outputs.build_prop, 'w') as fobj: + fobj.write('\n'.join(build_vars_list)) - def _generate_platforms_build(self) -> StatusCode: - pass + # generate parts to out/preloader/product_name/parts.json + def _generate_parts_json(self) -> StatusCode: + parts_info = {"parts": sorted(list(self._all_parts.keys()))} + IoUtil.dump_json_file(self._outputs.parts_json, parts_info) + + # generate parts config to out/preloader/product_name/parts_config.json + def _generate_parts_config_json(self) -> StatusCode: + parts_config = {} + for part in self._all_parts: + part = part.replace(":", "_") + part = part.replace("-", "_") + part = part.replace(".", "_") + part = part.replace("/", "_") + parts_config[part] = True + IoUtil.dump_json_file(self._outputs.parts_config_json, parts_config) + + # generate subsystem config info to out/preloader/product_name/subsystem_config.json + def _generate_subsystem_config_json(self) -> StatusCode: + if self._subsystem_info: + self._subsystem_info.update(self._product._get_product_specific_subsystem()) + self._subsystem_info.update(self._device.get_device_specific_subsystem()) + IoUtil.dump_json_file(self._outputs.subsystem_config_json, self._subsystem_info) + # generate systemcapability_json to out/preloader/product_name/systemcapability.json def _generate_systemcapability_json(self) -> StatusCode: - pass + IoUtil.dump_json_file(self._outputs.systemcapability_json, self._product._syscap_info) + +#get method + + def _get_org_subsystem_info(self): + subsystem_info = {} + if self._os_level == "standard": + subsystem_info = IoUtil.read_json_file(self._dirs.subsystem_config_json) + elif self._os_level == "mini" or self._os_level == "small": + ohos_build_output_dir = os.path.join(self._dirs.preloader_output_dir, + '{}_system'.format(self._os_level)) + subsystem_info = parse_lite_subsystem_config( + self._dirs.lite_components_dir, ohos_build_output_dir, + self._dirs.source_root_dir, self._dirs.subsystem_config_json) + return subsystem_info + + def _get_toolchain_label(self): + if self._os_level == 'mini' or self._os_level == 'small': + toolchain_label = "" + else: + toolchain_label = '//build/toolchain/{0}:{0}_clang_{1}'.format( + self._target_os, self._target_cpu) + return toolchain_label diff --git a/hb_new/util/preloader/parse_lite_subsystems_config.py b/hb_new/util/preloader/parse_lite_subsystems_config.py new file mode 100644 index 0000000000000000000000000000000000000000..49a44766fd5e0d0ba4288759bc4295010f52989c --- /dev/null +++ b/hb_new/util/preloader/parse_lite_subsystems_config.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import os + +from scripts.util.file_utils import read_json_file + + +def _read_lite_component_configs(file): + subsystem_name = os.path.basename(file)[:-5] + configs = {} + configs['subsystem_name'] = subsystem_name + with open(file, 'rb') as fin: + data = json.load(fin) + components = data.get('components') + parts = {} + for com in components: + part = {} + targets = com.get('targets') + test_targets = [] + non_test_targets = [] + for item in targets: + target_names = item.strip('"').split(':') + if len(target_names) > 1 and 'test' in target_names[1]: + test_targets.append(item) + else: + non_test_targets.append(item) + part['module_list'] = non_test_targets + if test_targets != []: + part['test_list'] = test_targets + part_name = com.get('component') + parts[part_name] = part + configs['parts'] = parts + return configs + + +def _save_as_ohos_build(config, ohos_build): + new_config = json.dumps(config, indent=2, sort_keys=True) + with open(ohos_build, 'w') as fout: + fout.write(new_config) + + +def parse_lite_subsystem_config(lite_components_dir, output_dir, + source_root_dir, subsystem_config_file): + subsystem_infos = read_json_file(subsystem_config_file) + for root, _, files in os.walk(lite_components_dir): + for file in files: + if file[-5:] == '.json': + configs = _read_lite_component_configs(os.path.join( + root, file)) + subsystem_name = configs.get('subsystem_name') + ohos_build = os.path.join( + output_dir, '{}/ohos.build'.format(subsystem_name)) + os.makedirs(os.path.dirname(ohos_build), exist_ok=True) + _save_as_ohos_build(configs, ohos_build) + subsystem_infos[subsystem_name] = { + 'name': + subsystem_name, + "path": + os.path.relpath(os.path.dirname(ohos_build), + source_root_dir), + } + return subsystem_infos diff --git a/hb_new/util/preloader/parse_vendor_product_config.py b/hb_new/util/preloader/parse_vendor_product_config.py new file mode 100644 index 0000000000000000000000000000000000000000..7ff2ceb2206c486f142b8d38582570fa82543724 --- /dev/null +++ b/hb_new/util/preloader/parse_vendor_product_config.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import sys +import json +import re +import os + + +def get_features(features): + feats = {} + for feat in features: + if not feat: + continue + match = feat.index("=") + if match <= 0: + print("Warning: invalid feature [" + feat + "]") + continue + key = feat[:match].strip() + val = feat[match + 1:].strip().strip('"') + if val == 'true': + feats[key] = True + elif val == 'false': + feats[key] = False + elif re.match(r'[0-9]+', val): + feats[key] = int(val) + else: + feats[key] = val.replace('\"', '"') + + pairs = dict() + pairs['features'] = feats + return pairs + + +def get_syscap(syscap): + feats = {} + for feat in syscap: + if not feat: + continue + if '=' not in feat: + raise Exception("Error: invalid syscap [{}]".format(feat)) + match = feat.index("=") + key = feat[:match].strip() + val = feat[match + 1:].strip().strip('"') + if val == 'true': + feats[key] = True + elif val == 'false': + feats[key] = False + elif re.match(r'[0-9]+', val): + feats[key] = int(val) + else: + feats[key] = val.replace('\"', '"') + + pairs = dict() + pairs['syscap'] = feats + return pairs + + +def get_exclusion_modules(exclusions): + pairs = dict() + pairs['exclusions'] = exclusions + return pairs + + +def from_ss_to_parts(subsystems): + parts = dict() + for subsystem in subsystems: + ss_name = subsystem.get('subsystem') + components = subsystem.get('components') + if components: + for com in components: + com_name = com.get('component') + features = com.get('features') + syscap = com.get('syscap') + exclusions = com.get('exclusions') + if features: + pairs = get_features(features) + parts['{}:{}'.format(ss_name, com_name)] = pairs + else: + parts['{}:{}'.format(ss_name, com_name)] = dict() + if syscap: + pairs = get_syscap(syscap) + parts.get('{}:{}'.format(ss_name, com_name)).update(pairs) + if exclusions: + pairs = get_exclusion_modules(exclusions) + parts.get('{}:{}'.format(ss_name, com_name)).update(pairs) + # Copy other key-values + for key, val in com.items(): + if key in ['component', 'features', 'syscap', 'exclusions']: + continue + parts['{}:{}'.format(ss_name, com_name)][key] = val + return parts + + +def transform(config): + subsystems = config.get('subsystems') + if subsystems: + config.pop('subsystems') + parts = from_ss_to_parts(subsystems) + config['parts'] = parts + return config + + +def save_transformed_config(config, output_file): + new_config = json.dumps(config, indent=2, sort_keys=True) + with open(output_file, 'wt') as fout: + fout.write(new_config) + + +def get_product_config(config_dir, product_name, company): + company_path = os.path.join(config_dir, company) + if not os.path.isdir(company_path): + raise Exception(f'Error: {company_path} is not a directory') + + for product in os.listdir(company_path): + product_path = os.path.join(company_path, product) + config_json = os.path.join(product_path, 'config.json') + + if os.path.isfile(config_json): + with open(config_json, 'rb') as fin: + config = json.load(fin) + if product_name == config.get('product_name'): + return config + raise Exception(f'Error: failed to get product config for {product_name}') + + +def get_vendor_parts_list(config): + return transform(config).get('parts') + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--product-name', required=True) + parser.add_argument('--company', required=True) + parser.add_argument('--config-dir', required=True) + options = parser.parse_args() + config = get_product_config(options.config_dir, options.product_name, + options.company) + get_vendor_parts_list(config) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/hb_new/util/preloader/preloader_process_data.py b/hb_new/util/preloader/preloader_process_data.py new file mode 100644 index 0000000000000000000000000000000000000000..7856a334fb829842cfe81938037670512b293039 --- /dev/null +++ b/hb_new/util/preloader/preloader_process_data.py @@ -0,0 +1,357 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +from util.ioUtil import IoUtil +from util.preloader import parse_lite_subsystems_config +from util.preloader.parse_vendor_product_config import get_vendor_parts_list + +class Outputs: + + def __init__(self, output_dir): + self.__post_init__(output_dir) + + def __post_init__(self, output_dir): + self.build_prop = os.path.join(output_dir, 'build.prop') + self.build_config_json = os.path.join(output_dir, 'build_config.json') + self.parts_json = os.path.join(output_dir, 'parts.json') + self.parts_config_json = os.path.join(output_dir, 'parts_config.json') + self.build_gnargs_prop = os.path.join(output_dir, 'build_gnargs.prop') + self.features_json = os.path.join(output_dir, 'features.json') + self.syscap_json = os.path.join(output_dir, 'syscap.json') + self.exclusion_modules_json = os.path.join(output_dir, + 'exclusion_modules.json') + self.subsystem_config_json = os.path.join(output_dir, + 'subsystem_config.json') + self.platforms_build = os.path.join(output_dir, 'platforms.build') + self.systemcapability_json = os.path.join(output_dir, 'SystemCapability.json') + + +class Dirs: + + def __init__(self, config): + self.__post_init__(config) + + def __post_init__(self, config): + self.source_root_dir = config.root_path + self.built_in_product_dir = config.built_in_product_path + self.productdefine_dir = os.path.join(self.source_root_dir, 'productdefine/common') + self.built_in_device_dir = config.built_in_device_path + self.built_in_base_dir = os.path.join(self.productdefine_dir, 'base') + + # Configs of vendor specified products are stored in ${vendor_dir} directory. + self.vendor_dir = config.vendor_path + # Configs of device specified products are stored in ${device_dir} directory. + self.device_dir = os.path.join(config.root_path, 'device') + + self.subsystem_config_json = os.path.join(config.root_path, config.subsystem_config_json) + self.lite_components_dir = os.path.join(config.root_path, 'build/lite/components') + + self.preloader_output_dir = os.path.join(config.root_path, 'out/preloader', config.product) + + +class Product(): + + def __init__(self, product_name, config_dirs, config_json): + self._name = product_name + self._dirs = config_dirs + self._device = None + self._config = {} + self._build_vars = {} + self._parts = {} + self._syscap_info = {} + self._parsed = False + self._config_file = config_json + + def _sanitize(self, config): + if config and self._name != config.get('product_name'): + raise Exception( + "product name configuration incorrect for '{}'".format( + self._name)) + + def _get_base_parts(self, base_config_dir, os_level): + system_base_config_file = os.path.join(base_config_dir, + '{}_system.json'.format(os_level)) + if not os.path.exists(system_base_config_file): + raise Exception("product configuration '{}' doesn't exist.".format( + system_base_config_file)) + return IoUtil.read_json_file(system_base_config_file) + + def _get_inherit_parts(self, inherit, source_root_dir): + inherit_parts = {} + for _config in inherit: + _file = os.path.join(source_root_dir, _config) + _info = IoUtil.read_json_file(_file) + parts = _info.get('parts') + if parts: + inherit_parts.update(parts) + else: + inherit_parts.update(get_vendor_parts_list(_info)) + return inherit_parts + + def _get_sys_relate_parts(self, system_component_info, _parts, source_root_dir): + _info = IoUtil.read_json_file(os.path.join(source_root_dir, system_component_info)) + ret = {} + parts = _info.get('parts') + if not parts: + parts = get_vendor_parts_list(_info) + for part, featrue in parts.items(): + if not _parts.get(part): + ret[part] = featrue + return ret + + def _get_product_specific_parts(self): + part_name = 'product_{}'.format(self._name) + subsystem_name = part_name + info = {} + info['{}:{}'.format(subsystem_name, part_name)] = {} + return info + + def _get_product_specific_subsystem(self): + info = {} + self._do_parse() + subsystem_name = 'product_{}'.format(self._name) + if self._get_product_build_path(): + info[subsystem_name] = { + 'name': subsystem_name, + 'path': self._get_product_build_path() + } + return info + + def _get_product_build_path(self): + return self._config.get('product_build_path') + + def _get_parts_and_build_vars(self): + self._config = IoUtil.read_json_file(self._config_file) + version = self._config.get('version', '3.0') + self._update_parts(self._config, version) + self._update_build_vars(self._config, version) + return self._parts, self._build_vars + + def _get_device(self): + self._do_parse() + return self._device + + def _remove_excluded_components(self): + items_to_remove = [] + for part, val in self._parts.items(): + if "exclude" in val and val["exclude"] == "true": + items_to_remove.append(part) + for item in items_to_remove: + del self._parts[item] + + def _do_parse(self): + self._config = IoUtil.read_json_file(self._config_file) + version = self._config.get('version', '3.0') + product_name = self._config.get('product_name') + if product_name == None: + product_name = "" + os_level = self._config.get('type') + if os_level == None: + os_level = "" + api_version = self._config.get('api_version') + if api_version == None: + api_version = 0 + manufacturer_id = self._config.get('manufacturer_id') + if manufacturer_id == None: + manufacturer_id = 0 + self._syscap_info = {'product': product_name, 'api_version': api_version, + 'system_type': os_level, 'manufacturer_id': manufacturer_id} + + self._sanitize(self._config) + self._update_device(self._config, version) + self._update_parts(self._config, version) + self._update_build_vars(self._config, version) + if version == '3.0': + if os.path.dirname(self._config_file) != self._dirs.built_in_product_dir and not hasattr(self._config, + 'product_build_path'): + self._config['product_build_path'] = os.path.relpath(os.path.dirname(self._config_file), + self._dirs.source_root_dir) + self._remove_excluded_components() + self._parsed = True + + # Generate build_info needed for V3 configuration + def _get_device_info(self, config): + # NOTE: + # Product_name, device_company are necessary for + # config.json, DON NOT use .get to replace [] + device_info = { + 'device_name': config['board'], + 'device_company': config['device_company'] + } + if config.get('target_os'): + device_info['target_os'] = config.get('target_os') + else: + device_info['target_os'] = 'ohos' + if config.get('target_cpu'): + device_info['target_cpu'] = config['target_cpu'] + else: + # Target cpu is used to set default toolchain for standard system. + print( + "The target_cpu needs to be specified, default target_cpu=arm") + device_info['target_cpu'] = 'arm' + if config.get('kernel_version'): + device_info['kernel_version'] = config.get('kernel_version') + if config.get('device_build_path'): + device_info['device_build_path'] = config.get('device_build_path') + else: + device_build_path = os.path.join(self._dirs.device_dir, + config['device_company'], + config['board']) + if not os.path.exists(device_build_path): + device_build_path = os.path.join(self._dirs.device_dir, + 'board', + config['device_company'], + config['board']) + device_info['device_build_path'] = device_build_path + return device_info + + # Update the _build_vars based on the product configuration in the vendor warehouse + def _update_build_vars(self, config, version): + build_vars = {} + if version == "1.0": + build_vars = {"os_level": 'large'} + else: + if version == "2.0": + build_vars['os_level'] = config.get("type", "standard") + device_name = config.get('product_device') + if device_name: + build_vars['device_name'] = device_name + else: + build_vars['device_name'] = '' + build_vars['product_company'] = config.get('product_company') + else: + build_vars['os_level'] = config.get('type', 'mini') + build_vars['device_name'] = config.get('board') + if config.get('product_company'): + build_vars['product_company'] = config.get('product_company') + elif os.path.dirname(self._config_file) != self._dirs.built_in_product_dir: + relpath = os.path.relpath(self._config_file, self._dirs.vendor_dir) + build_vars['product_company'] = relpath.split('/')[0] + else: + build_vars['product_company'] = config.get('device_company') + build_vars['product_name'] = config.get('product_name') + if 'enable_ramdisk' in config: + build_vars['enable_ramdisk'] = config.get('enable_ramdisk') + if 'build_selinux' in config: + build_vars['build_selinux'] = config.get('build_selinux') + if 'build_seccomp' in config: + build_vars['build_seccomp'] = config.get('build_seccomp') + if 'support_jsapi' in config: + build_vars['support_jsapi'] = config.get('support_jsapi') + self._build_vars = build_vars + + # Update the _device based on the product configuration in the vendor warehouse + def _update_device(self, config, version): + if version == "2.0": + device_name = config.get('product_device') + if device_name: + self._device = _MyDevice(device_name, self._dirs) + else: + device_name = config.get('board') + if device_name: + device_info = self._get_device_info(config) + self._device = _MyDevice(device_name, self._dirs, device_info) + + # Update the _parts based on the product configuration in the vendor warehouse + def _update_parts(self, config, version): + if version == "1.0": + _parts = {} + self._parts = _parts + else: + # 1. inherit parts information from base config + if version == "2.0": + os_level = config.get("type", "standard") + else: + os_level = config.get("type", "mini") + # 2. product config based on default minimum system + based_on_mininum_system = config.get('based_on_mininum_system') + if based_on_mininum_system == "true": + self._parts = self._get_base_parts(self._dirs.built_in_base_dir, os_level) + # 3. inherit parts information from inherit config + inherit = config.get('inherit') + if inherit: + self._parts.update( + self._get_inherit_parts(inherit, self._dirs.source_root_dir)) + + # 4. chipset products relate system parts config + sys_info_path = config.get('system_component') + if sys_info_path: + sys_parts = self._get_sys_relate_parts(sys_info_path, self._parts, self._dirs.source_root_dir) + self._parts.update(sys_parts) + all_parts = {} + if version == "2.0": + current_product_parts = config.get("parts") + if current_product_parts: + all_parts.update(current_product_parts) + else: + all_parts.update(get_vendor_parts_list(config)) + all_parts.update(self._get_product_specific_parts()) + + device_name = config.get('board') + if device_name: + all_parts.update(self._device.get_device_specific_parts()) + self._parts.update(all_parts) + + +class _MyDevice(): + + def __init__(self, device_name, config_dirs, device_info=None): + self._name = device_name + self._dirs = config_dirs + if device_info is None: + self._device_info = self._make_device_info( + self._name, self._dirs.built_in_device_dir) + else: + self._device_info = device_info + + def get_device_info(self): + return self._device_info + + def _make_device_info(self, device_name, config_dir): + device_config_file = os.path.join(config_dir, + '{}.json'.format(device_name)) + device_info = IoUtil.read_json_file(device_config_file) + if device_info and device_info.get('device_name') != device_name: + raise Exception("device name configuration incorrect in '{}'".format( + device_config_file)) + return device_info + + def get_device_specific_parts(self): + info = {} + if self._device_info: + device_build_path = self._device_info.get('device_build_path') + if device_build_path: + subsystem_name = 'device_{}'.format(self._name) + part_name = subsystem_name + info['{}:{}'.format(subsystem_name, part_name)] = {} + return info + + def get_device_specific_subsystem(self): + info = {} + subsystem_name = 'device_{}'.format(self._name) + if self._get_device_build_path(): + info[subsystem_name] = { + 'name': subsystem_name, + 'path': self._get_device_build_path() + } + return info + + def _get_device_build_path(self): + if self._device_info: + return self._device_info.get('device_build_path') + else: + return None \ No newline at end of file