From b05fa36762209787cc5e820d5639119be0cac0c0 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 28 Nov 2024 16:05:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E5=85=A5=E6=96=B0=E5=AE=8F=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: = --- third_party/musl/ndk_script/BUILD.gn | 16 ++++- .../musl/ndk_script/updated_version.py | 61 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 third_party/musl/ndk_script/updated_version.py diff --git a/third_party/musl/ndk_script/BUILD.gn b/third_party/musl/ndk_script/BUILD.gn index a71e33565..8dacc1543 100644 --- a/third_party/musl/ndk_script/BUILD.gn +++ b/third_party/musl/ndk_script/BUILD.gn @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build//version.gni") import("//build/config/clang/clang.gni") import("//build/ohos/ndk/ndk.gni") import("//third_party/musl/musl_config.gni") @@ -21,6 +22,7 @@ import("//third_party/musl/musl_template.gni") musl_target_out_dir = "${root_out_dir}/obj/third_party/musl" ndk_musl_include = "ndk_musl_include" interface_musl_dir = "//interface/sdk_c/third_party/musl" +target_version_file = "ndk_musl_include//info//application_target_sdk_version.h" if (host_os == "mac") { if (host_cpu == "arm64") { @@ -223,6 +225,18 @@ action("copy_ndk_musl_headers") { deps = [ ":copy_ndk_uapi" ] } +action("updated_version") { + outputs = ["${musl_target_out_dir}/${target_version_file}"] + script = "python3" + args = [ + "updated_version.py", + "-p", rebase_path("${musl_target_out_dir}/${target_version_file}"), + "-v", api_version, + "-o", rebase_path("${musl_target_out_dir}/${target_version_file}") + ] + deps = [ ":copy_ndk_musl_headers" ] +} + action("copy_musl_sysroot") { outputs = [ "${ndk_headers_out_dir}" ] script = "copy_musl_sysroot.sh" @@ -230,7 +244,7 @@ action("copy_musl_sysroot") { [ "-i" ] + [ rebase_path("${musl_target_out_dir}/${ndk_musl_include}") ] args += [ "-o" ] + [ rebase_path("${ndk_headers_out_dir}") ] args += [ "-t" ] + [ "${musl_arch}" ] - deps = [ ":copy_ndk_musl_headers" ] + deps = [ ":updated_version" ] } musl_libs_arm32 = [ diff --git a/third_party/musl/ndk_script/updated_version.py b/third_party/musl/ndk_script/updated_version.py new file mode 100644 index 000000000..7d52029b7 --- /dev/null +++ b/third_party/musl/ndk_script/updated_version.py @@ -0,0 +1,61 @@ + +import argparse + + +# 插入新版宏内容 +def updated_version(file_path: str, new_version: int, output: str): + version_define = '#define SDK_VERSION_' + version_current_define = '#define OH_CURRENT_SDK_VERSION OH_SDK_VERSION_' + # 需要插入的内容 + new_content = '' + # 插入的标志位置 + insert_after_line = '#define SDK_VERSION_9 9' + # 旧版本 + old_version = 9 + # 更新需插入的内容 + for i in range(new_version - old_version): + new_content += '{}{} {}\n'.format(version_define, old_version + i + 1, old_version + i + 1) + new_content += '{}{}\n'.format(version_current_define, new_version) + + with open(file_path, 'r') as fp: + lines = fp.readlines() + + # 查找插入位置的索引 + insert_position = None + for i, line in enumerate(lines): + if insert_after_line in line: + insert_position = i + 1 # 插入在该行之后 + break + + # 如果找到插入位置 + if insert_position is not None: + # 插入新内容 + lines.insert(insert_position, new_content) + # 更新修改后的内容 + with open(output, 'w') as fp: + fp.writelines(lines) + else: + print('未找到插入位置: {}'.format(insert_after_line)) + + +# 入口 +def process_target_version(): + try: + parser = argparse.ArgumentParser(description='Updated version') + # 定义命令行参数 + parser.add_argument('-p', '--path', type=str, required=True, help='Path to the input file') + parser.add_argument('-v', '--version', type=str, required=True, help='Version of the api') + parser.add_argument('-o', '--output', type=str, required=True, help='output path') + args = parser.parse_args() + # 获取文件路径和版本 + input_file = args.path + api_version = int(args.version) + output_path = args.output + # 写入新版宏内容 + updated_version(input_file, api_version, output_path) + except Exception as e: + print('{}'.format(e)) + + +if __name__ == '__main__': + process_target_version() -- Gitee