diff --git a/extract-files.py b/extract-files.py new file mode 100755 index 0000000..9c5a75b --- /dev/null +++ b/extract-files.py @@ -0,0 +1,81 @@ +#!/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.fixups_lib import ( + lib_fixup_remove, + lib_fixup_remove_arch_suffix, + lib_fixup_vendorcompat, + lib_fixups_user_type, + libs_clang_rt_ubsan, + libs_proto_3_9_1, +) +from extract_utils.main import ( + ExtractUtils, + ExtractUtilsModule, +) + +namespace_imports = [ + 'device/motorola/sm7325-common', + 'hardware/qcom-caf/sm8350', + 'hardware/qcom-caf/wlan', + 'vendor/qcom/opensource/commonsys-intf/display', + 'vendor/qcom/opensource/commonsys/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 + + +lib_fixups: lib_fixups_user_type = { + libs_clang_rt_ubsan: lib_fixup_remove_arch_suffix, + libs_proto_3_9_1: lib_fixup_vendorcompat, + ( + 'com.qualcomm.qti.dpm.api@1.0', + 'vendor.qti.hardware.fm@1.0', + 'vendor.qti.imsrtpservice@3.0', + ): lib_fixup_vendor_suffix, + ( + 'libofflinelog', + 'libqsap_sdk', + 'libril', + 'libthermalclient', + 'libwpa_client', + ): lib_fixup_remove, +} + +blob_fixups: blob_fixups_user_type = { + 'system_ext/etc/permissions/moto-telephony.xml': blob_fixup() + .regex_replace('/system/', '/system_ext/'), + 'system_ext/priv-app/ims/ims.apk': blob_fixup() + .apktool_patch('ims-patches'), + 'vendor/lib64/libwvhidl.so': blob_fixup() + .add_needed('libcrypto_shim.so'), + ('system_ext/lib/libwfdmmsrc_system.so', 'system_ext/lib64/libwfdmmsrc_system.so'): blob_fixup() + .add_needed('libgui_shim.so'), + 'system_ext/lib64/libwfdnative.so': blob_fixup() + .add_needed('libinput_shim.so'), + 'vendor/etc/vintf/manifest/vendor.dolby.media.c2@1.0-service.xml': blob_fixup() + .regex_replace('IComponentStore/default9', 'IComponentStore/default'), +} # fmt: skip + +module = ExtractUtilsModule( + 'sm7325-common', + 'motorola', + blob_fixups=blob_fixups, + lib_fixups=lib_fixups, + namespace_imports=namespace_imports, +) + +if __name__ == '__main__': + utils = ExtractUtils.device(module) + utils.run() diff --git a/extract-files.sh b/extract-files.sh deleted file mode 100755 index 69d6832..0000000 --- a/extract-files.sh +++ /dev/null @@ -1,143 +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 - -# 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}/../../.." - -# If XML files don't have comments before the XML header, use this flag -# Can still be used with broken XML files by using blob_fixup -export TARGET_DISABLE_XML_FIXING=true - -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_COMMON= -ONLY_FIRMWARE= -ONLY_TARGET= -KANG= -SECTION= - -while [ "${#}" -gt 0 ]; do - case "${1}" in - --only-common) - ONLY_COMMON=true - ;; - --only-firmware) - ONLY_FIRMWARE=true - ;; - --only-target) - ONLY_TARGET=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 - system_ext/lib*/libwfdmmsrc_system.so) - [ "$2" = "" ] && return 0 - grep -q "libgui_shim.so" "${2}" || "${PATCHELF}" --add-needed "libgui_shim.so" "${2}" - ;; - system_ext/lib64/libwfdnative.so) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --remove-needed "android.hidl.base@1.0.so" "${2}" - grep -q "libinput_shim.so" "${2}" || "${PATCHELF}" --add-needed "libinput_shim.so" "${2}" - ;; - system_ext/etc/permissions/moto-telephony.xml) - [ "$2" = "" ] && return 0 - sed -i "s#/system/#/system_ext/#" "${2}" - ;; - system_ext/priv-app/ims/ims.apk) - [ "$2" = "" ] && return 0 - apktool_patch "${2}" "$MY_DIR/ims-patches" - ;; - vendor/etc/vintf/manifest/vendor.dolby.media.c2@1.0-service.xml) - [ "$2" = "" ] && return 0 - sed -ni '/default.*fqname/!p' "${2}" - ;; - vendor/lib64/libwvhidl.so) - [ "$2" = "" ] && return 0 - grep -q libcrypto_shim.so "${2}" || "${PATCHELF}" --add-needed "libcrypto_shim.so" "${2}" - ;; - *) - return 1 - ;; - esac - - return 0 -} - -function blob_fixup_dry() { - blob_fixup "$1" "" -} - -function prepare_firmware() { - if [ "${SRC}" != "adb" ]; then - local STAR="${ANDROID_ROOT}"/lineage/scripts/motorola/star.sh - for IMAGE in bootloader radio; do - if [ -f "${SRC}/${IMAGE}.img" ]; then - echo "Extracting Motorola star image ${SRC}/${IMAGE}.img" - sh "${STAR}" "${SRC}/${IMAGE}.img" "${SRC}" - fi - done - local INFO="${ANDROID_ROOT}"/lineage/scripts/motorola/info.sh - ./${INFO} "${SRC}" - fi -} - -if [ -z "${ONLY_FIRMWARE}" ] && [ -z "${ONLY_TARGET}" ]; then - # Initialize the helper for common device - setup_vendor "${DEVICE_COMMON}" "${VENDOR_COMMON:-$VENDOR}" "${ANDROID_ROOT}" true "${CLEAN_VENDOR}" - - extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" -fi - -if [ -z "${ONLY_COMMON}" ] && [ -s "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" ]; then - # Reinitialize the helper for device - source "${MY_DIR}/../../${VENDOR}/${DEVICE}/extract-files.sh" - setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}" - - if [ -z "${ONLY_FIRMWARE}" ]; then - extract "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" - fi - - if [ -z "${SECTION}" ] && [ -f "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" ]; then - extract_firmware "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" "${SRC}" - fi -fi - -"${MY_DIR}/setup-makefiles.sh" diff --git a/setup-makefiles.py b/setup-makefiles.py new file mode 100755 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 da83ee2..0000000 --- a/setup-makefiles.sh +++ /dev/null @@ -1,89 +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 - -# 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}/../../.." - -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}" - -function vendor_imports() { - cat <>"$1" - "device/motorola/sm7325-common", - "hardware/qcom-caf/sm8350", - "hardware/qcom-caf/wlan", - "vendor/qcom/opensource/dataservices", - "vendor/qcom/opensource/display", -EOF -} - -function lib_to_package_fixup_vendor_variants() { - if [ "$2" != "vendor" ]; then - return 1 - fi - - case "$1" in - com.qualcomm.qti.dpm.api@1.0 | \ - vendor.qti.hardware.fm@1.0 | \ - vendor.qti.imsrtpservice@3.0) - echo "$1_vendor" - ;; - libofflinelog | \ - libqsap_sdk | \ - libril | \ - libthermalclient | \ - libwpa_client) ;; - *) - return 1 - ;; - esac -} - -function lib_to_package_fixup() { - lib_to_package_fixup_clang_rt_ubsan_standalone "$1" || - lib_to_package_fixup_proto_3_9_1 "$1" || - lib_to_package_fixup_vendor_variants "$@" -} - -# Initialize the helper for common -setup_vendor "${DEVICE_COMMON}" "${VENDOR_COMMON:-$VENDOR}" "${ANDROID_ROOT}" true - -# Warning headers and guards -write_headers "berlin berlna dubai xpeng" - -# The standard common blobs -write_makefiles "${MY_DIR}/proprietary-files.txt" - -# Finish -write_footers - -if [ -s "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" ]; then - # Reinitialize the helper for device - setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false - - # Warning headers and guards - write_headers - - # The standard device blobs - write_makefiles "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" - - if [ -f "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" ]; then - append_firmware_calls_to_makefiles "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" - fi - - # Finish - write_footers -fi