• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2022 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 argparse
18import os
19import subprocess
20
21sys.path.append(
22    os.path.dirname(os.path.dirname(os.path.dirname(
23        os.path.abspath(__file__)))))
24from scripts.util.file_utils import read_json_file, write_json_file  # noqa: E402
25
26
27def _do_symlink(all_host_parts_info: str, output_file: str, root_build_dir: str):
28    output_result = {}
29    for part_info in all_host_parts_info:
30        part_info_file = part_info.get('part_info_file')
31        part_modules_host_info = read_json_file(part_info_file)
32        for info in part_modules_host_info:
33            if info:
34                module_def = info.get('module_def')
35                module_info_file = info.get('module_info_file')
36                module_info = read_json_file(module_info_file)
37                if 'symlink' in module_info:
38                    source_file = module_info.get('source')
39                    source_file = os.path.join(root_build_dir, source_file)
40                    symlink_dest = module_info.get('symlink')
41
42                    for name in symlink_dest:
43                        symlink_dest_dir = os.path.dirname(source_file)
44                        symlink_dest_file = os.path.join(root_build_dir, symlink_dest_dir, name)
45                        if not os.path.exists(symlink_dest_file):
46                            subprocess.run(['ln', '-sf', str(source_file), str(symlink_dest_file)])
47                            output_result[symlink_dest_file] = str(source_file)
48    write_json_file(output_file, output_result)
49
50
51def main():
52    parser = argparse.ArgumentParser()
53    parser.add_argument('--all-parts-host-info-file', required=True)
54    parser.add_argument('--output-file', required=True)
55    parser.add_argument('--root-build-dir', required=True)
56    args = parser.parse_args()
57    all_host_parts_info = read_json_file(args.all_parts_host_info_file)
58    _do_symlink(all_host_parts_info, args.output_file, args.root_build_dir)
59    return 0
60
61
62if __name__ == '__main__':
63    sys.exit(main())
64