3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """Creates a script to run an "_incremental" .apk."""
14 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), os
.pardir
))
15 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), os
.pardir
, 'gyp'))
17 from pylib
import constants
18 from util
import build_utils
21 SCRIPT_TEMPLATE
= """\
24 # This file was generated by:
25 # //build/android/incremental_install/create_install_script.py
32 script_directory = os.path.dirname(__file__)
34 def resolve_path(path):
35 return os.path.abspath(os.path.join(script_directory, path))
37 cmd_path = resolve_path({cmd_path})
38 cmd_args = [cmd_path] + {cmd_args}
39 cmd_path_args = {cmd_path_args}
40 for arg, path in cmd_path_args:
43 cmd_args.append(resolve_path(path))
45 return subprocess.call(cmd_args + sys.argv[1:])
47 if __name__ == '__main__':
53 args
= build_utils
.ExpandFileArgs(args
)
54 parser
= argparse
.ArgumentParser()
55 build_utils
.AddDepfileOption(parser
)
56 parser
.add_argument('--script-output-path',
57 help='Output path for executable script.',
59 parser
.add_argument('--output-directory',
60 help='Path to the root build directory.',
62 parser
.add_argument('--apk-path',
63 help='Path to the .apk to install.',
65 parser
.add_argument('--split',
69 help='A glob matching the apk splits. '
70 'Can be specified multiple times.')
71 parser
.add_argument('--lib-dir',
72 help='Path to native libraries directory.')
73 parser
.add_argument('--dex-file',
77 help='List of dex files to include.')
78 parser
.add_argument('--dex-file-list',
79 help='GYP-list of dex files.')
81 options
= parser
.parse_args(args
)
82 options
.dex_files
+= build_utils
.ParseGypList(options
.dex_file_list
)
87 options
= _ParseArgs(args
)
90 return os
.path
.relpath(path
, os
.path
.dirname(options
.script_output_path
))
92 installer_path
= os
.path
.join(constants
.DIR_SOURCE_ROOT
, 'build', 'android',
93 'incremental_install', 'installer.py')
94 installer_path
= relativize(installer_path
)
97 ('--output-directory', relativize(options
.output_directory
)),
98 (None, relativize(options
.apk_path
)),
102 path_args
.append(('--lib-dir', relativize(options
.lib_dir
)))
104 if options
.dex_files
:
105 for dex_file
in options
.dex_files
:
106 path_args
.append(('--dex-file', relativize(dex_file
)))
108 for split_arg
in options
.splits
:
109 path_args
.append(('--split', relativize(split_arg
)))
111 with
open(options
.script_output_path
, 'w') as script
:
112 script
.write(SCRIPT_TEMPLATE
.format(
113 cmd_path
=pprint
.pformat(installer_path
),
115 cmd_path_args
=pprint
.pformat(path_args
)))
117 os
.chmod(options
.script_output_path
, 0750)
120 build_utils
.WriteDepfile(
122 build_utils
.GetPythonDependencies())
125 if __name__
== '__main__':
126 sys
.exit(main(sys
.argv
[1:]))