From d34309000e61e8e3b2d85bb273fbd55d5b805aed Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Fri, 6 Jun 2025 14:48:48 +0200 Subject: [PATCH] veux: Migrate to py extract utils Signed-off-by: Onelots Co-authored-by: LuK1337 Co-authored-by: Skyblueborb --- extract-files.py | 87 ++++++++++++++++++++++++++++++ extract-files.sh | 132 --------------------------------------------- setup-makefiles.py | 1 + setup-makefiles.sh | 37 ------------- 4 files changed, 88 insertions(+), 169 deletions(-) create mode 100644 extract-files.py delete mode 100755 extract-files.sh create mode 100644 setup-makefiles.py delete mode 100755 setup-makefiles.sh diff --git a/extract-files.py b/extract-files.py new file mode 100644 index 0000000..08de1ef --- /dev/null +++ b/extract-files.py @@ -0,0 +1,87 @@ +#!/usr/bin/env -S PYTHONPATH=../../../tools/extract-utils python3 +# +# SPDX-FileCopyrightText: 2024 The LineageOS Project +# SPDX-License-Identifier: Apache-2.0 +# + +from extract_utils.fixups_blob import ( + blob_fixup, + blob_fixups_user_type, +) + +from extract_utils.main import ( + ExtractUtils, + ExtractUtilsModule, +) + +namespace_imports = [ + 'device/xiaomi/veux', + 'hardware/qcom-caf/sm8350', + 'hardware/qcom-caf/wlan', + 'hardware/xiaomi', + 'vendor/qcom/opensource/commonsys/display', + 'vendor/qcom/opensource/commonsys-intf/display', + 'vendor/qcom/opensource/dataservices', + 'vendor/qcom/opensource/display', +] + + +def lib_fixup_vendor_suffix(lib: str, partition: str, *args, **kwargs): + return f'{lib}_{partition}' if partition == 'vendor' else None + +blob_fixups: blob_fixups_user_type = { + 'odm/etc/build_*.prop': blob_fixup() + .regex_replace(r'.*marketname.*\n', r'') + .regex_replace(r'cert', r'model'), + + 'system_ext/etc/init/wfdservice.rc': blob_fixup() + .regex_replace(r'^(?!service)(.*)wfdservice$', r'\g<1>wfdservice64'), + + 'system_ext/lib64/libwfdnative.so': blob_fixup() + .remove_needed('android.hidl.base@1.0.so'), + + 'vendor/etc/camera/camxoverridesettings.txt': blob_fixup() + .regex_replace(r'0x10080', r'0') + .regex_replace(r'0x1F', r'0x0'), + + 'vendor/etc/init/init.batterysecret.rc': blob_fixup() + .regex_replace(r'on charger', r'on property:init.svc.vendor.charger=running'), + + 'vendor/etc/libnfc-pn557.conf': blob_fixup() + .call(lambda file_path, content: + content if "NXP RF" in content + else content + '\n' + open(f"{SRC}/vendor/libnfc-nxp_RF.conf").read()), + + 'vendor/lib64/android.hardware.secure_element@1.0-impl.so': blob_fixup() + .remove_needed('android.hidl.base@1.0.so'), + + 'vendor/lib64/camera/components/com.qti.node.mialgocontrol.so': blob_fixup() + .add_needed('libpiex_shim.so'), + + ('vendor/lib64/libwvhidl.so', 'vendor/lib64/mediadrm/libwvdrmengine.so'): blob_fixup() + .add_needed('libcrypto_shim.so'), + + ('vendor/lib64/libdlbdsservice.so', + 'vendor/lib/libstagefright_soft_ac4dec.so', + 'vendor/lib/libstagefright_soft_ddpdec.so'): blob_fixup() + .replace_needed('libstagefright_foundation.so', 'libstagefright_foundation-v33.so'), + + 'vendor/etc/libnfc-sn100.conf': blob_fixup() + .regex_replace(r'(DEFAULT_ISODEP_ROUTE.*?)0x01', r'\g<1>0xC0') + .regex_replace(r'(DEFAULT_SYS_CODE_ROUTE.*?)0x00', r'\g<1>0xC0') + .regex_replace(r'(DEFAULT_OFFHOST_ROUTE.*?)0x01', r'\g<1>0xC0') + .regex_replace(r'(OFFHOST_ROUTE_ESE.*?)01', r'\g<1>C0') + .regex_replace(r'$', r'\nDEFAULT_NFCF_ROUTE=0xC0'), +} + + +module = ExtractUtilsModule( + 'veux', + 'xiaomi', + blob_fixups=blob_fixups, + namespace_imports=namespace_imports, +) + +if __name__ == '__main__': + utils = ExtractUtils.device(module) + utils.run() \ No newline at end of file diff --git a/extract-files.sh b/extract-files.sh deleted file mode 100755 index 9162305..0000000 --- a/extract-files.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/bash -# -# SPDX-FileCopyrightText: 2016 The CyanogenMod Project -# SPDX-FileCopyrightText: 2017-2024 The LineageOS Project -# SPDX-License-Identifier: Apache-2.0 -# - -set -e - -DEVICE=veux -VENDOR=xiaomi - -# Load extract_utils and do some sanity checks -MY_DIR="${BASH_SOURCE%/*}" -if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi - -ANDROID_ROOT="${MY_DIR}/../../.." - -export TARGET_ENABLE_CHECKELF=false - -HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" -if [ ! -f "${HELPER}" ]; then - echo "Unable to find helper script at ${HELPER}" - exit 1 -fi -source "${HELPER}" - -# Default to sanitizing the vendor folder before extraction -CLEAN_VENDOR=true - -ONLY_FIRMWARE= -KANG= -SECTION= - -while [ "${#}" -gt 0 ]; do - case "${1}" in - --only-firmware) - ONLY_FIRMWARE=true - ;; - -n | --no-cleanup) - CLEAN_VENDOR=false - ;; - -k | --kang) - KANG="--kang" - ;; - -s | --section) - SECTION="${2}" - shift - CLEAN_VENDOR=false - ;; - *) - SRC="${1}" - ;; - esac - shift -done - -if [ -z "${SRC}" ]; then - SRC="adb" -fi - -function blob_fixup() { - case "${1}" in - odm/etc/build_*.prop) - [ "$2" = "" ] && return 0 - sed -i "/marketname/d" "${2}" - sed -i "s/cert/model/" "${2}" - ;; - system_ext/etc/init/wfdservice.rc) - [ "$2" = "" ] && return 0 - sed -i "/^service/! s/wfdservice$/wfdservice64/g" "${2}" - ;; - system_ext/lib64/libwfdnative.so) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --remove-needed "android.hidl.base@1.0.so" "${2}" - ;; - vendor/etc/camera/camxoverridesettings.txt) - [ "$2" = "" ] && return 0 - sed -i "s/0x10080/0/g" "${2}" - sed -i "s/0x1F/0x0/g" "${2}" - ;; - vendor/etc/init/init.batterysecret.rc) - [ "$2" = "" ] && return 0 - sed -i "s/on charger/on property:init.svc.vendor.charger=running/g" "${2}" - ;; - vendor/etc/libnfc-pn557.conf) - [ "$2" = "" ] && return 0 - grep -q "NXP RF" "${2}" || cat "${SRC}/vendor/libnfc-nxp_RF.conf" >> "${2}" - ;; - vendor/lib64/android.hardware.secure_element@1.0-impl.so) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --remove-needed "android.hidl.base@1.0.so" "${2}" - ;; - vendor/lib64/camera/components/com.qti.node.mialgocontrol.so) - [ "$2" = "" ] && return 0 - llvm-strip --strip-debug "${2}" - grep -q "libpiex_shim.so" "${2}" || "${PATCHELF}" --add-needed "libpiex_shim.so" "${2}" - ;; - vendor/lib64/libwvhidl.so|vendor/lib64/mediadrm/libwvdrmengine.so) - [ "$2" = "" ] && return 0 - grep -q "libcrypto_shim.so" "${2}" || "${PATCHELF}" --add-needed "libcrypto_shim.so" "${2}" - ;; - vendor/lib64/libdlbdsservice.so|vendor/lib/libstagefright_soft_ac4dec.so|vendor/lib/libstagefright_soft_ddpdec.so) - "${PATCHELF}" --replace-needed "libstagefright_foundation.so" "libstagefright_foundation-v33.so" "${2}" - ;; - vendor/etc/libnfc-sn100.conf) - sed -i "/DEFAULT_ISODEP_ROUTE/ s/0x01/0xC0/g" "${2}" - sed -i "/DEFAULT_SYS_CODE_ROUTE/ s/0x00/0xC0/g" "${2}" - sed -i "/DEFAULT_OFFHOST_ROUTE/ s/0x01/0xC0/g" "${2}" - sed -i "/OFFHOST_ROUTE_ESE/ s/01/C0/g" "${2}" - echo "DEFAULT_NFCF_ROUTE=0xC0" >> "${2}" - ;; - *) - return 1 - ;; - esac - - return 0 -} - -function blob_fixup_dry() { - blob_fixup "$1" "" -} - -# Initialize the helper -setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}" - -if [ -z "${ONLY_FIRMWARE}" ]; then - extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" -fi - -"${MY_DIR}/setup-makefiles.sh" diff --git a/setup-makefiles.py b/setup-makefiles.py new file mode 100644 index 0000000..32947cf --- /dev/null +++ b/setup-makefiles.py @@ -0,0 +1 @@ +#!./extract-files.py --regenerate_makefiles diff --git a/setup-makefiles.sh b/setup-makefiles.sh deleted file mode 100755 index 856480d..0000000 --- a/setup-makefiles.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# -# SPDX-FileCopyrightText: 2016 The CyanogenMod Project -# SPDX-FileCopyrightText: 2017-2024 The LineageOS Project -# SPDX-License-Identifier: Apache-2.0 -# - -set -e - -DEVICE=veux -VENDOR=xiaomi - -# Load extract_utils and do some sanity checks -MY_DIR="${BASH_SOURCE%/*}" -if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi - -ANDROID_ROOT="${MY_DIR}/../../.." - -export TARGET_ENABLE_CHECKELF=false - -HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" -if [ ! -f "${HELPER}" ]; then - echo "Unable to find helper script at ${HELPER}" - exit 1 -fi -source "${HELPER}" - -# Initialize the helper -setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" - -# Warning headers and guards -write_headers - -write_makefiles "${MY_DIR}/proprietary-files.txt" - -# Finish -write_footers