Ejemplo n.º 1
0
def main():
  argparser = argparse.ArgumentParser(description='Print APK size metrics.')
  argparser.add_argument('--min-pak-resource-size', type=int, default=20*1024,
                         help='Minimum byte size of displayed pak resources.')
  argparser.add_argument('--chromium-output-directory',
                         help='Location of the build artifacts.')
  argparser.add_argument('--chartjson', action='store_true',
                         help='Sets output mode to chartjson.')
  argparser.add_argument('--output-dir', default='.',
                         help='Directory to save chartjson to.')
  argparser.add_argument('--no-output-dir', action='store_true',
                         help='Skip all measurements that rely on having '
                         'output-dir')
  argparser.add_argument('--no-static-initializer-check', action='store_false',
                         dest='static_initializer_check', default=True,
                         help='Skip checking for static initializers')
  argparser.add_argument('-d', '--device',
                         help='Dummy option for perf runner.')
  argparser.add_argument('--estimate-patch-size', action='store_true',
                         help='Include patch size estimates. Useful for perf '
                         'builders where a reference APK is available but adds '
                         '~3 mins to run time.')
  argparser.add_argument('--reference-apk-builder',
                         default=apk_downloader.DEFAULT_BUILDER,
                         help='Builder name to use for reference APK for patch '
                         'size estimates.')
  argparser.add_argument('--reference-apk-bucket',
                         default=apk_downloader.DEFAULT_BUCKET,
                         help='Storage bucket holding reference APKs.')
  argparser.add_argument('apk', help='APK file path.')
  args = argparser.parse_args()

  chartjson = _BASE_CHART.copy() if args.chartjson else None

  if args.chromium_output_directory:
    constants.SetOutputDirectory(args.chromium_output_directory)
  if not args.no_output_dir:
    constants.CheckOutputDirectory()
    devil_chromium.Initialize()
    build_vars = _ReadBuildVars(constants.GetOutDirectory())
    tools_prefix = os.path.join(constants.GetOutDirectory(),
                                build_vars['android_tool_prefix'])
  else:
    tools_prefix = ''

  PrintApkAnalysis(args.apk, tools_prefix, chartjson=chartjson)
  _PrintDexAnalysis(args.apk, chartjson=chartjson)
  if args.estimate_patch_size:
    _PrintPatchSizeEstimate(args.apk, args.reference_apk_builder,
                            args.reference_apk_bucket, chartjson=chartjson)
  if not args.no_output_dir:
    PrintPakAnalysis(args.apk, args.min_pak_resource_size)
    if args.static_initializer_check:
      _PrintStaticInitializersCountFromApk(
          args.apk, tools_prefix, chartjson=chartjson)
  if chartjson:
    results_path = os.path.join(args.output_dir, 'results-chart.json')
    logging.critical('Dumping json to %s', results_path)
    with open(results_path, 'w') as json_file:
      json.dump(chartjson, json_file)
Ejemplo n.º 2
0
def main():
    custom_handler = logging.StreamHandler(sys.stdout)
    custom_handler.setFormatter(run_tests_helper.CustomFormatter())
    logging.getLogger().addHandler(custom_handler)
    logging.getLogger().setLevel(logging.INFO)

    parser = optparse.OptionParser()
    parser.add_option('--device',
                      help='The serial number of the device. If not specified '
                      'will use all devices.')
    parser.add_option('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_option(
        '-a',
        '--all-tombstones',
        action='store_true',
        help="""Resolve symbols for all tombstones, rather than just
                         the most recent""")
    parser.add_option('-s',
                      '--stack',
                      action='store_true',
                      help='Also include symbols for stack data')
    parser.add_option('-w',
                      '--wipe-tombstones',
                      action='store_true',
                      help='Erase all tombstones from device after processing')
    parser.add_option('-j',
                      '--jobs',
                      type='int',
                      default=4,
                      help='Number of jobs to use when processing multiple '
                      'crash stacks.')
    parser.add_option('--output-directory',
                      help='Path to the root build directory.')
    options, _ = parser.parse_args()

    devil_chromium.Initialize()

    blacklist = (device_blacklist.Blacklist(options.blacklist_file)
                 if options.blacklist_file else None)

    if options.output_directory:
        constants.SetOutputDirectory(options.output_directory)
    # Do an up-front test that the output directory is known.
    constants.CheckOutputDirectory()

    if options.device:
        devices = [device_utils.DeviceUtils(options.device)]
    else:
        devices = device_utils.DeviceUtils.HealthyDevices(blacklist)

    # This must be done serially because strptime can hit a race condition if
    # used for the first time in a multithreaded environment.
    # http://bugs.python.org/issue7980
    tombstones = []
    for device in devices:
        tombstones += _GetTombstonesForDevice(device, options)

    _ResolveTombstones(options.jobs, tombstones)
Ejemplo n.º 3
0
def _ConfigOutDir(out_dir):
  if out_dir:
    constants.SetOutputDirectory(out_dir)
  else:
    try:
      # Triggers auto-detection when CWD == output directory.
      constants.CheckOutputDirectory()
      out_dir = constants.GetOutDirectory()
    except Exception:  # pylint: disable=broad-except
      pass
  return out_dir
Ejemplo n.º 4
0
def main():
  custom_handler = logging.StreamHandler(sys.stdout)
  custom_handler.setFormatter(run_tests_helper.CustomFormatter())
  logging.getLogger().addHandler(custom_handler)
  logging.getLogger().setLevel(logging.INFO)

  parser = argparse.ArgumentParser()
  parser.add_argument('--device',
                      help='The serial number of the device. If not specified '
                           'will use all devices.')
  parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
  parser.add_argument('-a', '--all-tombstones', action='store_true',
                      help='Resolve symbols for all tombstones, rather than '
                           'just the most recent.')
  parser.add_argument('-s', '--stack', action='store_true',
                      help='Also include symbols for stack data')
  parser.add_argument('-w', '--wipe-tombstones', action='store_true',
                      help='Erase all tombstones from device after processing')
  parser.add_argument('-j', '--jobs', type=int,
                      default=4,
                      help='Number of jobs to use when processing multiple '
                           'crash stacks.')
  parser.add_argument('--output-directory',
                      help='Path to the root build directory.')
  parser.add_argument('--adb-path', type=os.path.abspath,
                      help='Path to the adb binary.')
  args = parser.parse_args()

  devil_chromium.Initialize(adb_path=args.adb_path)

  blacklist = (device_blacklist.Blacklist(args.blacklist_file)
               if args.blacklist_file
               else None)

  if args.output_directory:
    constants.SetOutputDirectory(args.output_directory)
  # Do an up-front test that the output directory is known.
  constants.CheckOutputDirectory()

  if args.device:
    devices = [device_utils.DeviceUtils(args.device)]
  else:
    devices = device_utils.DeviceUtils.HealthyDevices(blacklist)

  # This must be done serially because strptime can hit a race condition if
  # used for the first time in a multithreaded environment.
  # http://bugs.python.org/issue7980
  for device in devices:
    resolved_tombstones = ResolveTombstones(
        device, args.all_tombstones,
        args.stack, args.wipe_tombstones, args.jobs)
    for line in resolved_tombstones:
      logging.info(line)
Ejemplo n.º 5
0
def _ConfigOutDirAndToolsPrefix(out_dir):
    if out_dir:
        constants.SetOutputDirectory(out_dir)
    else:
        try:
            # Triggers auto-detection when CWD == output directory.
            constants.CheckOutputDirectory()
            out_dir = constants.GetOutDirectory()
        except Exception:  # pylint: disable=broad-except
            return out_dir, ''
    build_vars = gn_helpers.ReadBuildVars(out_dir)
    tool_prefix = os.path.join(out_dir, build_vars['android_tool_prefix'])
    return out_dir, tool_prefix
Ejemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__ + _list_benchmarks(),
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('benchmark',
                        nargs='+',
                        metavar='BENCHMARK',
                        choices=_BENCHMARKS.keys(),
                        help='Names of default benchmark(s) to run.')
    parser.add_argument('-A',
                        '--args',
                        choices=_GN_ARG_PRESETS.keys(),
                        default='fast_local_dev',
                        help='The set of GN args to use for these benchmarks.')
    parser.add_argument('-r',
                        '--repeat',
                        type=int,
                        default=1,
                        help='Number of times to repeat the benchmark.')
    parser.add_argument(
        '-C',
        '--output-directory',
        help='If outdir is not provided, will attempt to guess.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=0,
                        help='1 to print logging, 2 to print ninja output.')
    args = parser.parse_args()

    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    out_dir = constants.GetOutDirectory()

    if args.verbose >= 2:
        level = logging.DEBUG
    elif args.verbose == 1:
        level = logging.INFO
    else:
        level = logging.WARNING
    logging.basicConfig(
        level=level, format='%(levelname).1s %(relativeCreated)6d %(message)s')

    gn_args = _GN_ARG_PRESETS[args.args]
    results = run_benchmarks(args.benchmark, gn_args, out_dir, args.repeat)

    print('Summary')
    print(f'gn args: {" ".join(gn_args)}')
    for name, result in results:
        print(f'{name}: {_format_result(result)}')
