1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88

build / android / gyp / create_apk_operations_script.py [blame]

#!/usr/bin/env python3
# Copyright 2017 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


import argparse
import os
import string
import sys

from util import build_utils

SCRIPT_TEMPLATE = string.Template("""\
#!/usr/bin/env python3
#
# This file was generated by build/android/gyp/create_apk_operations_script.py

import os
import sys

def main():
  script_directory = os.path.dirname(__file__)
  resolve = lambda p: p if p is None else os.path.abspath(os.path.join(
      script_directory, p))
  sys.path.append(resolve(${APK_OPERATIONS_DIR}))
  import apk_operations
  output_dir = resolve(${OUTPUT_DIR})
  apk_operations.Run(
      output_dir,
      resolve(${APK_PATH}),
      [resolve(p) for p in ${ADDITIONAL_APK_PATHS}],
      resolve(${INC_JSON_PATH}),
      ${FLAGS_FILE},
      ${TARGET_CPU},
      resolve(${MAPPING_PATH}))


if __name__ == '__main__':
  sys.exit(main())
""")


def main(args):
  args = build_utils.ExpandFileArgs(args)
  parser = argparse.ArgumentParser()
  parser.add_argument('--script-output-path',
                      help='Output path for executable script.')
  parser.add_argument('--apk-path')
  parser.add_argument('--incremental-install-json-path')
  parser.add_argument('--command-line-flags-file')
  parser.add_argument('--target-cpu')
  parser.add_argument(
      '--additional-apk-path',
      action='append',
      dest='additional_apk_paths',
      default=[],
      help='Paths to APKs to be installed prior to --apk-path.')
  parser.add_argument('--proguard-mapping-path')
  args = parser.parse_args(args)

  def relativize(path):
    """Returns the path relative to the output script directory."""
    if path is None:
      return path
    return os.path.relpath(path, os.path.dirname(args.script_output_path))
  apk_operations_dir = os.path.join(os.path.dirname(__file__), os.path.pardir)
  apk_operations_dir = relativize(apk_operations_dir)

  with open(args.script_output_path, 'w') as script:
    script_dict = {
        'APK_OPERATIONS_DIR': repr(apk_operations_dir),
        'OUTPUT_DIR': repr(relativize('.')),
        'APK_PATH': repr(relativize(args.apk_path)),
        'ADDITIONAL_APK_PATHS':
        [relativize(p) for p in args.additional_apk_paths],
        'INC_JSON_PATH': repr(relativize(args.incremental_install_json_path)),
        'MAPPING_PATH': repr(relativize(args.proguard_mapping_path)),
        'FLAGS_FILE': repr(args.command_line_flags_file),
        'TARGET_CPU': repr(args.target_cpu),
    }
    script.write(SCRIPT_TEMPLATE.substitute(script_dict))
  os.chmod(args.script_output_path, 0o750)
  return 0


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))