• 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(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21from scripts.util.file_utils import write_file  # noqa: E402
22from scripts.util import build_utils  # noqa: E402
23
24
25def copy_files(source_files, output_dir):
26    output_files = []
27    for src_file in source_files:
28        if not os.path.exists(src_file):
29            raise Exception("src file '{}' doesn't exist.".format(src_file))
30        if not os.path.isfile(src_file):
31            continue
32        file_name = os.path.basename(src_file)
33        output_file = os.path.join(output_dir, file_name)
34        if not os.path.exists(output_dir):
35            os.makedirs(output_dir, exist_ok=True)
36        shutil.copy2(src_file, output_file)
37        output_files.append(output_file)
38    return output_files
39
40
41def main():
42    parser = argparse.ArgumentParser()
43    parser.add_argument('--source-files', nargs='+', required=True)
44    parser.add_argument('--copy-output-dir', required=True)
45    parser.add_argument('--outfile', required=True)
46    parser.add_argument('--depfile', required=False)
47    args = parser.parse_args()
48
49    copy_out_list = copy_files(args.source_files, args.copy_output_dir)
50    write_file(args.outfile, '\n'.join(copy_out_list))
51
52    if args.depfile:
53        _dep_files = []
54        _dep_files.extend(args.source_files)
55        _dep_files.extend(copy_out_list)
56        _dep_files.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