Ejemplo n.º 7
0
def main():
    argparser = argparse.ArgumentParser(description='Print APK size metrics.')
    argparser.add_argument(
        '--min-pak-resource-size',
        type=int,
        default=20 * 1024,
        help='Minimum byte size of displayed pak resources.')
    argparser.add_argument('--chromium-output-directory',
                           help='Location of the build artifacts.')
    argparser.add_argument('--chartjson',
                           action='store_true',
                           help='Sets output mode to chartjson.')
    argparser.add_argument('--output-dir',
                           default='.',
                           help='Directory to save chartjson to.')
    argparser.add_argument('--no-output-dir',
                           action='store_true',
                           help='Skip all measurements that rely on having '
                           'output-dir')
    argparser.add_argument('-d',
                           '--device',
                           help='Dummy option for perf runner.')
    argparser.add_argument('apk', help='APK file path.')
    args = argparser.parse_args()

    chartjson = _BASE_CHART.copy() if args.chartjson else None

    if args.chromium_output_directory:
        constants.SetOutputDirectory(args.chromium_output_directory)
    if not args.no_output_dir:
        constants.CheckOutputDirectory()
        devil_chromium.Initialize()
        build_vars = _ReadBuildVars(constants.GetOutDirectory())
        tools_prefix = build_vars['android_tool_prefix']
    else:
        tools_prefix = ''

    PrintApkAnalysis(args.apk, tools_prefix, chartjson=chartjson)
    _PrintDexAnalysis(args.apk, chartjson=chartjson)
    if not args.no_output_dir:
        PrintPakAnalysis(args.apk, args.min_pak_resource_size)
        _PrintStaticInitializersCountFromApk(args.apk,
                                             tools_prefix,
                                             chartjson=chartjson)
    if chartjson:
        results_path = os.path.join(args.output_dir, 'results-chart.json')
        logging.critical('Dumping json to %s', results_path)
        with open(results_path, 'w') as json_file:
            json.dump(chartjson, json_file)
Ejemplo n.º 8
0
def main():
    arg_parser = argparse.ArgumentParser(
        description='Finds which build target contains a particular Java class.'
    )

    arg_parser.add_argument('-C',
                            '--output-directory',
                            help='Build output directory.')
    arg_parser.add_argument('classes',
                            nargs='+',
                            help=f'Java classes to search for')
    arg_parser.add_argument('-v',
                            '--verbose',
                            action='store_true',
                            help=f'Verbose logging.')

    arguments = arg_parser.parse_args()

    logging.basicConfig(
        level=logging.DEBUG if arguments.verbose else logging.WARNING,
        format='%(asctime)s.%(msecs)03d %(levelname).1s %(message)s',
        datefmt='%H:%M:%S')

    if arguments.output_directory:
        constants.SetOutputDirectory(arguments.output_directory)
    constants.CheckOutputDirectory()
    out_dir: str = constants.GetOutDirectory()

    index = ClassLookupIndex(pathlib.Path(out_dir))
    for class_name in arguments.classes:
        class_entries = index.match(class_name)
        if not class_entries:
            print(f'Could not find build target for class "{class_name}"')
        elif len(class_entries) == 1:
            class_entry = class_entries[0]
            print(f'Class {class_entry.full_class_name} found:')
            print(f'    "{class_entry.target}"')
        else:
            print(f'Multiple targets with classes that match "{class_name}":')
            print()
            for class_entry in class_entries:
                print(f'    "{class_entry.target}"')
                print(f'        contains {class_entry.full_class_name}')
                print()
def main():
  parser = optparse.OptionParser()
  parser.add_option('-l', '--logcat',
                    help='File containing adb logcat output with ASan stacks. '
                         'Use stdin if not specified.')
  parser.add_option('--output-directory',
                    help='Path to the root build directory.')
  options, _ = parser.parse_args()

  if options.output_directory:
    constants.SetOutputDirectory(options.output_directory)
  # Do an up-front test that the output directory is known.
  constants.CheckOutputDirectory()

  if options.logcat:
    asan_input = file(options.logcat, 'r')
  else:
    asan_input = sys.stdin
  _Symbolize(asan_input.readlines())
Ejemplo n.º 10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-l',
                        '--logcat',
                        help='File containing adb logcat output with ASan '
                        'stacks. Use stdin if not specified.')
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('--arch', default='arm', help='CPU architecture name')
    args = parser.parse_args()

    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    # Do an up-front test that the output directory is known.
    constants.CheckOutputDirectory()

    if args.logcat:
        asan_input = open(args.logcat, 'r')
    else:
        asan_input = sys.stdin

    _PrintSymbolized(asan_input.readlines(), args.arch)
Ejemplo n.º 11
0
def _CreateClassToFileNameDict(test_apk):
    """Creates a dict mapping classes to file names from size-info apk."""
    constants.CheckOutputDirectory()
    test_apk_size_info = os.path.join(constants.GetOutDirectory(), 'size-info',
                                      os.path.basename(test_apk) + '.jar.info')

    class_to_file_dict = {}
    # Some tests such as webview_cts_tests use a separately downloaded apk to run
    # tests. This means the apk may not have been built by the system and hence
    # no size info file exists.
    if not os.path.exists(test_apk_size_info):
        logging.debug('Apk size file not found. %s', test_apk_size_info)
        return class_to_file_dict

    with open(test_apk_size_info, 'r') as f:
        for line in f:
            file_class, file_name = line.rstrip().split(',', 1)
            # Only want files that are not prebuilt.
            if file_name.startswith('../../'):
                class_to_file_dict[file_class] = str(
                    file_name.replace('../../', '//', 1))

    return class_to_file_dict
Ejemplo n.º 12
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__ + _list_benchmarks(),
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('benchmark',
                        nargs='+',
                        metavar='BENCHMARK',
                        choices=list(_all_benchmark_and_suite_names()),
                        help='Names of benchmark(s) or suites(s) to run.')
    parser.add_argument('-A',
                        '--args',
                        choices=_GN_ARG_PRESETS.keys(),
                        default='incremental_install',
                        help='The set of GN args to use for these benchmarks.')
    parser.add_argument('--bundle',
                        action='store_true',
                        help='Switch the default target from apk to bundle.')
    parser.add_argument('--no-server',
                        action='store_true',
                        help='Do not start a faster local dev server before '
                        'running the test.')
    parser.add_argument('-r',
                        '--repeat',
                        type=int,
                        default=1,
                        help='Number of times to repeat the benchmark.')
    parser.add_argument(
        '-C',
        '--output-directory',
        help='If outdir is not provided, will attempt to guess.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=0,
                        help='1 to print logging, 2 to print ninja output.')
    args = parser.parse_args()

    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    out_dir: str = constants.GetOutDirectory()

    if args.verbose >= 2:
        level = logging.DEBUG
    elif args.verbose == 1:
        level = logging.INFO
    else:
        level = logging.WARNING
    logging.basicConfig(
        level=level, format='%(levelname).1s %(relativeCreated)6d %(message)s')

    target = _TARGETS['bundle' if args.bundle else 'apk']
    gn_args = _GN_ARG_PRESETS[args.args]
    results = run_benchmarks(args.benchmark, gn_args, out_dir, target,
                             args.repeat, args.no_server)

    print(f'Summary ({"not " if args.no_server else ""}using build server)')
    print(f'gn args: {" ".join(gn_args)}')
    print(f'target: {target}')
    for name, result in results:
        print(f'{name}: {_format_result(result)}')
