Skip to content

Commit

Permalink
Cleanup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Jan 24, 2021
1 parent ec31bb9 commit 6623195
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 80 deletions.
73 changes: 2 additions & 71 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
import multiprocessing
import zipfile
import datetime
import errno
import shutil
import lzma
Expand Down Expand Up @@ -151,7 +150,6 @@ def load_config(args):
# Default values
config['version'] = commit_hash
config['outdir'] = 'out'
config['prettyName'] = 'false'

# Load prop files
if op.exists(args.config):
Expand All @@ -161,8 +159,6 @@ def load_config(args):
if key.startswith('magisk.'):
config[key[7:]] = value

config['prettyName'] = config['prettyName'].lower() == 'true'

try:
config['versionCode'] = int(config['versionCode'])
except ValueError:
Expand All @@ -173,17 +169,10 @@ def load_config(args):
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():
for arch in archs + arch64:
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)
target = op.join('native', 'out', arch, bin)
mv(source, target)
Expand Down Expand Up @@ -214,7 +203,7 @@ def find_build_tools():
build_tools = op.join(build_tools_root, ls[-1])
return build_tools


# Unused but keep this code
def sign_zip(unsigned):
if 'keyStore' not in config:
return
Expand Down Expand Up @@ -384,60 +373,6 @@ def build_snet(args):
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):
support_targets = {'native', 'java'}
if args.target:
Expand Down Expand Up @@ -541,10 +476,6 @@ def build_all(args):
'snet', help='build snet extension')
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.add_argument(
'target', nargs='*', help='native, java, or empty to clean both')
Expand Down
9 changes: 0 additions & 9 deletions config.prop.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ version=string
# Output path. Default: out
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
# These 4 variables has to be either all set or not
Expand Down

0 comments on commit 6623195

Please sign in to comment.