Пример #1
0
def _ConfigOutDirAndToolsPrefix(out_dir):
  if out_dir:
    constants.SetOutputDirectory(out_dir)
  else:
    out_dir = constants.GetOutDirectory()
  if out_dir:
    build_vars = build_utils.ReadBuildVars(
        os.path.join(out_dir, "build_vars.txt"))
    tool_prefix = os.path.join(out_dir, build_vars['android_tool_prefix'])
  else:
    tool_prefix = ''
  return out_dir, tool_prefix
Пример #2
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 = build_utils.ReadBuildVars(
        os.path.join(out_dir, "build_vars.txt"))
    tool_prefix = os.path.join(out_dir, build_vars['android_tool_prefix'])
    return out_dir, tool_prefix
Пример #3
0
def _ConfigOutDirAndToolsPrefix(out_dir):
    if out_dir:
        constants.SetOutputDirectory(os.path.abspath(out_dir))
    else:
        try:
            out_dir = constants.GetOutDirectory()
            devil_chromium.Initialize()
        except EnvironmentError:
            pass
    if out_dir:
        build_vars = build_utils.ReadBuildVars()
        tool_prefix = os.path.join(out_dir, build_vars['android_tool_prefix'])
    else:
        tool_prefix = ''
    return out_dir, tool_prefix
Пример #4
0
def main(argv):
    argv = build_utils.ExpandFileArgs(argv)
    parser = argparse.ArgumentParser(description=__doc__)
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--build-vars',
                        help='Path to GN build vars file',
                        required=True)
    parser.add_argument('--root-manifest',
                        help='Root manifest which to merge into',
                        required=True)
    parser.add_argument('--output', help='Output manifest path', required=True)
    parser.add_argument('--extras',
                        help='GN list of additional manifest to merge')
    args = parser.parse_args(argv)

    classpath = _BuildManifestMergerClasspath(
        build_utils.ReadBuildVars(args.build_vars))
    cmd = [
        'java',
        '-cp',
        classpath,
        MANIFEST_MERGER_MAIN_CLASS,
        '--out',
        args.output,
    ]

    extras = build_utils.ParseGnList(args.extras)
    if extras:
        cmd += ['--libs', ':'.join(extras)]

    with _ProcessManifest(args.root_manifest) as tup:
        root_manifest, package = tup
        cmd += ['--main', root_manifest, '--property', 'PACKAGE=' + package]
        build_utils.CheckOutput(
            cmd,
            # https://issuetracker.google.com/issues/63514300: The merger doesn't set
            # a nonzero exit code for failures.
            fail_func=lambda returncode, stderr: returncode != 0 or build_utils
            .IsTimeStale(args.output, [root_manifest] + extras))
    if args.depfile:
        inputs = extras + classpath.split(':')
        build_utils.WriteDepfile(args.depfile,
                                 args.output,
                                 inputs=inputs,
                                 add_pydeps=False)
Пример #5
0
def main(argv):
    argv = build_utils.ExpandFileArgs(argv)
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--build-vars',
                        help='Path to GN build vars file',
                        required=True)
    parser.add_argument('--root-manifest',
                        help='Root manifest which to merge into',
                        required=True)
    parser.add_argument('--output', help='Output manifest path', required=True)
    parser.add_argument('--extras',
                        help='GN list of additional manifest to merge')
    args = parser.parse_args(argv)

    cmd = [
        'java',
        '-cp',
        _BuildManifestMergerClasspath(
            build_utils.ReadBuildVars(args.build_vars)),
        MANIFEST_MERGER_MAIN_CLASS,
        '--out',
        args.output,
    ]

    extras = build_utils.ParseGnList(args.extras)
    if extras:
        cmd += ['--libs', ':'.join(extras)]

    with _PatchedManifest(args.root_manifest) as root_manifest:
        cmd += ['--main', root_manifest]
        build_utils.CheckOutput(
            cmd,
            # https://issuetracker.google.com/issues/63514300: The merger doesn't set
            # a nonzero exit code for failures.
            fail_func=lambda returncode, stderr: returncode != 0 or build_utils
            .IsTimeStale(args.output, [root_manifest] + extras))