Ejemplo n.º 13
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level')
    parser.add_argument('--target',
                        help='GN target to generate project for.',
                        default='//chrome/android:chrome_public_apk')
    parser.add_argument('--project-dir',
                        help='Root of the output project.',
                        default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
    parser.add_argument('--use-gradle-process-resources',
                        action='store_true',
                        help='Have gradle generate R.java rather than ninja')
    args = parser.parse_args()
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()
    devil_chromium.Initialize(output_directory=output_dir)
    run_tests_helper.SetLogLevel(args.verbose_count)

    gradle_output_dir = os.path.abspath(
        args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
    logging.warning('Creating project at: %s', gradle_output_dir)

    main_entry = _ProjectEntry(args.target)
    logging.warning('Building .build_config files...')
    _RunNinja(output_dir, [main_entry.NinjaBuildConfigTarget()])

    all_entries = _FindAllProjectEntries(main_entry)
    logging.info('Found %d dependent build_config targets.', len(all_entries))

    config_json = build_utils.ReadJson(
        os.path.join(output_dir, 'gradle', 'config.json'))
    project_entries = []
    srcjar_tuples = []
    for entry in all_entries:
        build_config = entry.BuildConfig()
        if build_config['deps_info']['type'] not in ('android_apk',
                                                     'java_library'):
            continue

        entry_output_dir = os.path.join(gradle_output_dir,
                                        entry.GradleSubdir())
        relativize = lambda x, d=entry_output_dir: _RebasePath(x, d)

        srcjars = _RebasePath(build_config['gradle'].get(
            'bundled_srcjars', []))
        if not args.use_gradle_process_resources:
            srcjars += _RebasePath(build_config['javac']['srcjars'])

        java_sources_file = build_config['gradle'].get('java_sources_file')
        if java_sources_file:
            java_sources_file = _RebasePath(java_sources_file)

        java_dirs = _CreateJavaSourceDir(entry_output_dir, java_sources_file)
        if srcjars:
            java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR))

        data = _GenerateGradleFile(build_config, config_json, java_dirs,
                                   relativize,
                                   args.use_gradle_process_resources)
        if data:
            project_entries.append(entry)
            srcjar_tuples.extend(
                (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR))
                for s in srcjars)
            _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data)

    _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'),
               _GenerateRootGradle())

    _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'),
               _GenerateSettingsGradle(project_entries))

    sdk_path = _RebasePath(config_json['android_sdk_root'])
    _WriteFile(os.path.join(gradle_output_dir, 'local.properties'),
               _GenerateLocalProperties(sdk_path))

    if srcjar_tuples:
        logging.warning('Building all .srcjar files...')
        targets = _RebasePath([s[0] for s in srcjar_tuples], output_dir)
        _RunNinja(output_dir, targets)
        _ExtractSrcjars(gradle_output_dir, srcjar_tuples)
    logging.warning('Project created successfully!')
Ejemplo n.º 14
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '-C',
        '--output-directory',
        help='If outdir is not provided, will attempt to guess.')
    parser.add_argument('--gn-labels',
                        action='store_true',
                        help='Print GN labels rather than ninja targets')
    parser.add_argument(
        '--nested',
        action='store_true',
        help='Do not convert nested targets to their top-level equivalents. '
        'E.g. Without this, foo_test__apk -> foo_test')
    parser.add_argument('--print-types',
                        action='store_true',
                        help='Print type of each target')
    parser.add_argument('--build-build-configs',
                        action='store_true',
                        help='Build all .build_config files.')
    parser.add_argument('--type',
                        action='append',
                        help='Restrict to targets of given type',
                        choices=_VALID_TYPES)
    parser.add_argument('--stats',
                        action='store_true',
                        help='Print counts of each target type.')
    parser.add_argument('-v', '--verbose', default=0, action='count')
    args = parser.parse_args()

    args.build_build_configs |= bool(args.type or args.print_types
                                     or args.stats)

    logging.basicConfig(
        level=logging.WARNING - (10 * args.verbose),
        format='%(levelname).1s %(relativeCreated)6d %(message)s')

    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()

    # Query ninja for all __build_config_crbug_908819 targets.
    targets = _query_for_build_config_targets(output_dir)
    entries = [_TargetEntry(t) for t in targets]

    if args.build_build_configs:
        logging.warning('Building %d .build_config files...', len(entries))
        _run_ninja(output_dir, [e.ninja_build_config_target for e in entries])

    if args.type:
        entries = [e for e in entries if e.get_type() in args.type]

    if args.stats:
        counts = collections.Counter(e.get_type() for e in entries)
        for entry_type, count in sorted(counts.items()):
            print(f'{entry_type}: {count}')
    else:
        for e in entries:
            if args.gn_labels:
                to_print = e.gn_target
            else:
                to_print = e.ninja_target

            # Convert to top-level target
            if not args.nested:
                to_print = to_print.replace('__test_apk__apk',
                                            '').replace('__apk', '')

            if args.print_types:
                to_print = f'{to_print}: {e.get_type()}'

            print(to_print)
