def _extract_dex_dumps(apk): build_dir = tempfile.mkdtemp() extracted_dex_files = _extract_dex_files(apk, build_dir) cmd = [ build_tools.GetPath('dexdump'), '-d' ] + extracted_dex_files status, out = cmd_helper.GetCmdStatusAndOutput(cmd) shutil.rmtree(build_dir) return (status, out)
def testManifest(self): monochrome_apk = self.context.monochrome_apk cmd = [ build_tools.GetPath('aapt'), 'dump', 'xmltree', monochrome_apk, 'AndroidManifest.xml'] status, manifest = cmd_helper.GetCmdStatusAndOutput(cmd) self.assertEquals(status, 0) # Check that AndroidManifest.xml does not have any <uses-library> tags. # crbug.com/115604 self.assertNotIn('uses-library', manifest)
# Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """This module wraps Android's split-select tool.""" from devil.android.sdk import build_tools from devil.utils import cmd_helper from devil.utils import lazy _split_select_path = lazy.WeakConstant( lambda: build_tools.GetPath('split-select')) def _RunSplitSelectCmd(args): """Runs a split-select command. Args: args: A list of arguments for split-select. Returns: The output of the command. """ cmd = [_split_select_path.read()] + args status, output = cmd_helper.GetCmdStatusAndOutput(cmd) if status != 0: raise Exception('Failed running command "%s" with output "%s".' % (' '.join(cmd), output)) return output def _SplitConfig(device, allow_cached_props=False):
import posixpath import re import sys import tempfile import zipfile import zlib import devil_chromium from devil.android.sdk import build_tools from devil.utils import cmd_helper from devil.utils import lazy import method_count from pylib import constants from pylib.constants import host_paths _AAPT_PATH = lazy.WeakConstant(lambda: build_tools.GetPath('aapt')) _BUILD_UTILS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'gyp') with host_paths.SysPath(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')): import gn_helpers # pylint: disable=import-error with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): import perf_tests_results_helper # pylint: disable=import-error with host_paths.SysPath(host_paths.TRACING_PATH): from tracing.value import convert_chart_json # pylint: disable=import-error with host_paths.SysPath(_BUILD_UTILS_PATH, 0): from util import build_utils # pylint: disable=import-error from util import zipalign # pylint: disable=import-error
# build/android/gyp/bundletool.py to get the default path to the bundletool # jar file. If this fail, using --bundletool-path will be required to parse # bundles, allowing this script to be relocated or reused somewhere else. try: sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'gyp')) import bundletool _DEFAULT_BUNDLETOOL_PATH = bundletool.BUNDLETOOL_JAR_PATH except: _DEFAULT_BUNDLETOOL_PATH = None # Try to get the path of the aapt build tool from catapult/devil. try: import devil_chromium # pylint: disable=unused-import from devil.android.sdk import build_tools _AAPT_DEFAULT_PATH = build_tools.GetPath('aapt') except: _AAPT_DEFAULT_PATH = None def AutoIndentStringList(lines, indentation=2): """Auto-indents a input list of text lines, based on open/closed braces. For example, the following input text: 'Foo {', 'Bar {', 'Zoo', '}', '}',
def _CompareApiDumpForFiles(input_api, output_api, aidl_files): if len(aidl_files) == 0: return [] repo_root = input_api.change.RepositoryRoot() build_android_dir = os.path.join(repo_root, 'build', 'android') sys.path.append(build_android_dir) sys.path.append(os.path.join(repo_root, 'third_party', 'catapult', 'devil')) import devil_chromium from devil.android.sdk import build_tools devil_chromium.Initialize() aidl_tool_path = build_tools.GetPath('aidl') if not os.path.exists(aidl_tool_path): return [ output_api.PresubmitError( 'Android sdk does not contain aidl command ' + aidl_tool_path) ] framework_aidl_path = glob.glob( os.path.join(input_api.change.RepositoryRoot(), 'third_party', 'android_sdk', 'public', 'platforms', '*', 'framework.aidl'))[0] logging.debug('Using framework.aidl at path %s', framework_aidl_path) tmp_old_contents_dir = tempfile.mkdtemp() tmp_old_aidl_dir = tempfile.mkdtemp() tmp_new_aidl_dir = tempfile.mkdtemp() aidl_src_dir = aidl_files[0].java_root_dir generate_old_api_cmd = [ aidl_tool_path, '--dumpapi', '--out', tmp_old_aidl_dir, ('-p' + framework_aidl_path), ('-I' + aidl_src_dir) ] generate_new_api_cmd = [ aidl_tool_path, '--dumpapi', '--out', tmp_new_aidl_dir, ('-p' + framework_aidl_path), ('-I' + aidl_src_dir) ] # The following generates the aidl api dump (both original and new) for any # changed file. The dumps are then compared using --checkapi. try: valid_file = False for aidl_file in aidl_files: old_contents = '\n'.join(aidl_file.affected_file.OldContents()) if len(old_contents) == 0: # When |old_contents| is empty it indicates a new file, which is # implicitly compatible. continue old_contents_file_path = aidl_file.GetPathRelativeTo( tmp_old_contents_dir) # aidl expects the directory to match the java package names. if not os.path.isdir(os.path.dirname(old_contents_file_path)): os.makedirs(os.path.dirname(old_contents_file_path)) with open(old_contents_file_path, 'w') as old_contents_file: old_contents_file.write(old_contents) generate_old_api_cmd += [old_contents_file_path] generate_new_api_cmd += [aidl_file.path_in_repo] valid_file = True if not valid_file: return [] logging.debug('Generating old api %s', generate_old_api_cmd) result = subprocess.call(generate_old_api_cmd) if result != 0: return [ output_api.PresubmitError('Error generating old aidl api dump') ] logging.debug('Generating new api %s', generate_new_api_cmd) result = subprocess.call(generate_new_api_cmd) if result != 0: return [output_api.PresubmitError('Error generating new aidl api')] logging.debug('Diffing api') result = subprocess.call( [aidl_tool_path, '--checkapi', tmp_old_aidl_dir, tmp_new_aidl_dir]) if result != 0: return [ output_api.PresubmitPromptWarning( _INCOMPATIBLE_API_ERROR_STRING) ] finally: shutil.rmtree(tmp_old_contents_dir) shutil.rmtree(tmp_old_aidl_dir) shutil.rmtree(tmp_new_aidl_dir) return []
# Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """This module wraps Android's split-select tool.""" from devil.android.sdk import build_tools from devil.utils import cmd_helper from devil.utils import lazy _split_select_path = lazy.WeakConstant(lambda: build_tools.GetPath( 'split-select')) def _RunSplitSelectCmd(args): """Runs a split-select command. Args: args: A list of arguments for split-select. Returns: The output of the command. """ cmd = [_split_select_path.read()] + args status, output = cmd_helper.GetCmdStatusAndOutput(cmd) if status != 0: raise Exception('Failed running command "%s" with output "%s".' % (' '.join(cmd), output)) return output def _SplitConfig(device, allow_cached_props=False):
# Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """This module wraps the Android Asset Packaging Tool.""" from devil.android.sdk import build_tools from devil.utils import cmd_helper from devil.utils import lazy _aapt_path = lazy.WeakConstant(lambda: build_tools.GetPath('aapt')) def _RunAaptCmd(args): """Runs an aapt command. Args: args: A list of arguments for aapt. Returns: The output of the command. """ cmd = [_aapt_path.read()] + args status, output = cmd_helper.GetCmdStatusAndOutput(cmd) if status != 0: raise Exception('Failed running aapt command: "%s" with output "%s".' % (' '.join(cmd), output)) return output def Dump(what, apk, assets=None): """Returns the output of the aapt dump command.
# Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import six from devil.android.sdk import build_tools from devil.utils import cmd_helper from devil.utils import lazy _dexdump_path = lazy.WeakConstant(lambda: build_tools.GetPath('dexdump')) def DexDump(dexfiles, file_summary=False): """A wrapper around the Android SDK's dexdump tool. Args: dexfiles: The dexfile or list of dex files to dump. file_summary: Display summary information from the file header. (-f) Returns: An iterable over the output lines. """ # TODO(jbudorick): Add support for more options as necessary. if isinstance(dexfiles, six.string_types): dexfiles = [dexfiles] args = [_dexdump_path.read()] + dexfiles if file_summary: args.append('-f') return cmd_helper.IterCmdOutputLines(args)