Cleanup scripts

This commit is contained in:
topjohnwu 2021-01-24 07:24:13 -08:00
parent ec31bb9a82
commit 6623195bd5
2 changed files with 2 additions and 80 deletions

View File

@ -5,7 +5,6 @@ import subprocess
import argparse import argparse
import multiprocessing import multiprocessing
import zipfile import zipfile
import datetime
import errno import errno
import shutil import shutil
import lzma import lzma
@ -151,7 +150,6 @@ def load_config(args):
# Default values # Default values
config['version'] = commit_hash config['version'] = commit_hash
config['outdir'] = 'out' config['outdir'] = 'out'
config['prettyName'] = 'false'
# Load prop files # Load prop files
if op.exists(args.config): if op.exists(args.config):
@ -161,8 +159,6 @@ def load_config(args):
if key.startswith('magisk.'): if key.startswith('magisk.'):
config[key[7:]] = value config[key[7:]] = value
config['prettyName'] = config['prettyName'].lower() == 'true'
try: try:
config['versionCode'] = int(config['versionCode']) config['versionCode'] = int(config['versionCode'])
except ValueError: except ValueError:
@ -173,17 +169,10 @@ def load_config(args):
STDOUT = None if args.verbose else subprocess.DEVNULL STDOUT = None if args.verbose else subprocess.DEVNULL
def zip_with_msg(zip_file, source, target):
if not op.exists(source):
error(f'{source} does not exist! Try build \'binary\' and \'apk\' before zipping!')
zip_file.write(source, target)
vprint(f'zip: {source} -> {target}')
def collect_binary(): def collect_binary():
for arch in archs + arch64: for arch in archs + arch64:
mkdir_p(op.join('native', 'out', arch)) mkdir_p(op.join('native', 'out', arch))
for bin in support_targets + ['magiskinit64']: for bin in support_targets:
source = op.join('native', 'libs', arch, bin) source = op.join('native', 'libs', arch, bin)
target = op.join('native', 'out', arch, bin) target = op.join('native', 'out', arch, bin)
mv(source, target) mv(source, target)
@ -214,7 +203,7 @@ def find_build_tools():
build_tools = op.join(build_tools_root, ls[-1]) build_tools = op.join(build_tools_root, ls[-1])
return build_tools return build_tools
# Unused but keep this code
def sign_zip(unsigned): def sign_zip(unsigned):
if 'keyStore' not in config: if 'keyStore' not in config:
return return
@ -384,60 +373,6 @@ def build_snet(args):
header('Output: ' + target) header('Output: ' + target)
def zip_uninstaller(args):
header('* Packing Uninstaller Zip')
datestr = f'{datetime.datetime.now():%Y%m%d}'
name = f'Magisk-uninstaller-{datestr}.zip' if config['prettyName'] else 'magisk-uninstaller.zip'
output = op.join(config['outdir'], name)
with zipfile.ZipFile(output, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=False) as zipf:
# update-binary
source = op.join('scripts', 'update_binary.sh')
target = op.join('META-INF', 'com', 'google',
'android', 'update-binary')
zip_with_msg(zipf, source, target)
# updater-script
source = op.join('scripts', 'uninstaller.sh')
target = op.join('META-INF', 'com', 'google',
'android', 'updater-script')
zip_with_msg(zipf, source, target)
# Binaries
for exe in ('busybox', 'magiskboot'):
for arch in archs:
source = op.join('native', 'out', arch, exe)
target = op.join('lib', arch, f'lib{exe}.so')
zip_with_msg(zipf, source, target)
# util_functions.sh
source = op.join('scripts', 'util_functions.sh')
with open(source, 'r') as script:
# Add version info util_functions.sh
util_func = script.read().replace(
'#MAGISK_VERSION_STUB',
f'MAGISK_VER="{config["version"]}"\n'
f'MAGISK_VER_CODE={config["versionCode"]}')
target = op.join('assets', 'util_functions.sh')
vprint(f'zip: {source} -> {target}')
zipf.writestr(target, util_func)
# chromeos
for tool in ['futility', 'kernel_data_key.vbprivk', 'kernel.keyblock']:
if tool == 'futility':
source = op.join('tools', tool)
else:
source = op.join('tools', 'keys', tool)
target = op.join('assets', 'chromeos', tool)
zip_with_msg(zipf, source, target)
# End of zipping
sign_zip(output)
header('Output: ' + output)
def cleanup(args): def cleanup(args):
support_targets = {'native', 'java'} support_targets = {'native', 'java'}
if args.target: if args.target:
@ -541,10 +476,6 @@ snet_parser = subparsers.add_parser(
'snet', help='build snet extension') 'snet', help='build snet extension')
snet_parser.set_defaults(func=build_snet) snet_parser.set_defaults(func=build_snet)
un_parser = subparsers.add_parser(
'uninstaller', help='create flashable uninstaller')
un_parser.set_defaults(func=zip_uninstaller)
clean_parser = subparsers.add_parser('clean', help='cleanup') clean_parser = subparsers.add_parser('clean', help='cleanup')
clean_parser.add_argument( clean_parser.add_argument(
'target', nargs='*', help='native, java, or empty to clean both') 'target', nargs='*', help='native, java, or empty to clean both')

View File

@ -9,15 +9,6 @@ version=string
# Output path. Default: out # Output path. Default: out
outdir=string outdir=string
################################################################
# Whether to use pretty names for zips
# e.g. Magisk-v${version}.zip, Magisk-uninstaller-${date}.zip
# Default names are magisk-${release/debug/uninstaller}.zip
################################################################
# Default: false
prettyName=bool
##################################################### #####################################################
# Signing configs for signing zips and APKs # Signing configs for signing zips and APKs
# These 4 variables has to be either all set or not # These 4 variables has to be either all set or not