From 9f698a91b6a522ee2f6e550067445ec0c4aedca3 Mon Sep 17 00:00:00 2001 From: Zachery Wu Date: Sun, 26 Sep 2021 16:37:03 +0800 Subject: [PATCH] delete useless script Signed-off-by: Zachery Wu Change-Id: I78afbc29bf8f73168e73b15cdcad2f77fa3dac4f --- linux-4.19/prebuilts/linux_header_install.sh | 65 ------ linux-4.19/prebuilts/thirdparty_headers.sh | 49 ---- linux-4.19/prebuilts/update_headers.py | 229 ------------------- linux-5.10/prebuilts/linux_header_install.sh | 65 ------ linux-5.10/prebuilts/thirdparty_headers.sh | 49 ---- linux-5.10/prebuilts/update_headers.py | 229 ------------------- 6 files changed, 686 deletions(-) delete mode 100755 linux-4.19/prebuilts/linux_header_install.sh delete mode 100755 linux-4.19/prebuilts/thirdparty_headers.sh delete mode 100755 linux-4.19/prebuilts/update_headers.py delete mode 100755 linux-5.10/prebuilts/linux_header_install.sh delete mode 100755 linux-5.10/prebuilts/thirdparty_headers.sh delete mode 100755 linux-5.10/prebuilts/update_headers.py diff --git a/linux-4.19/prebuilts/linux_header_install.sh b/linux-4.19/prebuilts/linux_header_install.sh deleted file mode 100755 index bcbb701..0000000 --- a/linux-4.19/prebuilts/linux_header_install.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -# This script is used to prepare header files for musl's libc.so. - -set -e -ARM_TYPE=arm -PRJ_ROOT="$PWD/../../../../../" -KERNEL_ROOT="$PRJ_ROOT/kernel/linux-4.19" -ARM_HDR="$KERNEL_ROOT/hdr_install/${ARM_TYPE}_header" -OUT_HDR="$PRJ_ROOT/kernel/linux/patches/linux-4.19/prebuilts/linux_headers_install" -export Z_BUILD_TOP="$PRJ_ROOT" - -if [ -d "$ARM_HDR" ];then -rm -r $ARM_HDR -fi - -if [ -d "$OUT_HDR" ];then -rm -r $OUT_HDR -fi - -mkdir -p $ARM_HDR -mkdir -p $OUT_HDR - -pushd $KERNEL_ROOT -make headers_install ARCH=${ARM_TYPE} INSTALL_HDR_PATH=$ARM_HDR -popd - -function copy_if_exists () { - local check_dir=$1 - local src_dir=$2 - local tgt_dir=$3 - mkdir -p ${tgt_dir} - for file in $(ls -d ${src_dir}/* 2> /dev/null); do - if [[ -f "${file}" ]] && [[ "${file}" =~ .h$ ]]; then - header=$(basename ${file}) - if [[ -f "${check_dir}/${header}" ]]; then - cp ${file} ${tgt_dir} - fi - fi - done -} - -cp -r ${KERNEL_ROOT}/include/uapi ${OUT_HDR} -cp -r ${KERNEL_ROOT}/include/generated/uapi ${OUT_HDR} -cp -r ${ARM_HDR}/include/asm ${OUT_HDR}/uapi -cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE} -cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE} -cp -r ${KERNEL_ROOT}/drivers/staging/android/uapi/* ${OUT_HDR}/uapi/linux -copy_if_exists "${KERNEL_ROOT}/include/uapi/asm-generic" \ - "${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/asm" \ - "${OUT_HDR}/uapi/asm-${ARM_TYPE}/asm" -cp ${KERNEL_ROOT}/include/linux/compiler_types.h ${OUT_HDR}/uapi/linux diff --git a/linux-4.19/prebuilts/thirdparty_headers.sh b/linux-4.19/prebuilts/thirdparty_headers.sh deleted file mode 100755 index 1a0a781..0000000 --- a/linux-4.19/prebuilts/thirdparty_headers.sh +++ /dev/null @@ -1,49 +0,0 @@ -#/bin/bash - -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -# This script is used to prepare header files for musl's libc.so. - -set -e -ARM_TYPE=arm -PRJ_ROOT="${PWD}/../../../../../" -LINUX_HDR="${PRJ_ROOT}/kernel/linux/patches/linux-4.19/prebuilts/linux_headers_install" -TMP_DIR_ORI="${PRJ_ROOT}/kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp_ori" -TMP_DIR="${PRJ_ROOT}/kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp" -MUSL_DIR="${PWD}/usr/include" -export Z_BUILD_TOP="${PRJ_ROOT}" -if [ ! -d "${LINUX_HDR}/uapi/asm-${ARM_TYPE}" ] || [ ! -d "${LINUX_HDR}/uapi/asm-generic" ] || [ ! -d "${LINUX_HDR}/uapi/linux" ];then - echo "please install headers first!!!" - exit 1 -fi - -mkdir -p ${TMP_DIR_ORI} -mkdir -p ${TMP_DIR} - -cp -rf ${LINUX_HDR}/* ${TMP_DIR_ORI} -echo "#ifndef _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h -echo "#define _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h -echo "#define __user" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h -echo "#endif" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h - -pushd ${PRJ_ROOT} - python kernel/linux/patches/linux-4.19/prebuilts/update_headers.py 2>/dev/null -popd - -if [ ! -d ${MUSL_DIR} ]; then - mkdir -p ${MUSL_DIR} -fi -cp -rf ${TMP_DIR}/uapi/* ${MUSL_DIR}/ -rm -rf ${TMP_DIR_ORI} -rm -rf ${TMP_DIR} diff --git a/linux-4.19/prebuilts/update_headers.py b/linux-4.19/prebuilts/update_headers.py deleted file mode 100755 index 18f1621..0000000 --- a/linux-4.19/prebuilts/update_headers.py +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/env python -#-*-coding:utf-8-*- - -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -# Perform for Z kernel headers - -import sys -import os -import getopt -import subprocess -import time -import string -import re -import glob - -# /*..*/ //... -Rule1 = "(\/\*(\s|.)*?\*\/)|(\/\/.*)" -c1=re.compile(Rule1) - -#use list for order -key_list = [ -# grep key, gerp dir, sed key, sed replace - ["CONFIG_64BIT", ".", "CONFIG_64BIT", "__LP64__"], - ["__unused;", ".", "__unused;", "__linux_unused;"], - ["__unused\[", ".", "__unused\[", "__linux_unused["], - [" private;", ".", " private;", " __linux_private;"], - ["\*virtual;", ".", "\*virtual;", "\* __linux_virtual;"], - ["struct msqid_ds", ".", "struct msqid_ds", "struct __kernel_legacy_msqid_ds"], - ["struct semid_ds", ".", "struct semid_ds", "struct __kernel_legacy_semid_ds"], - ["struct shmid_ds", ".", "struct shmid_ds", "struct __kernel_legacy_shmid_ds"], - ["struct ipc_perm", ".", "struct ipc_perm", "struct __kernel_legacy_ipc_perm"], - ["union semun", ".", "union semun", "union __kernel_legacy_semun"], - ["_NSIG", ".", "_NSIG", "_KERNEL__NSIG"], - ["_KERNEL__NSIG_", ".", "_KERNEL__NSIG_", "_NSIG_"], - ["#define NSIG\s", ".", "#define NSIG", "#define _KERNEL_NSIG"], - ["SIGRTMIN", ".", "SIGRTMIN", "__SIGRTMIN"], - ["SIGRTMAX", ".", "SIGRTMAX", "__SIGRTMAX"], - ["struct udphdr", ".", "struct udphdr", "struct __kernel_udphdr"], - ["struct __kernel_sockaddr_storage", ".", "struct __kernel_sockaddr_storage", "struct sockaddr_storage"], - ["off_t", "asm-mips/asm/stat.h", "off_t", "__kernel_off_t"], - ["#ifndef __EXPORTED_HEADERS__", ".", "#ifndef __EXPORTED_HEADERS__", "#if 0 \/*__EXPORTED_HEADERS__*\/"], - ["#ifndef __KERNEL_STRICT_NAMES", ".", "#ifndef __KERNEL_STRICT_NAMES", "#if 0 \/*__KERNEL_STRICT_NAMES*\/"], - ["#ifdef __CHECKER__", ".", "#ifdef __CHECKER__", "#if 0 \/*__CHECKER__*\/"], - ["#ifdef __HAVE_BUILTIN_BSWAP16__", ".", "#ifdef __HAVE_BUILTIN_BSWAP16__", "#if 1 \/*__HAVE_BUILTIN_BSWAP16__*\/"], - ["#ifdef __HAVE_BUILTIN_BSWAP32__", ".", "#ifdef __HAVE_BUILTIN_BSWAP32__", "#if 1 \/*__HAVE_BUILTIN_BSWAP32__*\/"], - ["#ifdef __HAVE_BUILTIN_BSWAP64__", ".", "#ifdef __HAVE_BUILTIN_BSWAP64__", "#if 1 \/*__HAVE_BUILTIN_BSWAP64__*\/"], - ["#if defined(__ARMEB__)", "asm-arm", "#if defined(__ARMEB__)", "#if 0 \/*__ARMEB__*\/"], - ["#ifdef __ARMEB__", "asm-arm", "#ifdef __ARMEB__", "#if 0 \/*__ARMEB__*\/"], - ["defined(__ARM_EABI__)", "asm-arm", "defined(__ARM_EABI__)", "1 \/*defined(__ARM_EABI__)*\/"], - ["#ifdef __MIPSEB__", "asm-mips", "#ifdef __MIPSEB__", "#if 0 \/*__MIPSEB__*\/"], - ["#elif defined (__MIPSEB__)", "asm-mips", "#elif defined (__MIPSEB__)", "#elif 0 \/*__MIPSEB__*\/"], - ["#if defined(__MIPSEB__)", "asm-mips", "#if defined(__MIPSEB__)", "#if 0 \/*__MIPSEB__*\/"], - ["#elif defined(__MIPSEL__)", "asm-mips", "#elif defined(__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"], - ["#elif defined (__MIPSEL__)", "asm-mips", "#elif defined (__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"], - ["\!defined(__SANE_USERSPACE_TYPES__)", "asm-mips", "\!defined(__SANE_USERSPACE_TYPES__)", "0 \/*__SANE_USERSPACE_TYPES__*\/"], - ["\/\*.*\*\/", ".", "\/\*.*\*\/", ""], - ] - -def deal_file(src): - # file exist or not - if not os.path.exists(src): - print('Error: file - %s doesn\'t exist.'% src) - return False - if os.path.islink(src): - print('Error: file - %s is a link.'% src) - return False - filetype = (os.path.splitext(src))[1] - if not filetype in ['.c','.h','.cpp','.hh','.cc']: - return False - try: - if not os.access(src, os.W_OK): - os.chmod(src, 0o664) - except: - print('Error: you can not chang %s\'s mode.'% src) - - # del all comments - inputf = open(src, 'r') - outputfilename = (os.path.splitext(src))[0] + '_no_comment'+filetype - outputf = open(outputfilename, 'w') - - lines=inputf.read() - inputf.close() - lines=re.sub(Rule1,"",lines) - outputf.write(lines) - outputf.close() - - #del right space & blank line - os.remove(src) - inputf = open(outputfilename, 'r') - outputf = open(src, 'w') - #write head info - outputf.write("/*\n") - outputf.write(" * This header was generated from the Linux kernel headers by update_headers.py,\n") - outputf.write(" * to provide necessary information from kernel to userspace, such as constants,\n") - outputf.write(" * structures, and macros, and thus, contains no copyrightable information.\n") - outputf.write(" */\n") - line = inputf.readline() - while line: - if line == '\n': - line = line.strip("\n") - else: - line = line.rstrip() + '\n' - outputf.write(line) - line = inputf.readline() - inputf.close() - outputf.close() - os.remove(outputfilename) - - return True - - -def deal_dir(src): - # dir exist or not - if not os.path.exists(src): - print('Error: dir - %s is not exist.'% src) - return False - filelists = os.listdir(src) - for eachfile in filelists: - eachfile = src + '/' +eachfile - if os.path.isdir(eachfile): - deal_dir(eachfile) - elif os.path.isfile(eachfile): - deal_file(eachfile) - return True - - -def copy_kernel_headers(build_top, original_dir, target_dir): - headers_dir = build_top + '/' + target_dir - external_dir = build_top + original_dir - - headers_rm_cmd = "rm " + headers_dir + "/uapi -rf" - headers_cp_cmd = "cp " + external_dir + " " + headers_dir + " -r" - - try: - status = subprocess.call(headers_rm_cmd, shell=True) - except: - printf("[Error] rm error!!!") - - try: - status = subprocess.call(headers_cp_cmd, shell=True) - except: - printf("[Error] cp error!!!") - - return 1 - -def replace_key_words_ext(keys): - replace_key_words(keys[0], keys[1], keys[2], keys[3]) - return 1 - -def replace_key_words(original_key, target_dir, replace_key, replace_str): - replace_cmd = "grep \""+ original_key + "\" -rl " + target_dir + " | xargs sed -i \"s/" + replace_key + "/" + replace_str + "/g\"" - try: - status = subprocess.call(replace_cmd, shell=True) - except: - printf("[Error] replace CONFIG_64BIT error!!!") - - return 1 - - - -def usage(): - print(" Usage: run the script at the root of project.\n For example:\n\ - python ./foundation/ccruntime/libc/kernel/tools/update_Z_header.py") - return 0 - - -def main(): - - if len(sys.argv) > 1: - usage() - return -1 - - kernel_dir = "kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp" - external_dir = '/kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp_ori/uapi' - status = -1 - - try: - build_top = os.environ["Z_BUILD_TOP"] - except KeyError as e: - print("[Warning] no env : %s, use current work dir." %(str(e))) - build_top = subprocess.check_output("pwd", shell=True) - - status = copy_kernel_headers(build_top.strip(), external_dir, kernel_dir) - if status != 1: - print("[Error] copy files fail!!!") - sys.exti(1) - - try: - os.chdir(kernel_dir + "/uapi") - except: - print("[Error] no uapi dir1!!!") - sys.exit(1) - - current_dir = os.getcwd() - - if "uapi" not in current_dir: - print("[Error] not uapi dir!!!") - sys.exit(1) - - for val in key_list: - replace_key_words_ext(val) - - try: - os.chdir("../") - except: - print("[Error] no uapi dir2!!!") - sys.exit(1) - deal_dir("uapi") - - return 1 - -if __name__ == "__main__": - starttime=time.time() - main() - endtime=time.time() - print(endtime-starttime) - diff --git a/linux-5.10/prebuilts/linux_header_install.sh b/linux-5.10/prebuilts/linux_header_install.sh deleted file mode 100755 index 6ddbabb..0000000 --- a/linux-5.10/prebuilts/linux_header_install.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -# This script is used to prepare header files for musl's libc.so. - -set -e -ARM_TYPE=arm -PRJ_ROOT="$PWD/../../../../../" -KERNEL_ROOT="$PRJ_ROOT/kernel/linux/linux-5.10" -ARM_HDR="$KERNEL_ROOT/hdr_install/${ARM_TYPE}_header" -OUT_HDR="$PRJ_ROOT/kernel/linux/patches/linux-5.10/prebuilts/linux_headers_install" -export Z_BUILD_TOP="$PRJ_ROOT" - -if [ -d "$ARM_HDR" ];then -rm -r $ARM_HDR -fi - -if [ -d "$OUT_HDR" ];then -rm -r $OUT_HDR -fi - -mkdir -p $ARM_HDR -mkdir -p $OUT_HDR - -pushd $KERNEL_ROOT -make headers_install ARCH=${ARM_TYPE} INSTALL_HDR_PATH=$ARM_HDR -popd - -function copy_if_exists () { - local check_dir=$1 - local src_dir=$2 - local tgt_dir=$3 - mkdir -p ${tgt_dir} - for file in $(ls -d ${src_dir}/* 2> /dev/null); do - if [[ -f "${file}" ]] && [[ "${file}" =~ .h$ ]]; then - header=$(basename ${file}) - if [[ -f "${check_dir}/${header}" ]]; then - cp ${file} ${tgt_dir} - fi - fi - done -} - -cp -r ${KERNEL_ROOT}/include/uapi ${OUT_HDR} -cp -r ${KERNEL_ROOT}/include/generated/uapi ${OUT_HDR} -cp -r ${ARM_HDR}/include/asm ${OUT_HDR}/uapi -cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE} -cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE} -cp -r ${KERNEL_ROOT}/drivers/staging/android/uapi/* ${OUT_HDR}/uapi/linux -copy_if_exists "${KERNEL_ROOT}/include/uapi/asm-generic" \ - "${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/asm" \ - "${OUT_HDR}/uapi/asm-${ARM_TYPE}/asm" -cp ${KERNEL_ROOT}/include/linux/compiler_types.h ${OUT_HDR}/uapi/linux diff --git a/linux-5.10/prebuilts/thirdparty_headers.sh b/linux-5.10/prebuilts/thirdparty_headers.sh deleted file mode 100755 index efd9846..0000000 --- a/linux-5.10/prebuilts/thirdparty_headers.sh +++ /dev/null @@ -1,49 +0,0 @@ -#/bin/bash - -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -# This script is used to prepare header files for musl's libc.so. - -set -e -ARM_TYPE=arm -PRJ_ROOT="${PWD}/../../../../../" -LINUX_HDR="${PRJ_ROOT}/kernel/linux/patches/linux-5.10/prebuilts/linux_headers_install" -TMP_DIR_ORI="${PRJ_ROOT}/kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp_ori" -TMP_DIR="${PRJ_ROOT}/kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp" -MUSL_DIR="${PWD}/usr/include" -export Z_BUILD_TOP="${PRJ_ROOT}" -if [ ! -d "${LINUX_HDR}/uapi/asm-${ARM_TYPE}" ] || [ ! -d "${LINUX_HDR}/uapi/asm-generic" ] || [ ! -d "${LINUX_HDR}/uapi/linux" ];then - echo "please install headers first!!!" - exit 1 -fi - -mkdir -p ${TMP_DIR_ORI} -mkdir -p ${TMP_DIR} - -cp -rf ${LINUX_HDR}/* ${TMP_DIR_ORI} -echo "#ifndef _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h -echo "#define _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h -echo "#define __user" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h -echo "#endif" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h - -pushd ${PRJ_ROOT} - python kernel/linux/patches/linux-5.10/prebuilts/update_headers.py 2>/dev/null -popd - -if [ ! -d ${MUSL_DIR} ]; then - mkdir -p ${MUSL_DIR} -fi -cp -rf ${TMP_DIR}/uapi/* ${MUSL_DIR}/ -rm -rf ${TMP_DIR_ORI} -rm -rf ${TMP_DIR} diff --git a/linux-5.10/prebuilts/update_headers.py b/linux-5.10/prebuilts/update_headers.py deleted file mode 100755 index 3fc0145..0000000 --- a/linux-5.10/prebuilts/update_headers.py +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/env python -#-*-coding:utf-8-*- - -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -# Perform for Z kernel headers - -import sys -import os -import getopt -import subprocess -import time -import string -import re -import glob - -# /*..*/ //... -Rule1 = "(\/\*(\s|.)*?\*\/)|(\/\/.*)" -c1=re.compile(Rule1) - -#use list for order -key_list = [ -# grep key, gerp dir, sed key, sed replace - ["CONFIG_64BIT", ".", "CONFIG_64BIT", "__LP64__"], - ["__unused;", ".", "__unused;", "__linux_unused;"], - ["__unused\[", ".", "__unused\[", "__linux_unused["], - [" private;", ".", " private;", " __linux_private;"], - ["\*virtual;", ".", "\*virtual;", "\* __linux_virtual;"], - ["struct msqid_ds", ".", "struct msqid_ds", "struct __kernel_legacy_msqid_ds"], - ["struct semid_ds", ".", "struct semid_ds", "struct __kernel_legacy_semid_ds"], - ["struct shmid_ds", ".", "struct shmid_ds", "struct __kernel_legacy_shmid_ds"], - ["struct ipc_perm", ".", "struct ipc_perm", "struct __kernel_legacy_ipc_perm"], - ["union semun", ".", "union semun", "union __kernel_legacy_semun"], - ["_NSIG", ".", "_NSIG", "_KERNEL__NSIG"], - ["_KERNEL__NSIG_", ".", "_KERNEL__NSIG_", "_NSIG_"], - ["#define NSIG\s", ".", "#define NSIG", "#define _KERNEL_NSIG"], - ["SIGRTMIN", ".", "SIGRTMIN", "__SIGRTMIN"], - ["SIGRTMAX", ".", "SIGRTMAX", "__SIGRTMAX"], - ["struct udphdr", ".", "struct udphdr", "struct __kernel_udphdr"], - ["struct __kernel_sockaddr_storage", ".", "struct __kernel_sockaddr_storage", "struct sockaddr_storage"], - ["off_t", "asm-mips/asm/stat.h", "off_t", "__kernel_off_t"], - ["#ifndef __EXPORTED_HEADERS__", ".", "#ifndef __EXPORTED_HEADERS__", "#if 0 \/*__EXPORTED_HEADERS__*\/"], - ["#ifndef __KERNEL_STRICT_NAMES", ".", "#ifndef __KERNEL_STRICT_NAMES", "#if 0 \/*__KERNEL_STRICT_NAMES*\/"], - ["#ifdef __CHECKER__", ".", "#ifdef __CHECKER__", "#if 0 \/*__CHECKER__*\/"], - ["#ifdef __HAVE_BUILTIN_BSWAP16__", ".", "#ifdef __HAVE_BUILTIN_BSWAP16__", "#if 1 \/*__HAVE_BUILTIN_BSWAP16__*\/"], - ["#ifdef __HAVE_BUILTIN_BSWAP32__", ".", "#ifdef __HAVE_BUILTIN_BSWAP32__", "#if 1 \/*__HAVE_BUILTIN_BSWAP32__*\/"], - ["#ifdef __HAVE_BUILTIN_BSWAP64__", ".", "#ifdef __HAVE_BUILTIN_BSWAP64__", "#if 1 \/*__HAVE_BUILTIN_BSWAP64__*\/"], - ["#if defined(__ARMEB__)", "asm-arm", "#if defined(__ARMEB__)", "#if 0 \/*__ARMEB__*\/"], - ["#ifdef __ARMEB__", "asm-arm", "#ifdef __ARMEB__", "#if 0 \/*__ARMEB__*\/"], - ["defined(__ARM_EABI__)", "asm-arm", "defined(__ARM_EABI__)", "1 \/*defined(__ARM_EABI__)*\/"], - ["#ifdef __MIPSEB__", "asm-mips", "#ifdef __MIPSEB__", "#if 0 \/*__MIPSEB__*\/"], - ["#elif defined (__MIPSEB__)", "asm-mips", "#elif defined (__MIPSEB__)", "#elif 0 \/*__MIPSEB__*\/"], - ["#if defined(__MIPSEB__)", "asm-mips", "#if defined(__MIPSEB__)", "#if 0 \/*__MIPSEB__*\/"], - ["#elif defined(__MIPSEL__)", "asm-mips", "#elif defined(__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"], - ["#elif defined (__MIPSEL__)", "asm-mips", "#elif defined (__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"], - ["\!defined(__SANE_USERSPACE_TYPES__)", "asm-mips", "\!defined(__SANE_USERSPACE_TYPES__)", "0 \/*__SANE_USERSPACE_TYPES__*\/"], - ["\/\*.*\*\/", ".", "\/\*.*\*\/", ""], - ] - -def deal_file(src): - # file exist or not - if not os.path.exists(src): - print('Error: file - %s doesn\'t exist.'% src) - return False - if os.path.islink(src): - print('Error: file - %s is a link.'% src) - return False - filetype = (os.path.splitext(src))[1] - if not filetype in ['.c','.h','.cpp','.hh','.cc']: - return False - try: - if not os.access(src, os.W_OK): - os.chmod(src, 0o664) - except: - print('Error: you can not chang %s\'s mode.'% src) - - # del all comments - inputf = open(src, 'r') - outputfilename = (os.path.splitext(src))[0] + '_no_comment'+filetype - outputf = open(outputfilename, 'w') - - lines=inputf.read() - inputf.close() - lines=re.sub(Rule1,"",lines) - outputf.write(lines) - outputf.close() - - #del right space & blank line - os.remove(src) - inputf = open(outputfilename, 'r') - outputf = open(src, 'w') - #write head info - outputf.write("/*\n") - outputf.write(" * This header was generated from the Linux kernel headers by update_headers.py,\n") - outputf.write(" * to provide necessary information from kernel to userspace, such as constants,\n") - outputf.write(" * structures, and macros, and thus, contains no copyrightable information.\n") - outputf.write(" */\n") - line = inputf.readline() - while line: - if line == '\n': - line = line.strip("\n") - else: - line = line.rstrip() + '\n' - outputf.write(line) - line = inputf.readline() - inputf.close() - outputf.close() - os.remove(outputfilename) - - return True - - -def deal_dir(src): - # dir exist or not - if not os.path.exists(src): - print('Error: dir - %s is not exist.'% src) - return False - filelists = os.listdir(src) - for eachfile in filelists: - eachfile = src + '/' +eachfile - if os.path.isdir(eachfile): - deal_dir(eachfile) - elif os.path.isfile(eachfile): - deal_file(eachfile) - return True - - -def copy_kernel_headers(build_top, original_dir, target_dir): - headers_dir = build_top + '/' + target_dir - external_dir = build_top + original_dir - - headers_rm_cmd = "rm " + headers_dir + "/uapi -rf" - headers_cp_cmd = "cp " + external_dir + " " + headers_dir + " -r" - - try: - status = subprocess.call(headers_rm_cmd, shell=True) - except: - printf("[Error] rm error!!!") - - try: - status = subprocess.call(headers_cp_cmd, shell=True) - except: - printf("[Error] cp error!!!") - - return 1 - -def replace_key_words_ext(keys): - replace_key_words(keys[0], keys[1], keys[2], keys[3]) - return 1 - -def replace_key_words(original_key, target_dir, replace_key, replace_str): - replace_cmd = "grep \""+ original_key + "\" -rl " + target_dir + " | xargs sed -i \"s/" + replace_key + "/" + replace_str + "/g\"" - try: - status = subprocess.call(replace_cmd, shell=True) - except: - printf("[Error] replace CONFIG_64BIT error!!!") - - return 1 - - - -def usage(): - print(" Usage: run the script at the root of project.\n For example:\n\ - python ./foundation/ccruntime/libc/kernel/tools/update_Z_header.py") - return 0 - - -def main(): - - if len(sys.argv) > 1: - usage() - return -1 - - kernel_dir = "kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp" - external_dir = '/kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp_ori/uapi' - status = -1 - - try: - build_top = os.environ["Z_BUILD_TOP"] - except KeyError as e: - print("[Warning] no env : %s, use current work dir." %(str(e))) - build_top = subprocess.check_output("pwd", shell=True) - - status = copy_kernel_headers(build_top.strip(), external_dir, kernel_dir) - if status != 1: - print("[Error] copy files fail!!!") - sys.exti(1) - - try: - os.chdir(kernel_dir + "/uapi") - except: - print("[Error] no uapi dir1!!!") - sys.exit(1) - - current_dir = os.getcwd() - - if "uapi" not in current_dir: - print("[Error] not uapi dir!!!") - sys.exit(1) - - for val in key_list: - replace_key_words_ext(val) - - try: - os.chdir("../") - except: - print("[Error] no uapi dir2!!!") - sys.exit(1) - deal_dir("uapi") - - return 1 - -if __name__ == "__main__": - starttime=time.time() - main() - endtime=time.time() - print(endtime-starttime) - -- Gitee