2023-08-09 02:17:29 -05:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import configparser as cp
|
|
|
|
import json
|
2023-08-09 19:12:04 -05:00
|
|
|
from Cleanup import clean_exit
|
2023-08-10 14:50:42 -05:00
|
|
|
import subprocess
|
2023-08-09 02:17:29 -05:00
|
|
|
|
|
|
|
# Build the revanced apps
|
2023-08-09 19:12:04 -05:00
|
|
|
def build_apps(appstate):
|
|
|
|
build_config = appstate['build_config']
|
|
|
|
flag = appstate['flag']
|
2023-08-10 14:50:42 -05:00
|
|
|
print = appstate['logger'].info
|
2023-08-09 19:12:04 -05:00
|
|
|
|
2023-08-09 02:17:29 -05:00
|
|
|
chosen_patches = cp.ConfigParser()
|
|
|
|
chosen_patches.read('chosen_patches.toml')
|
|
|
|
|
|
|
|
try:
|
|
|
|
included_patches = json.loads(chosen_patches['patches']['included'])
|
|
|
|
except:
|
|
|
|
included_patches = []
|
|
|
|
try:
|
|
|
|
excluded_patches = json.loads(chosen_patches['patches']['excluded'])
|
|
|
|
except Exception as e:
|
|
|
|
excluded_patches = []
|
|
|
|
|
|
|
|
for app in build_config:
|
|
|
|
# Check if we need to build an app
|
|
|
|
if not build_config[app].getboolean('build'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Build the command to be run
|
|
|
|
cmd = 'java -jar revanced-cli.jar -m revanced-integrations.apk -b revanced-patches.jar'
|
|
|
|
|
|
|
|
try:
|
|
|
|
root = build_config[app].getboolean('root')
|
|
|
|
except:
|
|
|
|
root = False
|
|
|
|
|
|
|
|
if root:
|
|
|
|
cmd += ' --mount -e microg-support'
|
|
|
|
|
|
|
|
for item in included_patches:
|
|
|
|
cmd += f" -i {item}"
|
|
|
|
for item in excluded_patches:
|
|
|
|
cmd += f" -e {item}"
|
|
|
|
|
|
|
|
if flag == 'experimental':
|
|
|
|
cmd += ' --experimental'
|
|
|
|
|
|
|
|
try:
|
|
|
|
keystore = build_config[app]['keystore']
|
|
|
|
if not root:
|
|
|
|
cmd += f" --keystore {keystore}"
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
apk = build_config[app]['apk']
|
|
|
|
pretty_name = build_config[app]['pretty_name']
|
|
|
|
apkpure_appname = build_config[app]['apkpure_appname']
|
|
|
|
output_name = build_config[app]['output_name']
|
|
|
|
except:
|
2023-08-09 19:12:04 -05:00
|
|
|
clean_exit(f"Invalid config for {app} in build_config.toml!", appstate)
|
2023-08-09 02:17:29 -05:00
|
|
|
|
|
|
|
cmd += f" -a {apk}.apk -o {output_name}.apk"
|
|
|
|
|
|
|
|
if root:
|
|
|
|
print(f"Building {pretty_name} (root)...")
|
|
|
|
else:
|
|
|
|
print(f"Building {pretty_name} (nonroot)...")
|
|
|
|
|
|
|
|
try:
|
2023-08-10 14:50:42 -05:00
|
|
|
with subprocess.Popen(cmd, shell=True, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout as output:
|
|
|
|
for line in output:
|
|
|
|
line_utf = line.decode('utf-8').strip('\n')
|
|
|
|
if line_utf:
|
|
|
|
print(line_utf)
|
2023-08-09 02:17:29 -05:00
|
|
|
except Exception as e:
|
2023-08-10 14:50:42 -05:00
|
|
|
clean_exit(f"There was an error while building {pretty_name}!\n{e}", appstate)
|
2023-08-09 02:17:29 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.rename(output_name+'.apk', output_name+'.apk') # TODO: Add timestamp here
|
|
|
|
except FileNotFoundError:
|
2023-08-09 19:12:04 -05:00
|
|
|
clean_exit(f"There was an error while building {pretty_name}!", appstate)
|
2023-08-09 02:17:29 -05:00
|
|
|
|