Ejemplo n.º 15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level')
    parser.add_argument(
        '--target',
        dest='targets',
        action='append',
        help='GN target to generate project for. Replaces set of '
        'default targets. May be repeated.')
    parser.add_argument(
        '--extra-target',
        dest='extra_targets',
        action='append',
        help='GN target to generate project for, in addition to '
        'the default ones. May be repeated.')
    parser.add_argument('--project-dir',
                        help='Root of the output project.',
                        default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
    parser.add_argument('--all',
                        action='store_true',
                        help='Include all .java files reachable from any '
                        'apk/test/binary target. On by default unless '
                        '--split-projects is used (--split-projects can '
                        'slow down Studio given too many targets).')
    parser.add_argument('--use-gradle-process-resources',
                        action='store_true',
                        help='Have gradle generate R.java rather than ninja')
    parser.add_argument('--split-projects',
                        action='store_true',
                        help='Split projects by their gn deps rather than '
                        'combining all the dependencies of each target')
    version_group = parser.add_mutually_exclusive_group()
    version_group.add_argument(
        '--beta',
        action='store_true',
        help='Generate a project that is compatible with '
        'Android Studio Beta.')
    version_group.add_argument(
        '--canary',
        action='store_true',
        help='Generate a project that is compatible with '
        'Android Studio Canary.')
    sdk_group = parser.add_mutually_exclusive_group()
    sdk_group.add_argument(
        '--sdk',
        choices=[
            'AndroidStudioCurrent', 'AndroidStudioDefault', 'ChromiumSdkRoot'
        ],
        default='ChromiumSdkRoot',
        help="Set the project's SDK root. This can be set to "
        "Android Studio's current SDK root, the default "
        "Android Studio SDK root, or Chromium's SDK "
        "root. The default is Chromium's SDK root, but "
        "using this means that updates and additions to "
        "the SDK (e.g. installing emulators), will "
        "modify this root, hence possibly causing "
        "conflicts on the next repository sync.")
    sdk_group.add_argument(
        '--sdk-path',
        help='An explict path for the SDK root, setting this '
        'is an alternative to setting the --sdk option')
    args = parser.parse_args()
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()
    devil_chromium.Initialize(output_directory=output_dir)
    run_tests_helper.SetLogLevel(args.verbose_count)

    if args.use_gradle_process_resources:
        assert args.split_projects, (
            'Gradle resources does not work without --split-projects.')

    _gradle_output_dir = os.path.abspath(
        args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
    jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
    build_vars = _ReadPropertiesFile(os.path.join(output_dir,
                                                  'build_vars.txt'))
    source_properties = _ReadPropertiesFile(
        _RebasePath(
            os.path.join(build_vars['android_sdk_build_tools'],
                         'source.properties')))
    if args.beta:
        channel = 'beta'
    elif args.canary:
        channel = 'canary'
    else:
        channel = 'stable'
    generator = _ProjectContextGenerator(_gradle_output_dir, build_vars,
                                         args.use_gradle_process_resources,
                                         jinja_processor, args.split_projects,
                                         channel)
    logging.warning('Creating project at: %s', generator.project_dir)

    # Generate for "all targets" by default when not using --split-projects (too
    # slow), and when no --target has been explicitly set. "all targets" means all
    # java targets that are depended on by an apk or java_binary (leaf
    # java_library targets will not be included).
    args.all = args.all or (not args.split_projects and not args.targets)

    targets_from_args = set(args.targets or _DEFAULT_TARGETS)
    if args.extra_targets:
        targets_from_args.update(args.extra_targets)

    if args.all:
        # Run GN gen if necessary (faster than running "gn gen" in the no-op case).
        _RunNinja(constants.GetOutDirectory(), ['build.ninja'])
        # Query ninja for all __build_config targets.
        targets = _QueryForAllGnTargets(output_dir)
    else:
        targets = [
            re.sub(r'_test_apk$', '_test_apk__apk', t)
            for t in targets_from_args
        ]

    main_entries = [_ProjectEntry.FromGnTarget(t) for t in targets]

    logging.warning('Building .build_config files...')
    _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries])

    if args.all:
        # There are many unused libraries, so restrict to those that are actually
        # used by apks/binaries/tests or that are explicitly mentioned in --targets.
        main_entries = [
            e for e in main_entries
            if (e.GetType() in ('android_apk', 'java_binary',
                                'junit_binary') or e.GnTarget() in
                targets_from_args or e.GnTarget().endswith('_test_apk__apk'))
        ]

    if args.split_projects:
        main_entries = _FindAllProjectEntries(main_entries)

    logging.info('Generating for %d targets.', len(main_entries))

    entries = [e for e in _CombineTestEntries(main_entries) if e.IsValid()]
    logging.info('Creating %d projects for targets.', len(entries))

    # When only one entry will be generated we want it to have a valid
    # build.gradle file with its own AndroidManifest.
    add_all_module = not args.split_projects and len(entries) > 1

    logging.warning('Writing .gradle files...')
    project_entries = []
    zip_tuples = []
    generated_inputs = []
    for entry in entries:
        data = _GenerateGradleFile(entry, generator, build_vars,
                                   source_properties, jinja_processor)
        if data:
            # Build all paths references by .gradle that exist within output_dir.
            generated_inputs.extend(generator.GeneratedInputs(entry))
            zip_tuples.extend((
                s,
                os.path.join(generator.EntryOutputDir(entry), _SRCJARS_SUBDIR))
                              for s in generator.AllSrcjars(entry))
            zip_tuples.extend(
                (s, os.path.join(generator.EntryOutputDir(entry), _RES_SUBDIR))
                for s in generator.AllResZips(entry))
            if not add_all_module:
                project_entries.append(entry)
                _WriteFile(
                    os.path.join(generator.EntryOutputDir(entry),
                                 _GRADLE_BUILD_FILE), data)

    if add_all_module:
        _GenerateModuleAll(_gradle_output_dir, generator, build_vars,
                           source_properties, jinja_processor)

    _WriteFile(os.path.join(generator.project_dir, _GRADLE_BUILD_FILE),
               _GenerateRootGradle(jinja_processor, channel))

    _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'),
               _GenerateSettingsGradle(project_entries, add_all_module))

    if args.sdk != "AndroidStudioCurrent":
        if args.sdk_path:
            sdk_path = _RebasePath(args.sdk_path)
        elif args.sdk == "AndroidStudioDefault":
            sdk_path = os.path.expanduser('~/Android/Sdk')
        else:
            sdk_path = _RebasePath(build_vars['android_sdk_root'])
        _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
                   _GenerateLocalProperties(sdk_path))

    if generated_inputs:
        logging.warning('Building generated source files...')
        targets = _RebasePath(generated_inputs, output_dir)
        _RunNinja(output_dir, targets)

    if zip_tuples:
        _ExtractZips(generator.project_dir, zip_tuples)

    logging.warning('Project created!')
    logging.warning('Generated projects work with Android Studio %s', channel)
    logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                    '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 16
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level')
    parser.add_argument(
        '--target',
        dest='targets',
        action='append',
        help='GN target to generate project for. Replaces set of '
        'default targets. May be repeated.')
    parser.add_argument(
        '--extra-target',
        dest='extra_targets',
        action='append',
        help='GN target to generate project for, in addition to '
        'the default ones. May be repeated.')
    parser.add_argument('--project-dir',
                        help='Root of the output project.',
                        default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
    parser.add_argument('--all',
                        action='store_true',
                        help='Generate all java targets (slows down IDE)')
    parser.add_argument('--use-gradle-process-resources',
                        action='store_true',
                        help='Have gradle generate R.java rather than ninja')
    parser.add_argument('--split-projects',
                        action='store_true',
                        help='Split projects by their gn deps rather than '
                        'combining all the dependencies of each target')
    args = parser.parse_args()
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()
    devil_chromium.Initialize(output_directory=output_dir)
    run_tests_helper.SetLogLevel(args.verbose_count)

    if args.use_gradle_process_resources:
        assert args.split_projects, (
            'Gradle resources does not work without --split-projects.')

    _gradle_output_dir = os.path.abspath(
        args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
    jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
    build_vars = _ReadPropertiesFile(os.path.join(output_dir,
                                                  'build_vars.txt'))
    source_properties = _ReadPropertiesFile(
        _RebasePath(
            os.path.join(build_vars['android_sdk_build_tools'],
                         'source.properties')))
    generator = _ProjectContextGenerator(_gradle_output_dir, build_vars,
                                         args.use_gradle_process_resources,
                                         jinja_processor, args.split_projects)
    logging.warning('Creating project at: %s', generator.project_dir)

    if args.all:
        # Run GN gen if necessary (faster than running "gn gen" in the no-op case).
        _RunNinja(constants.GetOutDirectory(), ['build.ninja'])
        # Query ninja for all __build_config targets.
        targets = _QueryForAllGnTargets(output_dir)
    else:
        targets = args.targets or _DEFAULT_TARGETS
        if args.extra_targets:
            targets.extend(args.extra_targets)
        targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets]
        # TODO(wnwen): Utilize Gradle's test constructs for our junit tests?
        targets = [
            re.sub(r'_junit_tests$', '_junit_tests__java_binary', t)
            for t in targets
        ]

    main_entries = [_ProjectEntry.FromGnTarget(t) for t in targets]

    logging.warning('Building .build_config files...')
    _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries])

    # There are many unused libraries, so restrict to those that are actually used
    # when using --all.
    if args.all:
        main_entries = [
            e for e in main_entries
            if (e.GetType() == 'android_apk'
                or e.GnTarget().endswith('_test_apk__apk')
                or e.GnTarget().endswith('_junit_tests__java_binary'))
        ]

    if args.split_projects:
        main_entries = _FindAllProjectEntries(main_entries)
        logging.info('Found %d dependent build_config targets.',
                     len(main_entries))

    entries = [e for e in _CombineTestEntries(main_entries) if e.IsValid()]
    logging.info('Creating %d projects for targets.', len(entries))

    # When only one entry will be generated we want it to have a valid
    # build.gradle file with its own AndroidManifest.
    add_all_module = not args.split_projects and len(entries) > 1

    logging.warning('Writing .gradle files...')
    project_entries = []
    zip_tuples = []
    generated_inputs = []
    for entry in entries:
        data = _GenerateGradleFile(entry, generator, build_vars,
                                   source_properties, jinja_processor)
        if data:
            # Build all paths references by .gradle that exist within output_dir.
            generated_inputs.extend(generator.GeneratedInputs(entry))
            zip_tuples.extend((
                s,
                os.path.join(generator.EntryOutputDir(entry), _SRCJARS_SUBDIR))
                              for s in generator.AllSrcjars(entry))
            zip_tuples.extend(
                (s, os.path.join(generator.EntryOutputDir(entry), _RES_SUBDIR))
                for s in generator.AllResZips(entry))
            if not add_all_module:
                project_entries.append(entry)
                _WriteFile(
                    os.path.join(generator.EntryOutputDir(entry),
                                 _GRADLE_BUILD_FILE), data)

    if add_all_module:
        _GenerateModuleAll(_gradle_output_dir, generator, build_vars,
                           source_properties, jinja_processor)

    _WriteFile(os.path.join(generator.project_dir, _GRADLE_BUILD_FILE),
               _GenerateRootGradle(jinja_processor))

    _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'),
               _GenerateSettingsGradle(project_entries, add_all_module))

    sdk_path = _RebasePath(build_vars['android_sdk_root'])
    _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
               _GenerateLocalProperties(sdk_path))

    if generated_inputs:
        logging.warning('Building generated source files...')
        targets = _RebasePath(generated_inputs, output_dir)
        _RunNinja(output_dir, targets)

    if zip_tuples:
        _ExtractZips(generator.project_dir, zip_tuples)

    logging.warning('Project created!')
    logging.warning('Generated projects work with Android Studio 2.3')
    logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                    '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 17
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level')
    parser.add_argument(
        '--target',
        dest='targets',
        action='append',
        help='GN target to generate project for. Replaces set of '
        'default targets. May be repeated.')
    parser.add_argument(
        '--extra-target',
        dest='extra_targets',
        action='append',
        help='GN target to generate project for, in addition to '
        'the default ones. May be repeated.')
    parser.add_argument('--project-dir',
                        help='Root of the output project.',
                        default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
    parser.add_argument('--all',
                        action='store_true',
                        help='Include all .java files reachable from any '
                        'apk/test/binary target. On by default unless '
                        '--split-projects is used (--split-projects can '
                        'slow down Studio given too many targets).')
    parser.add_argument('--use-gradle-process-resources',
                        action='store_true',
                        help='Have gradle generate R.java rather than ninja')
    parser.add_argument('--split-projects',
                        action='store_true',
                        help='Split projects by their gn deps rather than '
                        'combining all the dependencies of each target')
    parser.add_argument('--native-target',
                        dest='native_targets',
                        action='append',
                        help='GN native targets to generate for. May be '
                        'repeated.')
    parser.add_argument(
        '--compile-sdk-version',
        type=int,
        default=0,
        help='Override compileSdkVersion for android sdk docs. '
        'Useful when sources for android_sdk_version is '
        'not available in Android Studio.')
    parser.add_argument('--sdk-path',
                        default=os.path.expanduser('~/Android/Sdk'),
                        help='The path to use as the SDK root, overrides the '
                        'default at ~/Android/Sdk.')
    version_group = parser.add_mutually_exclusive_group()
    version_group.add_argument(
        '--beta',
        action='store_true',
        help='Generate a project that is compatible with '
        'Android Studio Beta.')
    version_group.add_argument(
        '--canary',
        action='store_true',
        help='Generate a project that is compatible with '
        'Android Studio Canary.')
    args = parser.parse_args()
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()
    devil_chromium.Initialize(output_directory=output_dir)
    run_tests_helper.SetLogLevel(args.verbose_count)

    if args.use_gradle_process_resources:
        assert args.split_projects, (
            'Gradle resources does not work without --split-projects.')

    _gradle_output_dir = os.path.abspath(
        args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
    logging.warning('Creating project at: %s', _gradle_output_dir)

    # Generate for "all targets" by default when not using --split-projects (too
    # slow), and when no --target has been explicitly set. "all targets" means all
    # java targets that are depended on by an apk or java_binary (leaf
    # java_library targets will not be included).
    args.all = args.all or (not args.split_projects and not args.targets)

    targets_from_args = set(args.targets or _DEFAULT_TARGETS)
    if args.extra_targets:
        targets_from_args.update(args.extra_targets)

    if args.all:
        if args.native_targets:
            _RunGnGen(output_dir, ['--ide=json'])
        elif not os.path.exists(os.path.join(output_dir, 'build.ninja')):
            _RunGnGen(output_dir)
        else:
            # Faster than running "gn gen" in the no-op case.
            _RunNinja(output_dir, ['build.ninja'])
        # Query ninja for all __build_config_crbug_908819 targets.
        targets = _QueryForAllGnTargets(output_dir)
    else:
        assert not args.native_targets, 'Native editing requires --all.'
        targets = [
            re.sub(r'_test_apk$', _INSTRUMENTATION_TARGET_SUFFIX, t)
            for t in targets_from_args
        ]
        # Necessary after "gn clean"
        if not os.path.exists(os.path.join(output_dir, 'build_vars.txt')):
            _RunGnGen(output_dir)

    build_vars = _ReadPropertiesFile(os.path.join(output_dir,
                                                  'build_vars.txt'))
    jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
    if args.beta:
        channel = 'beta'
    elif args.canary:
        channel = 'canary'
    else:
        channel = 'stable'
    if args.compile_sdk_version:
        build_vars['compile_sdk_version'] = args.compile_sdk_version
    else:
        build_vars['compile_sdk_version'] = build_vars['android_sdk_version']
    generator = _ProjectContextGenerator(_gradle_output_dir, build_vars,
                                         args.use_gradle_process_resources,
                                         jinja_processor, args.split_projects,
                                         channel)

    main_entries = [_ProjectEntry.FromGnTarget(t) for t in targets]

    if args.all:
        # There are many unused libraries, so restrict to those that are actually
        # used by apks/bundles/binaries/tests or that are explicitly mentioned in
        # --targets.
        BASE_TYPES = ('android_apk', 'android_app_bundle_module',
                      'java_binary', 'junit_binary')
        main_entries = [
            e for e in main_entries
            if (e.GetType() in BASE_TYPES or e.GnTarget() in targets_from_args
                or e.GnTarget().endswith(_INSTRUMENTATION_TARGET_SUFFIX))
        ]

    if args.split_projects:
        main_entries = _FindAllProjectEntries(main_entries)

    logging.info('Generating for %d targets.', len(main_entries))

    entries = [e for e in _CombineTestEntries(main_entries) if e.IsValid()]
    logging.info('Creating %d projects for targets.', len(entries))

    logging.warning('Writing .gradle files...')
    project_entries = []
    # When only one entry will be generated we want it to have a valid
    # build.gradle file with its own AndroidManifest.
    for entry in entries:
        data = _GenerateGradleFile(entry, generator, build_vars,
                                   jinja_processor)
        if data and not args.all:
            project_entries.append((entry.ProjectName(), entry.GradleSubdir()))
            _WriteFile(
                os.path.join(generator.EntryOutputDir(entry),
                             _GRADLE_BUILD_FILE), data)
    if args.all:
        project_entries.append((_MODULE_ALL, _MODULE_ALL))
        _GenerateModuleAll(_gradle_output_dir, generator, build_vars,
                           jinja_processor, args.native_targets)

    _WriteFile(os.path.join(generator.project_dir, _GRADLE_BUILD_FILE),
               _GenerateRootGradle(jinja_processor, channel))

    _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'),
               _GenerateSettingsGradle(project_entries))

    # Ensure the Android Studio sdk is correctly initialized.
    if not os.path.exists(args.sdk_path):
        # Help first-time users avoid Android Studio forcibly changing back to
        # the previous default due to not finding a valid sdk under this dir.
        shutil.copytree(_RebasePath(build_vars['android_sdk_root']),
                        args.sdk_path)
    _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
               _GenerateLocalProperties(args.sdk_path))
    _WriteFile(os.path.join(generator.project_dir, 'gradle.properties'),
               _GenerateGradleProperties())

    wrapper_properties = os.path.join(generator.project_dir, 'gradle',
                                      'wrapper', 'gradle-wrapper.properties')
    if os.path.exists(wrapper_properties):
        os.unlink(wrapper_properties)
    if args.canary:
        _WriteFile(wrapper_properties,
                   _GenerateGradleWrapperPropertiesCanary())

    generated_inputs = set()
    for entry in entries:
        entries_to_gen = [entry]
        entries_to_gen.extend(entry.android_test_entries)
        for entry_to_gen in entries_to_gen:
            # Build all paths references by .gradle that exist within output_dir.
            generated_inputs.update(generator.GeneratedInputs(entry_to_gen))
    if generated_inputs:
        targets = _RebasePath(generated_inputs, output_dir)
        _RunNinja(output_dir, targets)

    logging.warning(
        'Generated files will only appear once you\'ve built them.')
    logging.warning('Generated projects for Android Studio %s', channel)
    logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                    '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 18
