From 2e77c9825614a102c3e39ca9e969dcfc23b816db Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Thu, 12 Sep 2024 02:01:54 +0200 Subject: [PATCH] sm8250-common: Move to sort-blobs-list shortcut Change-Id: I6f2fe5ed88f6fd3f9a344720ee5e967e2ff71469 --- reorder-libs.py | 66 ---------------------------------------------- sort-blobs-list.sh | 29 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 66 deletions(-) delete mode 100755 reorder-libs.py create mode 100755 sort-blobs-list.sh diff --git a/reorder-libs.py b/reorder-libs.py deleted file mode 100755 index 82388d1..0000000 --- a/reorder-libs.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2021 The LineageOS Project -# -# SPDX-License-Identifier: Apache-2.0 -# - -from functools import cmp_to_key -from locale import LC_ALL, setlocale, strcoll -from pathlib import Path - -FILES = [Path(file) for file in [ - "proprietary-files.txt", -]] - -setlocale(LC_ALL, "C") - -def strcoll_extract_utils(string1: str, string2: str) -> int: - # Skip logic if one of the string if empty - if not string1 or not string2: - return strcoll(string1, string2) - - # Remove '-' from strings if there, - # it is used to indicate a build target - string1 = string1.removeprefix('-') - string2 = string2.removeprefix('-') - - # If no directories, compare normally - if not "/" in string1 and not "/" in string2: - return strcoll(string1, string2) - - string1_dir = string1.rsplit("/", 1)[0] + "/" - string2_dir = string2.rsplit("/", 1)[0] + "/" - if string1_dir == string2_dir: - # Same directory, compare normally - return strcoll(string1, string2) - - if string1_dir.startswith(string2_dir): - # First string dir is a subdirectory of the second one, - # return string1 > string2 - return -1 - - if string2_dir.startswith(string1_dir): - # Second string dir is a subdirectory of the first one, - # return string2 > string1 - return 1 - - # Compare normally - return strcoll(string1, string2) - -for file in FILES: - if not file.is_file(): - print(f"File {str(file)} not found") - continue - - with open(file, 'r') as f: - sections = f.read().split("\n\n") - - ordered_sections = [] - for section in sections: - section_list = [line.strip() for line in section.splitlines()] - section_list.sort(key=cmp_to_key(strcoll_extract_utils)) - ordered_sections.append("\n".join(section_list)) - - with open(file, 'w') as f: - f.write("\n\n".join(ordered_sections).strip() + "\n") diff --git a/sort-blobs-list.sh b/sort-blobs-list.sh new file mode 100755 index 0000000..89669fe --- /dev/null +++ b/sort-blobs-list.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# SPDX-FileCopyrightText: 2024 The LineageOS Project +# SPDX-License-Identifier: Apache-2.0 +# + +set -e + +# List of files to sort +PROPRIETARY_FILES_TXT=( + "proprietary-files.txt" + "proprietary-files-phone.txt" +) + +# Load sort-blobs-list.py 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/sort-blobs-list.py" +if [ ! -f "${HELPER}" ]; then + echo "Unable to find helper script at ${HELPER}" + exit 1 +fi + +# Call the helper to sort the list +# Add --dir-first to give priority to directories and subdirectories +"${HELPER}" --dir-first "${PROPRIETARY_FILES_TXT[@]}"