def main(argv):
    argv = build_utils.ExpandFileArgs(argv)
    parser = argparse.ArgumentParser(description=__doc__)
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--build-vars',
                        help='Path to GN build vars file',
                        required=True)
    parser.add_argument('--root-manifest',
                        help='Root manifest which to merge into',
                        required=True)
    parser.add_argument('--output', help='Output manifest path', required=True)
    parser.add_argument('--extras',
                        help='GN list of additional manifest to merge')
    parser.add_argument('--min-sdk-version',
                        required=True,
                        help='android:minSdkVersion for merging.')
    parser.add_argument('--target-sdk-version',
                        required=True,
                        help='android:targetSdkVersion for merging.')
    parser.add_argument('--max-sdk-version',
                        help='android:maxSdkVersion for merging.')
    parser.add_argument('--manifest-package',
                        help='Package name of the merged AndroidManifest.xml.')
    args = parser.parse_args(argv)

    classpath = _BuildManifestMergerClasspath(
        build_utils.ReadBuildVars(args.build_vars))

    with build_utils.AtomicOutput(args.output) as output:
        cmd = [
            build_utils.JAVA_PATH,
            '-cp',
            classpath,
            _MANIFEST_MERGER_MAIN_CLASS,
            '--out',
            output.name,
            '--property',
            'MIN_SDK_VERSION=' + args.min_sdk_version,
            '--property',
            'TARGET_SDK_VERSION=' + args.target_sdk_version,
        ]

        if args.max_sdk_version:
            cmd += [
                '--property',
                'MAX_SDK_VERSION=' + args.max_sdk_version,
            ]

        extras = build_utils.ParseGnList(args.extras)
        if extras:
            cmd += ['--libs', ':'.join(extras)]

        with _ProcessManifest(args.root_manifest, args.min_sdk_version,
                              args.target_sdk_version, args.max_sdk_version,
                              args.manifest_package) as tup:
            root_manifest, package = tup
            cmd += [
                '--main',
                root_manifest,
                '--property',
                'PACKAGE=' + package,
            ]
            build_utils.CheckOutput(
                cmd,
                # https://issuetracker.google.com/issues/63514300:
                # The merger doesn't set a nonzero exit code for failures.
                fail_func=lambda returncode, stderr: returncode != 0 or
                build_utils.IsTimeStale(output.name, [root_manifest] + extras))

        # Check for correct output.
        _, manifest, _ = manifest_utils.ParseManifest(output.name)
        manifest_utils.AssertUsesSdk(manifest, args.min_sdk_version,
                                     args.target_sdk_version)
        manifest_utils.AssertPackage(manifest, package)

    if args.depfile:
        inputs = extras + classpath.split(':')
        build_utils.WriteDepfile(args.depfile,
                                 args.output,
                                 inputs=inputs,
                                 add_pydeps=False)
Пример #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(
        '--dump-static-initializers',
        action='store_true',
        help='Run dump-static-initializers.py to get the list'
        'of static initializers (slow).')
    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 = build_utils.ReadBuildVars()
        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)
        _PrintStaticInitializersCountFromApk(args.apk,
                                             tools_prefix,
                                             args.dump_static_initializers,
                                             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)
