106f6ba60Sopenharmony_ci#!/usr/bin/env python 206f6ba60Sopenharmony_ci# -*- coding: utf-8 -*- 306f6ba60Sopenharmony_ci# Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. 406f6ba60Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 506f6ba60Sopenharmony_ci# you may not use this file except in compliance with the License. 606f6ba60Sopenharmony_ci# You may obtain a copy of the License at 706f6ba60Sopenharmony_ci# 806f6ba60Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 906f6ba60Sopenharmony_ci# 1006f6ba60Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1106f6ba60Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1206f6ba60Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1306f6ba60Sopenharmony_ci# See the License for the specific language governing permissions and 1406f6ba60Sopenharmony_ci# limitations under the License. 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ciimport os 1706f6ba60Sopenharmony_ciimport sys 1806f6ba60Sopenharmony_ciimport getopt 1906f6ba60Sopenharmony_ciimport fstrace_code_generator as fstrace 2006f6ba60Sopenharmony_ci 2106f6ba60Sopenharmony_ciFSTRACE_PROGS_FILE = "../include/fstrace_progs.h" 2206f6ba60Sopenharmony_ciFSTRACE_TYPES_FILE = "../include/fstrace_types.h" 2306f6ba60Sopenharmony_ciFSTRACE_TARGETS_FILE = "../data/fstrace_target_funcs.txt" 2406f6ba60Sopenharmony_ciOVERWRITE = False 2506f6ba60Sopenharmony_ciLICENSE_HEAD = '''/* 2606f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. 2706f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 2806f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 2906f6ba60Sopenharmony_ci * You may obtain a copy of the License at 3006f6ba60Sopenharmony_ci * 3106f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 3206f6ba60Sopenharmony_ci * 3306f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 3406f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 3506f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 3606f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 3706f6ba60Sopenharmony_ci * limitations under the License. 3806f6ba60Sopenharmony_ci */ 3906f6ba60Sopenharmony_ci 4006f6ba60Sopenharmony_ci''' 4106f6ba60Sopenharmony_ci 4206f6ba60Sopenharmony_ciif __name__ == '__main__': 4306f6ba60Sopenharmony_ci opt_list = [ 4406f6ba60Sopenharmony_ci 'progs-out-file=', 4506f6ba60Sopenharmony_ci 'fstrace-out-file=', 4606f6ba60Sopenharmony_ci 'fstrace-targets-file=', 4706f6ba60Sopenharmony_ci 'overwrite=', 4806f6ba60Sopenharmony_ci ] 4906f6ba60Sopenharmony_ci opt_names = [ 5006f6ba60Sopenharmony_ci '--progs-out-file', 5106f6ba60Sopenharmony_ci '--fstrace-out-file', 5206f6ba60Sopenharmony_ci '--fstrace-targets-file', 5306f6ba60Sopenharmony_ci '--overwrite', 5406f6ba60Sopenharmony_ci ] 5506f6ba60Sopenharmony_ci opts, args = getopt.getopt(sys.argv[1:], '', opt_list) 5606f6ba60Sopenharmony_ci for opt, val in opts: 5706f6ba60Sopenharmony_ci if opt == opt_names[0]: 5806f6ba60Sopenharmony_ci FSTRACE_PROGS_FILE = val 5906f6ba60Sopenharmony_ci if opt == opt_names[1]: 6006f6ba60Sopenharmony_ci FSTRACE_TYPES_FILE = val 6106f6ba60Sopenharmony_ci if opt == opt_names[2]: 6206f6ba60Sopenharmony_ci FSTRACE_TARGETS_FILE = val 6306f6ba60Sopenharmony_ci if opt == opt_names[3] and val == "true": 6406f6ba60Sopenharmony_ci OVERWRITE = True 6506f6ba60Sopenharmony_ci 6606f6ba60Sopenharmony_ci PROGS_FILE_EXISTS = os.path.exists(FSTRACE_PROGS_FILE) 6706f6ba60Sopenharmony_ci TYPES_FILE_EXISTS = os.path.exists(FSTRACE_TYPES_FILE) 6806f6ba60Sopenharmony_ci FILE_EXISTS = PROGS_FILE_EXISTS or TYPES_FILE_EXISTS 6906f6ba60Sopenharmony_ci if OVERWRITE or not FILE_EXISTS: 7006f6ba60Sopenharmony_ci with open(FSTRACE_PROGS_FILE, 'w') as progs_ouf: 7106f6ba60Sopenharmony_ci HEAD_LINE = '/* This line is generated to truncate the original file */\n' 7206f6ba60Sopenharmony_ci progs_ouf.write(LICENSE_HEAD) 7306f6ba60Sopenharmony_ci progs_ouf.write(HEAD_LINE) 7406f6ba60Sopenharmony_ci with open(FSTRACE_TYPES_FILE, 'w') as fstrace_ouf: 7506f6ba60Sopenharmony_ci HEAD_LINE = '/* This line is generated to truncate the original file */\n' 7606f6ba60Sopenharmony_ci fstrace_ouf.write(LICENSE_HEAD) 7706f6ba60Sopenharmony_ci fstrace_ouf.write(HEAD_LINE) 7806f6ba60Sopenharmony_ci fstrace.output_fstrace_code(FSTRACE_PROGS_FILE, FSTRACE_TYPES_FILE, FSTRACE_TARGETS_FILE)