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 os
18import argparse
19import shutil
20import subprocess
21import multiprocessing
22sys.path.append(
23    os.path.dirname(os.path.dirname(os.path.dirname(
24        os.path.abspath(__file__)))))
25
26
27def copytree(source: str, destination: str):
28    shutil.copytree(source, destination, dirs_exist_ok=True)
29
30
31def copy_file(fuzz_config_file_path: str, fuzz_config_file_output_path: str):
32    if not os.path.exists(fuzz_config_file_path):
33        raise Exception("fuzz_config_file_path '{}' doesn't exist.".format(fuzz_config_file_path))
34    target_file_path = os.path.join(fuzz_config_file_output_path, os.path.basename(fuzz_config_file_path))
35    try:
36        p = multiprocessing.Process(target=copytree, args=(fuzz_config_file_path, target_file_path))
37        p.start()
38        p.join()
39    except Exception as e:
40        subprocess.call(["cp", "-rf", fuzz_config_file_path, fuzz_config_file_output_path])
41
42
43def main():
44    parser = argparse.ArgumentParser()
45    parser.add_argument('--fuzz-config-file-path', required=True)
46    parser.add_argument('--fuzz-config-file-output-path', required=True)
47    args = parser.parse_args()
48
49    copy_file(args.fuzz_config_file_path, args.fuzz_config_file_output_path)
50    return 0
51
52
53if __name__ == '__main__':
54    sys.exit(main())
55