0
def main(argv):
    usage = """Usage: %prog [options] file1 file2 ...

Pass any number of files to graph their sizes. Any files with the extension
'.apk' will be broken down into their components on a separate graph."""
    option_parser = optparse.OptionParser(usage=usage)
    option_parser.add_option('--so-path', help='Path to libchrome.so.')
    option_parser.add_option('--so-with-symbols-path',
                             help='Path to libchrome.so with symbols.')
    option_parser.add_option(
        '--min-pak-resource-size',
        type='int',
        default=20 * 1024,
        help='Minimum byte size of displayed pak resources.')
    option_parser.add_option('--build_type',
                             dest='build_type',
                             default='Debug',
                             help='Sets the build type, default is Debug.')
    option_parser.add_option('--chromium-output-directory',
                             help='Location of the build artifacts. '
                             'Takes precidence over --build_type.')
    option_parser.add_option('--chartjson',
                             action="store_true",
                             help='Sets output mode to chartjson.')
    option_parser.add_option('--output-dir',
                             default='.',
                             help='Directory to save chartjson to.')
    option_parser.add_option('-d',
                             '--device',
                             help='Dummy option for perf runner.')
    options, args = option_parser.parse_args(argv)
    files = args[1:]
    chartjson = _BASE_CHART.copy() if options.chartjson else None

    constants.SetBuildType(options.build_type)
    if options.chromium_output_directory:
        constants.SetOutputDirectory(options.chromium_output_directory)
    constants.CheckOutputDirectory()

    # For backward compatibilty with buildbot scripts, treat --so-path as just
    # another file to print the size of. We don't need it for anything special any
    # more.
    if options.so_path:
        files.append(options.so_path)

    if not files:
        option_parser.error('Must specify a file')

    devil_chromium.Initialize()

    if options.so_with_symbols_path:
        PrintStaticInitializersCount(options.so_with_symbols_path,
                                     chartjson=chartjson)

    PrintResourceSizes(files, chartjson=chartjson)

    for f in files:
        if f.endswith('.apk'):
            PrintApkAnalysis(f, chartjson=chartjson)
            PrintPakAnalysis(f, options.min_pak_resource_size)

    if chartjson:
        results_path = os.path.join(options.output_dir, 'results-chart.json')
        with open(results_path, 'w') as json_file:
            json.dump(chartjson, json_file)
