Ejemplo n.º 1
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.º 2
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Enable verbose logging.')
    parser.add_argument('-a',
                        '--auxclasspath',
                        default=None,
                        dest='auxclasspath',
                        help='Set aux classpath for analysis.')
    parser.add_argument(
        '--auxclasspath-gyp',
        dest='auxclasspath_gyp',
        help='A gyp list containing the aux classpath for analysis')
    parser.add_argument('-o',
                        '--only-analyze',
                        default=None,
                        dest='only_analyze',
                        help='Only analyze the given classes and packages.')
    parser.add_argument('-e',
                        '--exclude',
                        default=None,
                        dest='exclude',
                        help='Exclude bugs matching given filter.')
    parser.add_argument('-l',
                        '--release-build',
                        action='store_true',
                        dest='release_build',
                        help='Analyze release build instead of debug.')
    parser.add_argument('-f',
                        '--findbug-args',
                        default=None,
                        dest='findbug_args',
                        help='Additional findbug arguments.')
    parser.add_argument('-b',
                        '--base-dir',
                        default=_DEFAULT_BASE_DIR,
                        dest='base_dir',
                        help='Base directory for configuration file.')
    parser.add_argument('--output-file',
                        dest='output_file',
                        help='Path to save the output to.')
    parser.add_argument('--stamp', help='Path to touch on success.')
    parser.add_argument(
        '--depfile',
        help='Path to the depfile. This must be specified as the '
        "action's first output.")

    parser.add_argument('jar_paths',
                        metavar='JAR_PATH',
                        nargs='+',
                        help='JAR file to analyze')

    args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))

    run_tests_helper.SetLogLevel(args.verbose)

    if args.auxclasspath:
        args.auxclasspath = args.auxclasspath.split(':')
    elif args.auxclasspath_gyp:
        args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp)

    if args.base_dir:
        if not args.exclude:
            args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')

    findbugs_command, findbugs_warnings = findbugs.Run(
        args.exclude, args.only_analyze, args.auxclasspath, args.output_file,
        args.findbug_args, args.jar_paths)

    if findbugs_warnings:
        print
        print '*' * 80
        print 'FindBugs run via:'
        print findbugs_command
        print
        print 'FindBugs reported the following issues:'
        for warning in sorted(findbugs_warnings):
            print str(warning)
        print '*' * 80
        print
    else:
        if args.depfile:
            build_utils.WriteDepfile(
                args.depfile,
                build_utils.GetPythonDependencies() + args.auxclasspath +
                args.jar_paths)
        if args.stamp:
            build_utils.Touch(args.stamp)

    return len(findbugs_warnings)
Ejemplo n.º 3
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]

    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/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.º 4
0
def main():
    # Recommended options on perf bots:
    # --disable-network
    #     TODO(tonyg): We eventually want network on. However, currently radios
    #     can cause perfbots to drain faster than they charge.
    # --min-battery-level 95
    #     Some perf bots run benchmarks with USB charging disabled which leads
    #     to gradual draining of the battery. We must wait for a full charge
    #     before starting a run in order to keep the devices online.

    parser = argparse.ArgumentParser(
        description='Provision Android devices with settings required for bots.'
    )
    parser.add_argument(
        '-d',
        '--device',
        metavar='SERIAL',
        help='the serial number of the device to be provisioned'
        ' (the default is to provision all devices attached)')
    parser.add_argument('--adb-path',
                        help='Absolute path to the adb binary to use.')
    parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_argument('--phase',
                        action='append',
                        choices=_PHASES.ALL,
                        dest='phases',
                        help='Phases of provisioning to run. '
                        '(If omitted, all phases will be run.)')
    parser.add_argument('--skip-wipe',
                        action='store_true',
                        default=False,
                        help="don't wipe device data during provisioning")
    parser.add_argument('--reboot-timeout',
                        metavar='SECS',
                        type=int,
                        help='when wiping the device, max number of seconds to'
                        ' wait after each reboot '
                        '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT)
    parser.add_argument(
        '--min-battery-level',
        type=int,
        metavar='NUM',
        help='wait for the device to reach this minimum battery'
        ' level before trying to continue')
    parser.add_argument('--disable-location',
                        action='store_true',
                        help='disable Google location services on devices')
    parser.add_argument('--disable-mock-location',
                        action='store_true',
                        default=False,
                        help='Set ALLOW_MOCK_LOCATION to false')
    parser.add_argument('--disable-network',
                        action='store_true',
                        help='disable network access on devices')
    parser.add_argument('--disable-java-debug',
                        action='store_false',
                        dest='enable_java_debug',
                        default=True,
                        help='disable Java property asserts and JNI checking')
    parser.add_argument('--disable-system-chrome',
                        action='store_true',
                        help='Disable the system chrome from devices.')
    parser.add_argument('--remove-system-webview',
                        action='store_true',
                        help='Remove the system webview from devices.')
    parser.add_argument('-t',
                        '--target',
                        default='Debug',
                        help='the build target (default: %(default)s)')
    parser.add_argument('-r',
                        '--auto-reconnect',
                        action='store_true',
                        help='push binary which will reboot the device on adb'
                        ' disconnections')
    parser.add_argument('--adb-key-files',
                        type=str,
                        nargs='+',
                        help='list of adb keys to push to device')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        help='Log more information.')
    parser.add_argument(
        '--max-battery-temp',
        type=int,
        metavar='NUM',
        help='Wait for the battery to have this temp or lower.')
    parser.add_argument('--output-device-blacklist',
                        help='Json file to output the device blacklist.')
    parser.add_argument(
        '--chrome-specific-wipe',
        action='store_true',
        help='only wipe chrome specific data during provisioning')
    parser.add_argument('--emulators',
                        action='store_true',
                        help='provision only emulators and ignore usb devices')
    args = parser.parse_args()
    constants.SetBuildType(args.target)

    run_tests_helper.SetLogLevel(args.verbose)

    devil_custom_deps = None
    if args.adb_path:
        devil_custom_deps = {
            'adb': {
                devil_env.GetPlatform(): [args.adb_path],
            },
        }

    devil_chromium.Initialize(custom_deps=devil_custom_deps)

    return ProvisionDevices(args)
Ejemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('apk_path', help='The path to the APK to install.')
    parser.add_argument('--split',
                        action='append',
                        dest='splits',
                        help='A glob matching the apk splits. '
                        'Can be specified multiple times.')
    parser.add_argument('--native_lib',
                        dest='native_libs',
                        help='Path to native library (repeatable)',
                        action='append',
                        default=[])
    parser.add_argument('--dex-file',
                        dest='dex_files',
                        help='Path to dex files (repeatable)',
                        action='append',
                        default=[])
    parser.add_argument('-d',
                        '--device',
                        dest='device',
                        help='Target device for apk to install on.')
    parser.add_argument('--uninstall',
                        action='store_true',
                        default=False,
                        help='Remove the app and all side-loaded files.')
    parser.add_argument('--output-directory',
                        help='Path to the root build directory.')
    parser.add_argument('--no-threading',
                        action='store_false',
                        default=True,
                        dest='threading',
                        help='Do not install and push concurrently')
    parser.add_argument(
        '--no-cache',
        action='store_false',
        default=True,
        dest='cache',
        help='Do not use cached information about what files are '
        'currently on the target device.')
    parser.add_argument('--show-proguard-warning',
                        action='store_true',
                        default=False,
                        help='Print a warning about proguard being disabled')
    parser.add_argument('--dont-even-try',
                        help='Prints this message and exits.')
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose_count',
                        default=0,
                        action='count',
                        help='Verbose level (multiple times for more)')
    parser.add_argument('--disable-downgrade',
                        action='store_false',
                        default=True,
                        dest='allow_downgrade',
                        help='Disable install of apk with lower version number'
                        'than the version already on the device.')

    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose_count)
    constants.SetBuildType('Debug')
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)

    devil_chromium.Initialize(output_directory=constants.GetOutDirectory())

    if args.dont_even_try:
        logging.fatal(args.dont_even_try)
        return 1

    # Retries are annoying when commands fail for legitimate reasons. Might want
    # to enable them if this is ever used on bots though.
    device = device_utils.DeviceUtils.HealthyDevices(
        device_arg=args.device,
        default_retries=0,
        enable_device_files_cache=True)[0]

    apk = apk_helper.ToHelper(args.apk_path)
    if args.uninstall:
        Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache)
    else:
        Install(device,
                apk,
                split_globs=args.splits,
                native_libs=args.native_libs,
                dex_files=args.dex_files,
                enable_device_cache=args.cache,
                use_concurrency=args.threading,
                show_proguard_warning=args.show_proguard_warning,
                allow_downgrade=args.allow_downgrade)
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')
    parser.add_argument('--canary',
                        action='store_true',
                        help='Generate a project that is compatible with '
                        'Android Studio 3.0 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))
    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,
                                         args.canary)
    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, args.canary))

    _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 %s',
        'Android Studio 3.0 Beta 2' if args.canary else 'Android Studio 2.3')
    logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                    '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 7
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('--full',
                      action='store_true',
                      help='Generate R.java and other ninja-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='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))
  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'])
    else:
      # Faster than running "gn gen" in the no-op case.
      _RunNinja(constants.GetOutDirectory(), ['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]

  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')
    else:
      sdk_path = _RebasePath(build_vars['android_sdk_root'])
    _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
               _GenerateLocalProperties(sdk_path))

  if args.full:
    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.full:
    logging.warning('Run with --full flag to update generated files (slow)')
  logging.warning('For more tips: https://chromium.googlesource.com/chromium'
                  '/src.git/+/master/docs/android_studio.md')
Ejemplo n.º 8
0
def main(raw_args):
    # Recommended options on perf bots:
    # --disable-network
    #     TODO(tonyg): We eventually want network on. However, currently radios
    #     can cause perfbots to drain faster than they charge.
    # --min-battery-level 95
    #     Some perf bots run benchmarks with USB charging disabled which leads
    #     to gradual draining of the battery. We must wait for a full charge
    #     before starting a run in order to keep the devices online.

    parser = argparse.ArgumentParser(
        description='Provision Android devices with settings required for bots.'
    )
    script_common.AddDeviceArguments(parser)
    script_common.AddEnvironmentArguments(parser)
    parser.add_argument('--adb-key-files',
                        type=str,
                        nargs='+',
                        help='list of adb keys to push to device')
    parser.add_argument('--disable-location',
                        action='store_true',
                        help='disable Google location services on devices')
    parser.add_argument('--disable-mock-location',
                        action='store_true',
                        default=False,
                        help='Set ALLOW_MOCK_LOCATION to false')
    parser.add_argument('--disable-network',
                        action='store_true',
                        help='disable network access on devices')
    parser.add_argument('--disable-java-debug',
                        action='store_false',
                        dest='enable_java_debug',
                        default=True,
                        help='disable Java property asserts and JNI checking')
    parser.add_argument(
        '--disable-system-chrome',
        action='store_true',
        help='DEPRECATED: use --remove-system-packages com.android.google '
        'Disable the system chrome from devices.')
    parser.add_argument('--emulators',
                        action='store_true',
                        help='provision only emulators and ignore usb devices '
                        '(this will not wipe emulators)')
    parser.add_argument(
        '--max-battery-temp',
        type=int,
        metavar='NUM',
        help='Wait for the battery to have this temp or lower.')
    parser.add_argument(
        '--min-battery-level',
        type=int,
        metavar='NUM',
        help='wait for the device to reach this minimum battery'
        ' level before trying to continue')
    parser.add_argument('--output-device-blacklist',
                        help='Json file to output the device blacklist.')
    parser.add_argument('--reboot-timeout',
                        metavar='SECS',
                        type=int,
                        help='when wiping the device, max number of seconds to'
                        ' wait after each reboot '
                        '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT)
    parser.add_argument(
        '--remove-system-apps',
        nargs='*',
        dest='system_app_remove_list',
        help='DEPRECATED: use --remove-system-packages instead. '
        'The names of system apps to remove. ')
    parser.add_argument('--remove-system-packages',
                        nargs='*',
                        dest='system_package_remove_list',
                        help='The names of system packages to remove.')
    parser.add_argument('--remove-system-webview',
                        action='store_true',
                        help='DEPRECATED: use --remove-system-packages '
                        'com.google.android.webview com.android.webview '
                        'Remove the system webview from devices.')
    parser.add_argument('--skip-wipe',
                        action='store_true',
                        default=False,
                        help='do not wipe device data during provisioning')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        help='Log more information.')

    # No-op arguments for compatibility with build/android/provision_devices.py.
    # TODO(jbudorick): Remove these once all callers have stopped using them.
    parser.add_argument('--chrome-specific-wipe',
                        action='store_true',
                        help=argparse.SUPPRESS)
    parser.add_argument('--phase', action='append', help=argparse.SUPPRESS)
    parser.add_argument('-r',
                        '--auto-reconnect',
                        action='store_true',
                        help=argparse.SUPPRESS)
    parser.add_argument('-t', '--target', help=argparse.SUPPRESS)

    args = parser.parse_args(raw_args)

    run_tests_helper.SetLogLevel(args.verbose)
    script_common.InitializeEnvironment(args)

    try:
        return ProvisionDevices(
            args.devices,
            args.blacklist_file,
            adb_key_files=args.adb_key_files,
            disable_location=args.disable_location,
            disable_mock_location=args.disable_mock_location,
            disable_network=args.disable_network,
            disable_system_chrome=args.disable_system_chrome,
            emulators=args.emulators,
            enable_java_debug=args.enable_java_debug,
            max_battery_temp=args.max_battery_temp,
            min_battery_level=args.min_battery_level,
            output_device_blacklist=args.output_device_blacklist,
            reboot_timeout=args.reboot_timeout,
            remove_system_webview=args.remove_system_webview,
            system_app_remove_list=args.system_app_remove_list,
            system_package_remove_list=args.system_package_remove_list,
            wipe=not args.skip_wipe and not args.emulators)
    except (device_errors.DeviceUnreachableError,
            device_errors.NoDevicesError):
        logging.exception('Unable to provision local devices.')
        return exit_codes.INFRA
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--out-dir',
                        help='Directory where the device path is stored',
                        default=os.path.join(constants.DIR_SOURCE_ROOT, 'out'))
    parser.add_argument('--restart-usb',
                        action='store_true',
                        help='DEPRECATED. '
                        'This script now always tries to reset USB.')
    parser.add_argument('--json-output',
                        help='Output JSON information into a specified file.')
    parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_argument('--known-devices-file',
                        action='append',
                        default=[],
                        dest='known_devices_files',
                        help='Path to known device lists.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        help='Log more information.')

    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose)

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

    last_devices_path = os.path.join(args.out_dir,
                                     device_list.LAST_DEVICES_FILENAME)
    args.known_devices_files.append(last_devices_path)

    expected_devices = set()
    try:
        for path in args.known_devices_files:
            if os.path.exists(path):
                expected_devices.update(
                    device_list.GetPersistentDeviceList(path))
    except IOError:
        logging.warning('Problem reading %s, skipping.', path)

    logging.info('Expected devices:')
    for device in expected_devices:
        logging.info('  %s', device)

    usb_devices = set(lsusb.get_android_devices())
    devices = [
        device_utils.DeviceUtils(s)
        for s in expected_devices.union(usb_devices)
    ]

    RecoverDevices(devices, blacklist)
    statuses = DeviceStatus(devices, blacklist)

    # Log the state of all devices.
    for status in statuses:
        logging.info(status['serial'])
        adb_status = status.get('adb_status')
        blacklisted = status.get('blacklisted')
        logging.info('  USB status: %s',
                     'online' if status.get('usb_status') else 'offline')
        logging.info('  ADB status: %s', adb_status)
        logging.info('  Blacklisted: %s', str(blacklisted))
        if adb_status == 'device' and not blacklisted:
            logging.info('  Device type: %s', status.get('ro.build.product'))
            logging.info('  OS build: %s', status.get('ro.build.id'))
            logging.info('  OS build fingerprint: %s',
                         status.get('ro.build.fingerprint'))
            logging.info('  Battery state:')
            for k, v in status.get('battery', {}).iteritems():
                logging.info('    %s: %s', k, v)
            logging.info('  IMEI slice: %s', status.get('imei_slice'))
            logging.info('  WiFi IP: %s', status.get('wifi_ip'))

    # Update the last devices file(s).
    for path in args.known_devices_files:
        device_list.WritePersistentDeviceList(
            path, [status['serial'] for status in statuses])

    # Write device info to file for buildbot info display.
    if os.path.exists('/home/chrome-bot'):
        with open('/home/chrome-bot/.adb_device_info', 'w') as f:
            for status in statuses:
                try:
                    if status['adb_status'] == 'device':
                        f.write(
                            '{serial} {adb_status} {build_product} {build_id} '
                            '{temperature:.1f}C {level}%\n'.format(
                                serial=status['serial'],
                                adb_status=status['adb_status'],
                                build_product=status['type'],
                                build_id=status['build'],
                                temperature=float(
                                    status['battery']['temperature']) / 10,
                                level=status['battery']['level']))
                    else:
                        f.write('{serial} {adb_status}'.format(
                            serial=status['serial'],
                            adb_status=status['adb_status']))
                except Exception:  # pylint: disable=broad-except
                    pass

    # Dump the device statuses to JSON.
    if args.json_output:
        with open(args.json_output, 'wb') as f:
            f.write(json.dumps(statuses, indent=4))

    live_devices = [
        status['serial'] for status in statuses
        if (status['adb_status'] == 'device'
            and not _IsBlacklisted(status['serial'], blacklist))
    ]

    # If all devices failed, or if there are no devices, it's an infra error.
    return 0 if live_devices else constants.INFRA_EXIT_CODE
Ejemplo n.º 10
0
def ProcessCommonOptions(args):
    """Processes and handles all common options."""
    run_tests_helper.SetLogLevel(args.verbose_count)
    constants.SetBuildType(args.build_type)
    if args.output_directory:
        constants.SetOutputDirectory(args.output_directory)