• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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
18import argparse
19import shutil
20sys.path.append(
21    os.path.dirname(os.path.dirname(os.path.dirname(
22        os.path.abspath(__file__)))))
23from scripts.util.file_utils import write_file  # noqa: E402
24from scripts.util import build_utils  # noqa: E402
25
26
27def copy_file(target_base_dir, source_files, output_dir):
28    output_files = []
29    for src_file in source_files:
30        if not os.path.exists(src_file):
31            raise Exception("src file '{}' doesn't exist.".format(src_file))
32        relative_path = os.path.relpath(src_file, target_base_dir)
33        output_file = os.path.join(output_dir, relative_path)
34        dest_dir = os.path.dirname(output_file)
35        if not os.path.exists(dest_dir):
36            os.makedirs(dest_dir, exist_ok=True)
37        shutil.copy2(src_file, output_file)
38        output_files.append(output_file)
39    return output_files
40
41
42def main():
43    parser = argparse.ArgumentParser()
44    parser.add_argument('--target-base-dir', required=True)
45    parser.add_argument('--source-files', nargs='+', required=True)
46    parser.add_argument('--copy-output-dir', required=True)
47    parser.add_argument('--outfile', required=True)
48    parser.add_argument('--depfile', required=False)
49    args = parser.parse_args()
50
51    copy_out_list = copy_file(args.target_base_dir, args.source_files,
52                              args.copy_output_dir)
53    write_file(args.outfile, '\n'.join(copy_out_list))
54
55    if args.depfile:
56        _dep_files = (args.source_files + copy_out_list).sort()
57        build_utils.write_depfile(args.depfile,
58                                 args.outfile,
59                                 _dep_files,
60                                 add_pydeps=False)
61    return 0
62
63
64if __name__ == '__main__':
65    sys.exit(main())
66