Пример #8
0
def main(argv):
    argv = build_utils.ExpandFileArgs(argv)
    parser = argparse.ArgumentParser(description=__doc__)
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--build-vars',
                        help='Path to GN build vars file',
                        required=True)
    parser.add_argument('--root-manifest',
                        help='Root manifest which to merge into',
                        required=True)
    parser.add_argument('--expected-manifest',
                        help='Expected contents for the merged manifest.')
    parser.add_argument('--normalized-output',
                        help='Normalized merged manifest.')
    parser.add_argument(
        '--verify-expected-manifest',
        action='store_true',
        help='Fail if expected contents do not match merged manifest contents.'
    )
    parser.add_argument('--output', help='Output manifest path', required=True)
    parser.add_argument('--extras',
                        help='GN list of additional manifest to merge')
    args = parser.parse_args(argv)

    classpath = _BuildManifestMergerClasspath(
        build_utils.ReadBuildVars(args.build_vars))

    with build_utils.AtomicOutput(args.output) as output:
        cmd = [
            'java',
            '-cp',
            classpath,
            _MANIFEST_MERGER_MAIN_CLASS,
            '--out',
            output.name,
        ]

        extras = build_utils.ParseGnList(args.extras)
        if extras:
            cmd += ['--libs', ':'.join(extras)]

        with _ProcessManifest(args.root_manifest) as tup:
            root_manifest, package = tup
            cmd += [
                '--main', root_manifest, '--property', 'PACKAGE=' + package
            ]
            build_utils.CheckOutput(
                cmd,
                # https://issuetracker.google.com/issues/63514300:
                # The merger doesn't set a nonzero exit code for failures.
                fail_func=lambda returncode, stderr: returncode != 0 or
                build_utils.IsTimeStale(output.name, [root_manifest] + extras))

    if args.expected_manifest:
        with build_utils.AtomicOutput(
                args.normalized_output) as normalized_output:
            normalized_output.write(_NormalizeManifest(args.output))
        msg = diff_utils.DiffFileContents(args.expected_manifest,
                                          args.normalized_output)
        if msg:
            sys.stderr.write("""\
AndroidManifest.xml expectations file needs updating. For details see:
https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md
""")
            sys.stderr.write(msg)
            if args.verify_expected_manifest:
                sys.exit(1)

    if args.depfile:
        inputs = extras + classpath.split(':')
        build_utils.WriteDepfile(args.depfile,
                                 args.output,
                                 inputs=inputs,
                                 add_pydeps=False)
Пример #9
0
def main(argv):
    argv = build_utils.ExpandFileArgs(argv)
    parser = argparse.ArgumentParser(description=__doc__)
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--build-vars',
                        help='Path to GN build vars file',
                        required=True)
    parser.add_argument('--root-manifest',
                        help='Root manifest which to merge into',
                        required=True)
    parser.add_argument('--output', help='Output manifest path', required=True)
    parser.add_argument('--extras',
                        help='GN list of additional manifest to merge')
    parser.add_argument('--min-sdk-version',
                        required=True,
                        help='android:minSdkVersion for merging.')
    parser.add_argument('--target-sdk-version',
                        required=True,
                        help='android:targetSdkVersion for merging.')
    parser.add_argument(
        '--allow-uses-sdk',
        action='store_true',
        help='Use only for third party code. '
        'Don\'t fail if input manifest contains a <uses-sdk> element.')
    args = parser.parse_args(argv)

    classpath = _BuildManifestMergerClasspath(
        build_utils.ReadBuildVars(args.build_vars))

    with build_utils.AtomicOutput(args.output) as output:
        cmd = [
            'java',
            '-cp',
            classpath,
            _MANIFEST_MERGER_MAIN_CLASS,
            '--out',
            output.name,
        ]

        extras = build_utils.ParseGnList(args.extras)
        if extras:
            cmd += ['--libs', ':'.join(extras)]

        with _ProcessManifest(args.root_manifest, args.allow_uses_sdk) as tup:
            root_manifest, package = tup
            cmd += [
                '--main',
                root_manifest,
                '--property',
                'PACKAGE=' + package,
                '--property',
                'MIN_SDK_VERSION=' + args.min_sdk_version,
                '--property',
                'TARGET_SDK_VERSION=' + args.target_sdk_version,
            ]
            build_utils.CheckOutput(
                cmd,
                # https://issuetracker.google.com/issues/63514300:
                # The merger doesn't set a nonzero exit code for failures.
                fail_func=lambda returncode, stderr: returncode != 0 or
                build_utils.IsTimeStale(output.name, [root_manifest] + extras))

        # Subsequent build system steps expect uses-sdk tag does not exist.
        # Therefore, check it has the expected attribute values and remove it.
        doc, manifest, _ = manifest_utils.ParseManifest(output.name)
        uses_sdk = manifest.find('./uses-sdk')
        assert uses_sdk.get(
            '{%s}minSdkVersion' %
            manifest_utils.ANDROID_NAMESPACE) == args.min_sdk_version
        assert uses_sdk.get(
            '{%s}targetSdkVersion' %
            manifest_utils.ANDROID_NAMESPACE) == args.target_sdk_version
        manifest.remove(uses_sdk)
        manifest_utils.SaveManifest(doc, output.name)

    if args.depfile:
        inputs = extras + classpath.split(':')
        build_utils.WriteDepfile(args.depfile,
                                 args.output,
                                 inputs=inputs,
                                 add_pydeps=False)