• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#   Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
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 os
17import sys
18import getopt
19import fstrace_code_generator as fstrace
20
21FSTRACE_PROGS_FILE = "../include/fstrace_progs.h"
22FSTRACE_TYPES_FILE = "../include/fstrace_types.h"
23FSTRACE_TARGETS_FILE = "../data/fstrace_target_funcs.txt"
24OVERWRITE = False
25LICENSE_HEAD = '''/*
26 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
27 * Licensed under the Apache License, Version 2.0 (the "License");
28 * you may not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 *     http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS,
35 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
38 */
39
40'''
41
42if __name__ == '__main__':
43    opt_list = [
44        'progs-out-file=',
45        'fstrace-out-file=',
46        'fstrace-targets-file=',
47        'overwrite=',
48    ]
49    opt_names = [
50        '--progs-out-file',
51        '--fstrace-out-file',
52        '--fstrace-targets-file',
53        '--overwrite',
54    ]
55    opts, args = getopt.getopt(sys.argv[1:], '', opt_list)
56    for opt, val in opts:
57        if opt == opt_names[0]:
58            FSTRACE_PROGS_FILE = val
59        if opt == opt_names[1]:
60            FSTRACE_TYPES_FILE = val
61        if opt == opt_names[2]:
62            FSTRACE_TARGETS_FILE = val
63        if opt == opt_names[3] and val == "true":
64            OVERWRITE = True
65
66    PROGS_FILE_EXISTS = os.path.exists(FSTRACE_PROGS_FILE)
67    TYPES_FILE_EXISTS = os.path.exists(FSTRACE_TYPES_FILE)
68    FILE_EXISTS = PROGS_FILE_EXISTS or TYPES_FILE_EXISTS
69    if OVERWRITE or not FILE_EXISTS:
70        with open(FSTRACE_PROGS_FILE, 'w') as progs_ouf:
71            HEAD_LINE = '/* This line is generated to truncate the original file */\n'
72            progs_ouf.write(LICENSE_HEAD)
73            progs_ouf.write(HEAD_LINE)
74        with open(FSTRACE_TYPES_FILE, 'w') as fstrace_ouf:
75            HEAD_LINE = '/* This line is generated to truncate the original file */\n'
76            fstrace_ouf.write(LICENSE_HEAD)
77            fstrace_ouf.write(HEAD_LINE)
78        fstrace.output_fstrace_code(FSTRACE_PROGS_FILE, FSTRACE_TYPES_FILE, FSTRACE_TARGETS_FILE)