Ejemplo n.º 19
0
        elif option == "--fallback-monochrome":
            fallback_monochrome = True
        elif option == "--verbose":
            logging.basicConfig(level=logging.DEBUG)
        elif option in ('--packed-relocation-adjustments',
                        '--no-packed-relocation-adjustments'):
            print(
                '--[no-]packed-relocation-adjustments options are deprecated. '
                'Specify packed libs directory instead.')

    if len(arguments) > 1:
        PrintUsage()

    # Do an up-front test that the output directory is known.
    if not symbol.CHROME_SYMBOLS_DIR:
        constants.CheckOutputDirectory()

    print("Reading Android symbols from: " +
          os.path.normpath(symbol.SYMBOLS_DIR))
    chrome_search_path = symbol.GetLibrarySearchPaths()
    print("Searching for Chrome symbols from within: " + ':'.join(
        (os.path.normpath(d) for d in chrome_search_path)))

    rootdir = None
    if zip_arg:
        rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg)

    if not arguments or arguments[0] == "-":
        print "Reading native crash info from stdin"
        with llvm_symbolizer.LLVMSymbolizer() as symbolizer:
            stack_core.StreamingConvertTrace(sys.stdin, {}, more_info,
Ejemplo n.º 20
0
def main(argv, test_symbolizer=None):
    try:
        options, arguments = getopt.getopt(argv, "", [
            "more-info",
            "less-info",
            "chrome-symbols-dir=",
            "output-directory=",
            "apks-directory=",
            "symbols-dir=",
            "symbols-zip=",
            "arch=",
            "fallback-monochrome",
            "verbose",
            "quiet",
            "help",
        ])
    except getopt.GetoptError:
        PrintUsage()

    zip_arg = None
    more_info = False
    fallback_monochrome = False
    arch_defined = False
    apks_directory = None
    log_level = logging.INFO
    for option, value in options:
        if option == "--help":
            PrintUsage()
        elif option == "--symbols-dir":
            symbol.SYMBOLS_DIR = os.path.abspath(os.path.expanduser(value))
        elif option == "--symbols-zip":
            zip_arg = os.path.abspath(os.path.expanduser(value))
        elif option == "--arch":
            symbol.ARCH = value
            arch_defined = True
        elif option == "--chrome-symbols-dir":
            symbol.CHROME_SYMBOLS_DIR = os.path.join(constants.DIR_SOURCE_ROOT,
                                                     value)
        elif option == "--output-directory":
            constants.SetOutputDirectory(os.path.abspath(value))
        elif option == "--apks-directory":
            apks_directory = os.path.abspath(value)
        elif option == "--more-info":
            more_info = True
        elif option == "--less-info":
            more_info = False
        elif option == "--fallback-monochrome":
            fallback_monochrome = True
        elif option == "--verbose":
            log_level = logging.DEBUG
        elif option == "--quiet":
            log_level = logging.WARNING

    if len(arguments) > 1:
        PrintUsage()

    logging.basicConfig(level=log_level)
    # Do an up-front test that the output directory is known.
    if not symbol.CHROME_SYMBOLS_DIR:
        constants.CheckOutputDirectory()

    logging.info('Reading Android symbols from: %s',
                 os.path.normpath(symbol.SYMBOLS_DIR))
    chrome_search_path = symbol.GetLibrarySearchPaths()
    logging.info('Searching for Chrome symbols from within: %s', ':'.join(
        (os.path.normpath(d) for d in chrome_search_path)))

    rootdir = None
    if zip_arg:
        rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg)

    if not arguments or arguments[0] == "-":
        logging.info(
            'Reading native crash info from stdin (symbolization starts '
            'on the first unrelated line or EOF)')
        with llvm_symbolizer.LLVMSymbolizer() as symbolizer:
            stack_core.StreamingConvertTrace(sys.stdin, {}, more_info,
                                             fallback_monochrome, arch_defined,
                                             symbolizer, apks_directory)
    else:
        logging.info('Searching for native crashes in: %s',
                     os.path.realpath(arguments[0]))
        f = open(arguments[0], "r")

        lines = f.readlines()
        f.close()

        # This used to be required when ELF logical addresses did not align with
        # physical addresses, which happened when relocations were converted to APS2
        # format post-link via relocation_packer tool.
        load_vaddrs = {}

        with llvm_symbolizer.LLVMSymbolizer() as symbolizer:
            logging.info(
                'Searching for Chrome symbols from within: %s', ':'.join(
                    (os.path.normpath(d) for d in chrome_search_path)))
            stack_core.ConvertTrace(lines, load_vaddrs, more_info,
                                    fallback_monochrome, arch_defined,
                                    test_symbolizer or symbolizer,
                                    apks_directory)

    if rootdir:
        # be a good citizen and clean up...os.rmdir and os.removedirs() don't work
        cmd = "rm -rf \"%s\"" % rootdir
        logging.info('cleaning up (%s)', cmd)
        os.system(cmd)
