Android: makes "apk_package" optional in adb_install_apk.py

We can derive the package name from the mandatory apk.

BUG=
TEST=adb_install_apk.py --apk ContentShell.apk


Review URL: https://chromiumcodereview.appspot.com/11365004

git-svn-id: http://src.chromium.org/svn/trunk/src/build@165450 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
bulach@chromium.org 2012-11-01 18:55:26 +00:00
Родитель ad1edc9d9a
Коммит a093bd53df
3 изменённых файлов: 37 добавлений и 19 удалений

Просмотреть файл

@ -10,27 +10,24 @@ import os
import sys
from pylib import android_commands
from pylib import test_options_parser
from pylib import apk_info
from pylib import constants
from pylib import test_options_parser
def InstallApk(args):
options, device = args
apk_path = os.path.join(os.environ['CHROME_SRC'],
'out', options.build_type,
'apks', options.apk)
def _InstallApk(args):
apk_path, apk_package, device = args
result = android_commands.AndroidCommands(device=device).ManagedInstall(
apk_path, False, options.apk_package)
apk_path, False, apk_package)
print '----- Installed on %s -----' % device
print result
def main(argv):
parser = optparse.OptionParser()
test_options_parser.AddBuildTypeOption(parser)
test_options_parser.AddInstallAPKOption(parser)
options, args = parser.parse_args(argv)
test_options_parser.ValidateInstallAPKOption(parser, options)
if len(args) > 1:
raise Exception('Error: Unknown argument:', args[1:])
@ -38,9 +35,14 @@ def main(argv):
if not devices:
raise Exception('Error: no connected devices')
if not options.apk_package:
options.apk_package = apk_info.GetPackageNameForApk(options.apk)
pool = multiprocessing.Pool(len(devices))
# Send a tuple (options, device) per instance of DeploySingleDevice.
pool.map(InstallApk, zip([options] * len(devices), devices))
# Send a tuple (apk_path, apk_package, device) per device.
pool.map(_InstallApk, zip([options.apk] * len(devices),
[options.apk_package] * len(devices),
devices))
if __name__ == '__main__':

Просмотреть файл

@ -11,6 +11,18 @@ import re
import cmd_helper
def GetPackageNameForApk(apk_path):
"""Returns the package name of the apk file."""
aapt_output = cmd_helper.GetCmdOutput(
['aapt', 'dump', 'badging', apk_path]).split('\n')
package_name_re = re.compile(r'package: .*name=\'(\S*)\'')
for line in aapt_output:
m = package_name_re.match(line)
if m:
return m.group(1)
raise Exception('Failed to determine package name of %s' % apk_path)
class ApkInfo(object):
"""Helper class for inspecting APKs."""
@ -26,7 +38,6 @@ class ApkInfo(object):
self._PROGUARD_ANNOTATION_CONST_RE = (
re.compile(r'\s*?- Constant element value.*$'))
self._PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$')
self._AAPT_PACKAGE_NAME_RE = re.compile(r'package: .*name=\'(\S*)\'')
if not os.path.exists(apk_path):
raise Exception('%s not found, please build it' % apk_path)
@ -99,13 +110,7 @@ class ApkInfo(object):
def GetPackageName(self):
"""Returns the package name of this APK."""
aapt_output = cmd_helper.GetCmdOutput(
['aapt', 'dump', 'badging', self._apk_path]).split('\n')
for line in aapt_output:
m = self._AAPT_PACKAGE_NAME_RE.match(line)
if m:
return m.group(1)
raise Exception('Failed to determine package name of %s' % self._apk_path)
return GetPackageNameForApk(self._apk_path)
def GetTestAnnotations(self, test):
"""Returns a list of all annotations for the given |test|. May be empty."""

Просмотреть файл

@ -28,6 +28,7 @@ def AddBuildTypeOption(option_parser):
def AddInstallAPKOption(option_parser):
"""Decorates OptionParser with apk option used to install the APK."""
AddBuildTypeOption(option_parser)
option_parser.add_option('--apk',
help=('The name of the apk containing the '
' application (with the .apk extension).'))
@ -35,6 +36,16 @@ def AddInstallAPKOption(option_parser):
help=('The package name used by the apk containing '
'the application.'))
def ValidateInstallAPKOption(option_parser, options):
if not options.apk:
option_parser.error('--apk is mandatory.')
if not os.path.exists(options.apk):
options.apk = os.path.join(os.environ['CHROME_SRC'],
'out', options.build_type,
'apks', options.apk)
def AddTestRunnerOptions(option_parser, default_timeout=60):
"""Decorates OptionParser with options applicable to all tests."""