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