From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6C1B7A2EDB for ; Mon, 30 Sep 2019 11:22:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CE03437B4; Mon, 30 Sep 2019 11:22:37 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 125C334F3 for ; Mon, 30 Sep 2019 11:22:34 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Sep 2019 02:22:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,565,1559545200"; d="scan'208";a="204792623" Received: from baranmx-mobl.ger.corp.intel.com ([10.103.104.83]) by fmsmga001.fm.intel.com with ESMTP; 30 Sep 2019 02:22:33 -0700 From: Marcin Baran To: dev@dpdk.org, bruce.richardson@intel.com, ray.kinsella@intel.com Cc: Pawel Modrak Date: Mon, 30 Sep 2019 11:21:33 +0200 Message-Id: <20190930092139.2440-2-marcinx.baran@intel.com> X-Mailer: git-send-email 2.22.0.windows.1 In-Reply-To: <20190930092139.2440-1-marcinx.baran@intel.com> References: <20190930092139.2440-1-marcinx.baran@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/8] buildtools: scripts for updating symbols abi version X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Pawel Modrak The scripts updates version number for binding symbols and version map files. Signed-off-by: Pawel Modrak --- buildtools/update_default_symbol_abi.py | 57 ++++++++++++ buildtools/update_version_map_abi.py | 110 ++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100755 buildtools/update_default_symbol_abi.py create mode 100755 buildtools/update_version_map_abi.py diff --git a/buildtools/update_default_symbol_abi.py b/buildtools/update_default_symbol_abi.py new file mode 100755 index 000000000..6fe60d8cd --- /dev/null +++ b/buildtools/update_default_symbol_abi.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2019 Intel Corporation + +from __future__ import print_function +import sys +import argparse +import re + +def setup_options(): + arg_parser = argparse.ArgumentParser(description='Update default bind symbol abi version.') + arg_parser.add_argument('map_file', metavar='map_file', type=str, nargs=1, + help='path to source file (pattern: *.c)') + arg_parser.add_argument('dst_abi_version', metavar='dst_abi_version', type=str, nargs=1, + help='target ABI version (pattern: DPDK_*)') + arg_parser.add_argument('-v', '--verbose', action='store_true', help='print changes') + + return arg_parser.parse_args() + +def replace_abi(f_in, abi_version_number, verbose): + source_file_content = [] + + for ln_no, ln in enumerate(f_in, 1): + if re.search("^BIND_DEFAULT_SYMBOL\(.*", ln): + source_file_content += [re.sub(", [0-9]{1,2}\.[0-9]{1,2}\);$", ", " + abi_version_number + ");", ln)] + if verbose: + print(f_in.name + ":" + str(ln_no) + ": " + ln[:-1] + " -> " + source_file_content[-1][:-1]) + elif re.search("^VERSION_SYMBOL\(.*", ln): + if verbose: + print(f_in.name + ":" + str(ln_no) + ": " + ln[:-1] + " -> " + "[DELETED]") + else: + source_file_content += [ln] + + return source_file_content + +def main(args): + params = setup_options() + + if not params.map_file[0].endswith('.c') or \ + not params.dst_abi_version[0].startswith('DPDK_'): + print('Wrong pattern for input files!\n') + arg_parser.print_help() + return 1 + + abi_version_number = params.dst_abi_version[0][5:] + source_file_content = [] + + with open(params.map_file[0]) as f_in: + source_file_content = replace_abi(f_in, abi_version_number, params.verbose) + + with open(params.map_file[0], 'w') as f_out: + f_out.writelines(source_file_content) + + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/buildtools/update_version_map_abi.py b/buildtools/update_version_map_abi.py new file mode 100755 index 000000000..5a840e766 --- /dev/null +++ b/buildtools/update_version_map_abi.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2019 Intel Corporation + +from __future__ import print_function +import sys +import argparse + +def setup_options(): + arg_parser = argparse.ArgumentParser(description='Merge versions in linker version script.') + arg_parser.add_argument("map_file", metavar='map_file', type=str, nargs=1, + help='path to linker version script file (pattern: *version.map)') + arg_parser.add_argument("dst_abi_version", metavar='dst_abi_version', type=str, nargs=1, + help='target ABI version (pattern: DPDK_*)') + arg_parser.add_argument("src_abi_version", metavar='src_abi_version', default="DPDK_", type=str, nargs='?', + help='source ABI version (pattern: DPDK_*, default: DPDK_)') + arg_parser.add_argument('-v', '--verbose', action='store_true', help='print changes') + + return arg_parser.parse_args() + +def is_function_line(ln): + return ln.startswith('\t') and ln.endswith(';\n') and ":" not in ln + +def is_dpdk_version_start_line(ln, src_abi_version): + return ln.startswith(src_abi_version) and ln.endswith('{\n') and ":" not in ln + +def is_experimental_version_start_line(ln): + return ln.startswith('EXPERIMENTAL {') and ln.endswith('\n') and ":" not in ln + +def is_version_end_line(ln): + return ln.startswith('}') and ln.endswith(';\n') and ":" not in ln + +def is_global_line(ln): + return ln.startswith('\tglobal:') and ln.endswith('\n') + +def is_local_line(ln): + return ln.startswith('\tlocal: ') and ln.endswith(';\n') + +def store_functions(f_in): + functions = [] + local_line = [] + + for line in f_in: + if is_version_end_line(line): break + elif is_local_line(line): + local_line = [line] + elif is_function_line(line): functions += [line] + + return functions, local_line + +def parse_linker_version_map_file(f_in, src_abi_version): + dpdk_functions = [] + experimental_functions = [] + dpdk_local_line = [] + experimental_local_line = [] + + for line in f_in: + if is_dpdk_version_start_line(line, src_abi_version): + dpdk_functions_tmp, dpdk_local_line_tmp = store_functions(f_in) + dpdk_functions += dpdk_functions_tmp + dpdk_local_line = dpdk_local_line_tmp if len(dpdk_local_line_tmp) > 0 else dpdk_local_line + elif is_experimental_version_start_line(line): + experimental_functions_tmp, experimental_local_line_tmp = store_functions(f_in) + experimental_functions += experimental_functions_tmp + experimental_local_line += experimental_local_line_tmp + + return list(set(dpdk_functions)), list(set(experimental_functions)), list(set(dpdk_local_line)), list(set(experimental_local_line)) + +def main(args): + params = setup_options() + + if not params.map_file[0].endswith('version.map') or \ + not params.dst_abi_version[0].startswith('DPDK_'): + print('Wrong pattern for input files!\n') + arg_parser.print_help() + return 1 + + dpdk_functions = [] + experimental_functions = [] + dpdk_local_line = [] + experimental_local_line = [] + + with open(params.map_file[0]) as f_in: + dpdk_functions, experimental_functions, dpdk_local_line, experimental_local_line = parse_linker_version_map_file(f_in, params.src_abi_version) + + dpdk_functions.sort() + experimental_functions.sort() + + with open(params.map_file[0], 'w') as f_out: + if len(dpdk_functions) > 0: + dpdk_functions = params.dst_abi_version + [" {\n"] + ["\tglobal:\n\n"] + dpdk_functions + dpdk_local_line + ["};\n\n"] + if params.verbose: + print(*dpdk_functions) + f_out.writelines(dpdk_functions) + elif len(dpdk_local_line) > 0: + dpdk_functions = params.dst_abi_version + [" {\n"] + ["\n\tlocal: *;\n};\n"] + if params.verbose: + print(*dpdk_functions) + f_out.writelines(dpdk_functions) + + if len(experimental_functions) > 0: + experimental_functions = ["EXPERIMENTAL" + " {\n"] + ["\tglobal:\n\n"] + experimental_functions + experimental_local_line + ["};\n"] + if params.verbose: + print(*experimental_functions) + f_out.writelines(experimental_functions) + + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) -- 2.22.0.windows.1