• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import sys
17import os
18
19sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
20from scripts.util import file_utils  # noqa: E402
21
22
23class BundlePartObj(object):
24    def __init__(self, bundle_config_file, exclusion_modules_config_file, load_test_config):
25        self._build_config_file = bundle_config_file
26        self._exclusion_modules_config_file = exclusion_modules_config_file
27        self._load_test_config = load_test_config
28        self._loading_config()
29
30    def _loading_config(self):
31        if not os.path.exists(self._build_config_file):
32            raise Exception("file '{}' doesn't exist.".format(
33                self._build_config_file))
34        self.bundle_info = file_utils.read_json_file(self._build_config_file)
35        if self.bundle_info is None:
36            raise Exception("read file '{}' failed.".format(
37                self._build_config_file))
38        self._check_format()
39        self.exclusion_modules_info = file_utils.read_json_file(
40            self._exclusion_modules_config_file)
41
42    def _check_format(self):
43        _tip_info = "bundle.json info is incorrect in '{}'".format(
44            self._build_config_file)
45        if 'component' not in self.bundle_info:
46            raise Exception("{}, 'component' is required.".format(_tip_info))
47        _component_info = self.bundle_info.get('component')
48        if 'name' not in _component_info:
49            raise Exception(
50                "{}, 'component.name' is required.".format(_tip_info))
51        if 'subsystem' not in _component_info:
52            raise Exception(
53                "{}, 'component.subsystem' is required.".format(_tip_info))
54        if 'build' not in _component_info:
55            raise Exception(
56                "{}, 'component.build' is required.".format(_tip_info))
57        _bundle_build = _component_info.get('build')
58        if 'sub_component' not in _bundle_build and 'group_type' not in _bundle_build:
59            raise Exception(
60                "{}, 'component.build.sub_component' or 'component.build.group_type' is required.".format(
61                    _tip_info))
62        if 'group_type' in _bundle_build:
63            group_list = ['base_group', 'fwk_group', 'service_group']
64            _module_groups = _bundle_build.get('group_type')
65            for _group_type, _module_list in _module_groups.items():
66                if _group_type not in group_list:
67                    raise Exception("{}, incorrect group type".format(_tip_info))
68
69    def to_ohos_build(self):
70        _component_info = self.bundle_info.get('component')
71        _subsystem_name = _component_info.get('subsystem')
72        _part_name = _component_info.get('name')
73        _bundle_build = _component_info.get('build')
74        _exclusion_modules_info = self.exclusion_modules_info
75        _ohos_build_info = {}
76        _ohos_build_info['subsystem'] = _subsystem_name
77        _part_info = {}
78        module_list = []
79        if _component_info.get('build').__contains__('sub_component'):
80            _part_info['module_list'] = _component_info.get('build').get(
81                'sub_component')
82        elif _component_info.get('build').__contains__('group_type'):
83            _module_groups = _component_info.get('build').get('group_type')
84            for _group_type, _module_list in _module_groups.items():
85                _key = '{}:{}'.format(_subsystem_name, _part_name)
86                if not _exclusion_modules_info.get(_key):
87                    module_list.extend(_module_list)
88                elif _group_type not in _exclusion_modules_info.get(_key):
89                    module_list.extend(_module_list)
90            _part_info['module_list'] = module_list
91        if 'inner_kits' in _bundle_build:
92            _part_info['inner_kits'] = _bundle_build.get('inner_kits')
93        if 'test' in _bundle_build and self._load_test_config:
94            _part_info['test_list'] = _bundle_build.get('test')
95        if 'features' in _component_info:
96            _part_info['feature_list'] = _component_info.get('features')
97        if 'syscap' in _component_info:
98            _part_info['system_capabilities'] = _component_info.get('syscap')
99        if 'hisysevent_config' in _component_info:
100            _part_info['hisysevent_config'] = _component_info.get('hisysevent_config')
101        _ohos_build_info['parts'] = {_part_name: _part_info}
102        return _ohos_build_info
103