From 87fa5fa7b90de0d507507434925d8a698f94fd92 Mon Sep 17 00:00:00 2001 From: Soo Hwan Na Date: Sat, 6 Jul 2024 14:00:20 +0900 Subject: [PATCH] TgBot++: android_builder: Write each cmd to stdin - instead of && chains --- .../scripts/build_rom_utils.py | 22 ++++++++++++++----- src/android_builder/scripts/custom_print.py | 20 ++++++++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/android_builder/scripts/build_rom_utils.py b/src/android_builder/scripts/build_rom_utils.py index a2add533..4768dfa4 100644 --- a/src/android_builder/scripts/build_rom_utils.py +++ b/src/android_builder/scripts/build_rom_utils.py @@ -20,13 +20,23 @@ def find_vendor_str() -> str: def build_rom(device: str, variant: str, target: str, jobs: int) -> bool: vendor = find_vendor_str() + success = False + if vendor is None: print('Couldn\'t find vendor') return False - command_list = [ - '. build/envsetup.sh', - f'lunch {vendor}_{device}-{variant}', - f'm {target} -j{jobs}' - ] - return subprocess_utils.run_command(' && '.join(command_list)) \ No newline at end of file + shell_process = subprocess.Popen(['bash'], stdin=subprocess.PIPE, stdout=fp, stderr=fp, text=True) + print('Writing . build/envsetup.sh') + shell_process.stdin.write('. build/envsetup.sh\n') + print(f'Writing lunch {vendor}_{device}-{variant}') + shell_process.stdin.write(f'lunch {vendor}_{device}-{variant}\n') + print(f'Writing m {target} -j{jobs}') + shell_process.stdin.write(f'm {target} -j{jobs}\n') + shell_process.stdin.flush() + shell_process.stdin.close() + print('Now waiting...') + shell_process.wait() + success = shell_process.returncode == 0 + + return success \ No newline at end of file diff --git a/src/android_builder/scripts/custom_print.py b/src/android_builder/scripts/custom_print.py index aad9e37c..05ead9a5 100644 --- a/src/android_builder/scripts/custom_print.py +++ b/src/android_builder/scripts/custom_print.py @@ -1,5 +1,23 @@ import os +def get_logfd() -> int: + """ + This function retrieves the file descriptor for logging. + + Returns: + int: The file descriptor for logging. + + Raises: + OSError: If the environment variable 'PYTHON_LOG_FD' is not set or cannot be converted to an integer. + """ + try: + logfd = int(os.environ['PYTHON_LOG_FD']) + return logfd + except KeyError: + raise OSError("Environment variable 'PYTHON_LOG_FD' not set") + except ValueError: + raise OSError("Invalid value for environment variable 'PYTHON_LOG_FD'") + def custom_print(*args, **kwargs): """ This function prints the provided arguments to a file descriptor specified by the environment variable 'PYTHON_LOG_FD'. @@ -16,7 +34,7 @@ def custom_print(*args, **kwargs): Raises: OSError: If the file descriptor is invalid or not open for writing. """ - logfd = int(os.environ['PYTHON_LOG_FD']) + logfd = get_logfd() # Get kwargs or set default values sep = kwargs.get('sep', ' ')