Skip to content

Commit

Permalink
TgBot++: android_builder: Write each cmd to stdin
Browse files Browse the repository at this point in the history
- instead of && chains
  • Loading branch information
Royna2544 committed Jul 6, 2024
1 parent 83bea25 commit 87fa5fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/android_builder/scripts/build_rom_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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
20 changes: 19 additions & 1 deletion src/android_builder/scripts/custom_print.py
Original file line number Diff line number Diff line change
@@ -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'.
Expand All @@ -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', ' ')
Expand Down

0 comments on commit 87fa5fa

Please sign in to comment.