tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

system_image_apks.py (1887B)


      1 #!/usr/bin/env python3
      2 
      3 # Copyright 2022 The Chromium Authors
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 """Generates APKs for use on system images."""
      7 
      8 import argparse
      9 import os
     10 import pathlib
     11 import tempfile
     12 import shutil
     13 import sys
     14 import zipfile
     15 
     16 _DIR_SOURCE_ROOT = str(pathlib.Path(__file__).parents[2])
     17 sys.path.append(os.path.join(_DIR_SOURCE_ROOT, 'build', 'android', 'gyp'))
     18 from util import build_utils
     19 
     20 
     21 def main():
     22  parser = argparse.ArgumentParser()
     23  parser.add_argument('--input', required=True, help='Input path')
     24  parser.add_argument('--output', required=True, help='Output path')
     25  parser.add_argument('--bundle-wrapper', help='APK operations script path')
     26  parser.add_argument('--fuse-apk',
     27                      help='Create single .apk rather than using apk splits',
     28                      action='store_true')
     29  args = parser.parse_args()
     30 
     31  if not args.bundle_wrapper:
     32    shutil.copyfile(args.input, args.output)
     33    return
     34 
     35  with tempfile.NamedTemporaryFile(suffix='.apks') as tmp_file:
     36    cmd = [
     37        args.bundle_wrapper, 'build-bundle-apks', '--output-apks', tmp_file.name
     38    ]
     39    cmd += ['--build-mode', 'system' if args.fuse_apk else 'system_apks']
     40 
     41    # Creates a .apks zip file that contains the system image APK(s).
     42    build_utils.CheckOutput(cmd)
     43 
     44    if args.fuse_apk:
     45      with zipfile.ZipFile(tmp_file.name) as z:
     46        pathlib.Path(args.output).write_bytes(z.read('system/system.apk'))
     47      return
     48 
     49    # A single .apk file means a bundle where we take only the base split.
     50    if args.output.endswith('.apk'):
     51      with zipfile.ZipFile(tmp_file.name) as z:
     52        pathlib.Path(args.output).write_bytes(z.read('splits/base-master.apk'))
     53      return
     54 
     55    # Use the full .apks.
     56    shutil.copyfile(tmp_file.name, args.output)
     57 
     58 
     59 if __name__ == '__main__':
     60  sys.exit(main())