Ejemplo n.º 21
0
def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('--output-directory',
                      help='Path to the root build directory.')
  parser.add_argument('-v',
                      '--verbose',
                      dest='verbose_count',
                      default=0,
                      action='count',
                      help='Verbose level')
  parser.add_argument('--target',
                      dest='targets',
                      action='append',
                      help='GN target to generate project for. '
                           'May be repeated.')
  parser.add_argument('--project-dir',
                      help='Root of the output project.',
                      default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
  parser.add_argument('--all',
                      action='store_true',
                      help='Generate all java targets (slows down IDE)')
  parser.add_argument('--use-gradle-process-resources',
                      action='store_true',
                      help='Have gradle generate R.java rather than ninja')
  args = parser.parse_args()
  if args.output_directory:
    constants.SetOutputDirectory(args.output_directory)
  constants.CheckOutputDirectory()
  output_dir = constants.GetOutDirectory()
  devil_chromium.Initialize(output_directory=output_dir)
  run_tests_helper.SetLogLevel(args.verbose_count)

  gradle_output_dir = os.path.abspath(
      args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
  logging.warning('Creating project at: %s', gradle_output_dir)

  if args.all:
    # Run GN gen if necessary (faster than running "gn gen" in the no-op case).
    _RunNinja(output_dir, ['build.ninja'])
    # Query ninja for all __build_config targets.
    targets = _QueryForAllGnTargets(output_dir)
  else:
    targets = args.targets or _DEFAULT_TARGETS
    # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs
    # for our instrumentation tests.
    targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets]

  main_entries = [_ProjectEntry(t) for t in targets]

  logging.warning('Building .build_config files...')
  _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries])

  # There are many unused libraries, so restrict to those that are actually used
  # when using --all.
  if args.all:
    main_entries = [e for e in main_entries if e.GetType() == 'android_apk']

  all_entries = _FindAllProjectEntries(main_entries)
  logging.info('Found %d dependent build_config targets.', len(all_entries))

  logging.warning('Writing .gradle files...')
  jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT)
  config_json = build_utils.ReadJson(
      os.path.join(output_dir, 'gradle', 'config.json'))
  project_entries = []
  srcjar_tuples = []
  for entry in all_entries:
    if entry.GetType() not in ('android_apk', 'java_library'):
      continue

    entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir())
    relativize = lambda x, d=entry_output_dir: _RebasePath(x, d)
    build_config = entry.BuildConfig()

    srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', []))
    if not args.use_gradle_process_resources:
      srcjars += _RebasePath(build_config['javac']['srcjars'])

    java_sources_file = build_config['gradle'].get('java_sources_file')
    if java_sources_file:
      java_sources_file = _RebasePath(java_sources_file)

    java_dirs = _CreateJavaSourceDir(output_dir, entry_output_dir,
                                     java_sources_file)
    if srcjars:
      java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR))

    data = _GenerateGradleFile(build_config, config_json, java_dirs, relativize,
                               args.use_gradle_process_resources,
                               jinja_processor)
    if data:
      project_entries.append(entry)
      srcjar_tuples.extend(
          (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) for s in srcjars)
      _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data)

  _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'),
             _GenerateRootGradle(jinja_processor))

  _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'),
             _GenerateSettingsGradle(project_entries))

  sdk_path = _RebasePath(config_json['android_sdk_root'])
  _WriteFile(os.path.join(gradle_output_dir, 'local.properties'),
             _GenerateLocalProperties(sdk_path))

  if srcjar_tuples:
    logging.warning('Building all .srcjar files...')
    targets = _RebasePath([s[0] for s in srcjar_tuples], output_dir)
    _RunNinja(output_dir, targets)
    _ExtractSrcjars(gradle_output_dir, srcjar_tuples)
  logging.warning('Project created! (%d subprojects)', len(project_entries))
  logging.warning('Generated projects work best with Android Studio 2.2')
  logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                  '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 22
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level')
    parser.add_argument(
        '--target',
        dest='targets',
        action='append',
        help='GN target to generate project for. Replaces set of '
        'default targets. May be repeated.')
    parser.add_argument(
        '--extra-target',
        dest='extra_targets',
        action='append',
        help='GN target to generate project for, in addition to '
        'the default ones. May be repeated.')
    parser.add_argument('--project-dir',
                        help='Root of the output project.',
                        default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
    parser.add_argument('--all',
                        action='store_true',
                        help='Include all .java files reachable from any '
                        'apk/test/binary target. On by default unless '
                        '--split-projects is used (--split-projects can '
                        'slow down Studio given too many targets).')
    parser.add_argument('--use-gradle-process-resources',
                        action='store_true',
                        help='Have gradle generate R.java rather than ninja')
    parser.add_argument('--split-projects',
                        action='store_true',
                        help='Split projects by their gn deps rather than '
                        'combining all the dependencies of each target')
    parser.add_argument(
        '--fast',
        action='store_true',
        help='Skip generating R.java and other generated files.')
    parser.add_argument('-j',
                        default=1000 if os.path.exists(_SRC_INTERNAL) else 50,
                        help='Value for number of parallel jobs for ninja')
    parser.add_argument('--native-target',
                        dest='native_targets',
                        action='append',
                        help='GN native targets to generate for. May be '
                        'repeated.')
    version_group = parser.add_mutually_exclusive_group()
    version_group.add_argument(
        '--beta',
        action='store_true',
        help='Generate a project that is compatible with '
        'Android Studio Beta.')
    version_group.add_argument(
        '--canary',
        action='store_true',
        help='Generate a project that is compatible with '
        'Android Studio Canary.')
    sdk_group = parser.add_mutually_exclusive_group()
    sdk_group.add_argument(
        '--sdk',
        choices=[
            'AndroidStudioCurrent', 'AndroidStudioDefault', 'ChromiumSdkRoot'
        ],
        default='AndroidStudioDefault',
        help="Set the project's SDK root. This can be set to "
        "Android Studio's current SDK root, the default "
        "Android Studio SDK root, or Chromium's SDK "
        "root in //third_party. The default is Android "
        "Studio's SDK root in ~/Android/Sdk.")
    sdk_group.add_argument(
        '--sdk-path',
        help='An explict path for the SDK root, setting this '
        'is an alternative to setting the --sdk option')
    args = parser.parse_args()
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()
    devil_chromium.Initialize(output_directory=output_dir)
    run_tests_helper.SetLogLevel(args.verbose_count)

    if args.use_gradle_process_resources:
        assert args.split_projects, (
            'Gradle resources does not work without --split-projects.')

    _gradle_output_dir = os.path.abspath(
        args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
    logging.warning('Creating project at: %s', _gradle_output_dir)

    # Generate for "all targets" by default when not using --split-projects (too
    # slow), and when no --target has been explicitly set. "all targets" means all
    # java targets that are depended on by an apk or java_binary (leaf
    # java_library targets will not be included).
    args.all = args.all or (not args.split_projects and not args.targets)

    targets_from_args = set(args.targets or _DEFAULT_TARGETS)
    if args.extra_targets:
        targets_from_args.update(args.extra_targets)

    if args.all:
        if args.native_targets:
            _RunGnGen(output_dir, ['--ide=json'])
        elif not os.path.exists(os.path.join(output_dir, 'build.ninja')):
            _RunGnGen(output_dir)
        else:
            # Faster than running "gn gen" in the no-op case.
            _RunNinja(output_dir, ['build.ninja'], args.j)
        # Query ninja for all __build_config targets.
        targets = _QueryForAllGnTargets(output_dir)
    else:
        assert not args.native_targets, 'Native editing requires --all.'
        targets = [
            re.sub(r'_test_apk$', '_test_apk__apk', t)
            for t in targets_from_args
        ]
        # Necessary after "gn clean"
        if not os.path.exists(os.path.join(output_dir, 'build_vars.txt')):
            _RunGnGen(output_dir)

    build_vars = _ReadPropertiesFile(os.path.join(output_dir,
                                                  'build_vars.txt'))
    jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
    if args.beta:
        channel = 'beta'
    elif args.canary:
        channel = 'canary'
    else:
        channel = 'stable'
    generator = _ProjectContextGenerator(_gradle_output_dir, build_vars,
                                         args.use_gradle_process_resources,
                                         jinja_processor, args.split_projects,
                                         channel)

    main_entries = [_ProjectEntry.FromGnTarget(t) for t in targets]

    logging.warning('Building .build_config files...')
    _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries],
              args.j)

    if args.all:
        # There are many unused libraries, so restrict to those that are actually
        # used by apks/binaries/tests or that are explicitly mentioned in --targets.
        main_entries = [
            e for e in main_entries
            if (e.GetType() in ('android_apk', 'java_binary',
                                'junit_binary') or e.GnTarget() in
                targets_from_args or e.GnTarget().endswith('_test_apk__apk'))
        ]

    if args.split_projects:
        main_entries = _FindAllProjectEntries(main_entries)

    logging.info('Generating for %d targets.', len(main_entries))

    entries = [e for e in _CombineTestEntries(main_entries) if e.IsValid()]
    logging.info('Creating %d projects for targets.', len(entries))

    logging.warning('Writing .gradle files...')
    source_properties = _ReadPropertiesFile(
        _RebasePath(
            os.path.join(build_vars['android_sdk_build_tools'],
                         'source.properties')))
    project_entries = []
    # When only one entry will be generated we want it to have a valid
    # build.gradle file with its own AndroidManifest.
    for entry in entries:
        data = _GenerateGradleFile(entry, generator, build_vars,
                                   source_properties, jinja_processor)
        if data and not args.all:
            project_entries.append((entry.ProjectName(), entry.GradleSubdir()))
            _WriteFile(
                os.path.join(generator.EntryOutputDir(entry),
                             _GRADLE_BUILD_FILE), data)
    if args.all:
        project_entries.append((_MODULE_ALL, _MODULE_ALL))
        _GenerateModuleAll(_gradle_output_dir, generator, build_vars,
                           source_properties, jinja_processor,
                           args.native_targets)

    _WriteFile(os.path.join(generator.project_dir, _GRADLE_BUILD_FILE),
               _GenerateRootGradle(jinja_processor, channel))

    _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'),
               _GenerateSettingsGradle(project_entries))

    if args.sdk != "AndroidStudioCurrent":
        if args.sdk_path:
            sdk_path = _RebasePath(args.sdk_path)
        elif args.sdk == "AndroidStudioDefault":
            sdk_path = os.path.expanduser('~/Android/Sdk')
            if not os.path.exists(sdk_path):
                # Help first-time users avoid Android Studio forcibly changing back to
                # the previous default due to not finding a valid sdk under this dir.
                shutil.copytree(_RebasePath(build_vars['android_sdk_root']),
                                sdk_path)
        else:
            sdk_path = _RebasePath(build_vars['android_sdk_root'])
        _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
                   _GenerateLocalProperties(sdk_path))

    if not args.fast:
        zip_tuples = []
        generated_inputs = set()
        for entry in entries:
            # Build all paths references by .gradle that exist within output_dir.
            generated_inputs.update(generator.GeneratedInputs(entry))
            zip_tuples.extend(generator.GeneratedZips(entry))
        if generated_inputs:
            logging.warning('Building generated source files...')
            targets = _RebasePath(generated_inputs, output_dir)
            _RunNinja(output_dir, targets, args.j)
        if zip_tuples:
            _ExtractZips(generator.project_dir, zip_tuples)

    logging.warning('Generated projects for Android Studio %s', channel)
    if not args.fast:
        logging.warning(
            'Run with --fast flag to skip generating files (faster, '
            'but less correct)')
    logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                    '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 23
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level')
    parser.add_argument('--target',
                        dest='targets',
                        action='append',
                        help='GN target to generate project for. '
                        'May be repeated.')
    parser.add_argument('--project-dir',
                        help='Root of the output project.',
                        default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle'))
    parser.add_argument('--all',
                        action='store_true',
                        help='Generate all java targets (slows down IDE)')
    parser.add_argument('--use-gradle-process-resources',
                        action='store_true',
                        help='Have gradle generate R.java rather than ninja')
    args = parser.parse_args()
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)
    constants.CheckOutputDirectory()
    output_dir = constants.GetOutDirectory()
    devil_chromium.Initialize(output_directory=output_dir)
    run_tests_helper.SetLogLevel(args.verbose_count)

    _gradle_output_dir = os.path.abspath(
        args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
    generator = _ProjectContextGenerator(_gradle_output_dir,
                                         args.use_gradle_process_resources)
    logging.warning('Creating project at: %s', generator.project_dir)

    if args.all:
        # Run GN gen if necessary (faster than running "gn gen" in the no-op case).
        _RunNinja(constants.GetOutDirectory(), ['build.ninja'])
        # Query ninja for all __build_config targets.
        targets = _QueryForAllGnTargets(output_dir)
    else:
        targets = args.targets or _DEFAULT_TARGETS
        targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets]
        # TODO(wnwen): Utilize Gradle's test constructs for our junit tests?
        targets = [
            re.sub(r'_junit_tests$', '_junit_tests__java_binary', t)
            for t in targets
        ]

    main_entries = [_ProjectEntry(t) for t in targets]

    logging.warning('Building .build_config files...')
    _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries])

    # There are many unused libraries, so restrict to those that are actually used
    # when using --all.
    if args.all:
        main_entries = [
            e for e in main_entries if e.GetType() == 'android_apk'
        ]

    all_entries = _FindAllProjectEntries(main_entries)
    logging.info('Found %d dependent build_config targets.', len(all_entries))
    entries = _CombineTestEntries(all_entries)
    logging.info('Creating %d projects for targets.', len(entries))

    logging.warning('Writing .gradle files...')
    jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
    build_vars = _ReadBuildVars(output_dir)
    project_entries = []
    srcjar_tuples = []
    generated_inputs = []
    for entry in entries:
        if entry.GetType() not in ('android_apk', 'java_library',
                                   'java_binary'):
            continue

        data = _GenerateGradleFile(entry, generator, build_vars,
                                   jinja_processor)
        if data:
            project_entries.append(entry)
            # Build all paths references by .gradle that exist within output_dir.
            generated_inputs.extend(generator.GeneratedInputs(entry))
            srcjar_tuples.extend((
                s,
                os.path.join(generator.EntryOutputDir(entry), _SRCJARS_SUBDIR))
                                 for s in generator.Srcjars(entry))
            _WriteFile(
                os.path.join(generator.EntryOutputDir(entry), 'build.gradle'),
                data)

    _WriteFile(os.path.join(generator.project_dir, 'build.gradle'),
               _GenerateRootGradle(jinja_processor))

    _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'),
               _GenerateSettingsGradle(project_entries))

    sdk_path = _RebasePath(build_vars['android_sdk_root'])
    _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
               _GenerateLocalProperties(sdk_path))

    if generated_inputs:
        logging.warning('Building generated source files...')
        targets = _RebasePath(generated_inputs, output_dir)
        _RunNinja(output_dir, targets)

    if srcjar_tuples:
        _ExtractSrcjars(generator.project_dir, srcjar_tuples)

    logging.warning('Project created! (%d subprojects)', len(project_entries))
    logging.warning('Generated projects work best with Android Studio 2.2')
    logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                    '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 24
