1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#
5# Copyright (c) 2021 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import sys
21import subprocess
22
23
24def main(argv):
25    if len(argv) < 3:
26        print("argv count error, return!")
27        return
28    input_file = argv[1] + "/all_plugin_static.h.in"
29    output_file = argv[2] + "/all_plugin_static.h"
30    static_declare = []
31    static_register = []
32    static_unregister = []
33    if not os.path.isfile(input_file):
34        print("input file is not exist, return!")
35        return
36    if not os.path.exists(argv[2]):
37        os.makedirs(argv[2])
38    for i in range(3, len(argv)):
39        static_declare += "PLUGIN_REGISTER_STATIC_DECLARE(%s);" % argv[i]
40        static_register += "REGISTER_STATIC(%s, reg);" % argv[i]
41        static_unregister += "UNREGISTER_STATIC(%s);" % argv[i]
42    with open(input_file, "r") as infile:
43        with open(output_file, "w") as outfile:
44            for line in infile:
45                if '@HISTREAMER_PLUGIN_STATIC_DECLARE@' in line:
46                    outfile.write("".join(static_declare))
47                elif '@HISTREAMER_PLUGIN_REGISTER_STATIC@' in line:
48                    outfile.write("(void)(reg);")
49                    outfile.write("".join(static_register))
50                elif '@HISTREAMER_PLUGIN_UNREGISTER_STATIC@' in line:
51                    outfile.write("".join(static_unregister))
52                else:
53                    outfile.write(line)
54
55if __name__ == '__main__':
56    sys.exit(main(sys.argv))
57
58