0
def main():
  parser = argparse.ArgumentParser(
      description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
  parser.add_argument('--out-dir',
                      '--output-directory',
                      '-C',
                      metavar='OUT_DIR',
                      help='output directory of the build')
  parser.add_argument(
      '--run-all',
      action='store_true',
      help='Run all tests for the file or directory, instead of just one')
  parser.add_argument('--line',
                      type=int,
                      help='run only the test on this line number. c++ only.')
  parser.add_argument(
      '--gtest_filter', '-f', metavar='FILTER', help='test filter')
  parser.add_argument(
      '--dry-run',
      '-n',
      action='store_true',
      help='Print ninja and test run commands without executing them.')
  parser.add_argument(
      '--no-try-android-wrappers',
      action='store_true',
      help='Do not try to use Android test wrappers to run tests.')
  parser.add_argument('file',
                      metavar='FILE_NAME',
                      help='test suite file (eg. FooTest.java)')

  args, _extras = parser.parse_known_args()

  # Use CWD as out_dir when build.ninja exists.
  if not args.out_dir and os.path.exists('build.ninja'):
    args.out_dir = '.'

  if args.out_dir:
    constants.SetOutputDirectory(args.out_dir)
  constants.CheckOutputDirectory()
  out_dir: str = constants.GetOutDirectory()

  if not os.path.isdir(out_dir):
    parser.error(f'OUT_DIR "{out_dir}" does not exist.')
  target_cache = TargetCache(out_dir)
  filenames = FindMatchingTestFiles(args.file)

  targets, used_cache = FindTestTargets(target_cache, out_dir, filenames,
                                        args.run_all)

  gtest_filter = args.gtest_filter
  if not gtest_filter:
    gtest_filter = BuildTestFilter(filenames, args.line)

  if not gtest_filter:
    ExitWithMessage('Failed to derive a gtest filter')

  assert targets
  build_ok = BuildTestTargetsWithNinja(out_dir, targets, args.dry_run)

  # If we used the target cache, it's possible we chose the wrong target because
  # a gn file was changed. The build step above will check for gn modifications
  # and update build.ninja. Use this opportunity the verify the cache is still
  # valid.
  if used_cache and not target_cache.IsStillValid():
    target_cache = TargetCache(out_dir)
    new_targets, _ = FindTestTargets(target_cache, out_dir, filenames,
                                     args.run_all)
    if targets != new_targets:
      # Note that this can happen, for example, if you rename a test target.
      print('gn config was changed, trying to build again', file=sys.stderr)
      targets = new_targets
      build_ok = BuildTestTargetsWithNinja(out_dir, targets, args.dry_run)

  if not build_ok: sys.exit(1)

  RunTestTargets(out_dir, targets, gtest_filter, _extras, args.dry_run,
                 args.no_try_android_wrappers)
Ejemplo n.º 25
0
def main():
    arg_parser = argparse.ArgumentParser(
        description='Finds which build target contains a particular Java class.'
    )

    arg_parser.add_argument('-C',
                            '--output-directory',
                            help='Build output directory.')
    arg_parser.add_argument('--build',
                            action='store_true',
                            help='Build all .build_config files.')
    arg_parser.add_argument('classes',
                            nargs='+',
                            help='Java classes to search for')
    arg_parser.add_argument('-v',
                            '--verbose',
                            action='store_true',
                            help='Verbose logging.')

    arguments = arg_parser.parse_args()

    logging.basicConfig(
        level=logging.DEBUG if arguments.verbose else logging.WARNING,
        format='%(asctime)s.%(msecs)03d %(levelname).1s %(message)s',
        datefmt='%H:%M:%S')

    if arguments.output_directory:
        constants.SetOutputDirectory(arguments.output_directory)
    constants.CheckOutputDirectory()
    abs_out_dir: pathlib.Path = pathlib.Path(
        constants.GetOutDirectory()).resolve()

    index = ClassLookupIndex(abs_out_dir, arguments.build)
    matches = {c: index.match(c) for c in arguments.classes}

    if not arguments.build:
        # Try finding match without building because it is faster.
        for class_name, match_list in matches.items():
            if len(match_list) == 0:
                arguments.build = True
                break
        if arguments.build:
            index = ClassLookupIndex(abs_out_dir, True)
            matches = {c: index.match(c) for c in arguments.classes}

    if not arguments.build:
        print(
            'Showing potentially stale results. Run lookup.dep.py with --build '
            '(slower) to build any unbuilt GN targets and get full results.')
        print()

    for (class_name, class_entries) in matches.items():
        if not class_entries:
            print(f'Could not find build target for class "{class_name}"')
        elif len(class_entries) == 1:
            class_entry = class_entries[0]
            print(f'Class {class_entry.full_class_name} found:')
            print(f'    "{class_entry.target}"')
        else:
            print(f'Multiple targets with classes that match "{class_name}":')
            print()
            for class_entry in class_entries:
                print(f'    "{class_entry.target}"')
                print(f'        contains {class_entry.full_class_name}')
                print()
Ejemplo n.º 26
0
    def ParseAndroidEmulatorOptions(self):
        """Parses Android emulator args, and if necessary, starts an emulator.

    No-ops if --avd-config is not specified or if an emulator is already
    started.

    Performing this setup during argument parsing isn't ideal, but we need to
    set up the emulator sometime between arg parsing and browser finding.
    """
        if not self.avd_config:
            return
        if BrowserFinderOptions.emulator_environment:
            return
        build_android_dir = os.path.join(util.GetChromiumSrcDir(), 'build',
                                         'android')
        if not os.path.exists(build_android_dir):
            raise RuntimeError(
                '--avd-config specified, but Chromium //build/android directory not '
                'available')
        # Everything after this point only works if //build/android is actually
        # available, which we can't rely on, so use this to exit early in unittests.
        self._NoOpFunctionForTesting()
        sys.path.append(build_android_dir)
        # pylint: disable=import-error
        from pylib import constants as pylib_constants
        from pylib.local.emulator import local_emulator_environment
        # pylint: enable=import-error

        # We need to call this so that the Chromium output directory is set if it
        # is not explicitly specified via the command line argument/environment
        # variable.
        pylib_constants.CheckOutputDirectory()

        class AvdArgs(object):
            """A class to stand in for the AVD argparse.ArgumentParser object.

      Chromium's Android emulator code expects quite a few arguments from
      //build/android/test_runner.py, but the only one we actually care about
      here is avd_config. So, use a stand-in class with some sane defaults.
      """
            def __init__(self, avd_config):
                self.avd_config = avd_config
                self.emulator_count = 1
                self.emulator_window = False
                self.use_webview_provider = False
                self.replace_system_package = False
                self.denylist_file = None
                self.test_devices = []
                self.enable_concurrent_adb = False
                self.logcat_output_dir = None
                self.logcat_output_file = None
                self.num_retries = 1
                self.recover_devices = False
                self.skip_clear_data = True
                self.tool = None
                self.adb_path = None
                self.enable_device_cache = True

        avd_args = AvdArgs(self.avd_config)
        BrowserFinderOptions.emulator_environment =\
            local_emulator_environment.LocalEmulatorEnvironment(
                avd_args, None, None)
        BrowserFinderOptions.emulator_environment.SetUp()
        atexit.register(BrowserFinderOptions.emulator_environment.TearDown)