コード例 #1
0
def _MaybeCreateStableIdsFile(options):
    """Transforms a file generated by --emit-ids from another package.

  --stable-ids is generally meant to be used by different versions of the same
  package. To make it work for other packages, we need to transform the package
  name references to match the package that resources are being generated for.

  Note: This will fail if the package ID of the resources in
  |options.use_resource_ids_path| does not match the package ID of the
  resources being linked.

  Args:
    options: The command-line options
  Yields:
    Path to the transformed resource IDs file (lines formatted like
      package:type/name = 0xPPTTEEEE) or None
  """
    if options.use_resource_ids_path:
        package_name = options.package_name
        if not package_name:
            package_name = resource_utils.ExtractPackageFromManifest(
                options.android_manifest)
        with open(options.use_resource_ids_path) as stable_ids_file:
            with tempfile.NamedTemporaryFile() as output_ids_file:
                output_stable_ids = re.sub(r'^.*?:',
                                           package_name + ':',
                                           stable_ids_file.read(),
                                           flags=re.MULTILINE)
                output_ids_file.write(output_stable_ids)
                output_ids_file.flush()
                yield output_ids_file
    else:
        yield None
コード例 #2
0
def _OnStaleMd5(options):
    with resource_utils.BuildContext() as build:
        if options.r_text_in:
            r_txt_path = options.r_text_in
        else:
            # Extract dependencies to resolve @foo/type references into
            # dependent packages.
            dep_subdirs = resource_utils.ExtractDeps(
                options.dependencies_res_zips, build.deps_dir)

            _GenerateRTxt(options, dep_subdirs, build.gen_dir)
            r_txt_path = build.r_txt_path

            # 'aapt' doesn't generate any R.txt file if res/ was empty.
            if not os.path.exists(r_txt_path):
                build_utils.Touch(r_txt_path)

        if options.r_text_out:
            shutil.copyfile(r_txt_path, options.r_text_out)

        if options.srcjar_out:
            package = options.custom_package
            if not package and options.android_manifest:
                package = resource_utils.ExtractPackageFromManifest(
                    options.android_manifest)

            # Don't create a .java file for the current resource target when no
            # package name was provided (either by manifest or build rules).
            if package:
                # All resource IDs should be non-final here, but the
                # onResourcesLoaded() method should only be generated if
                # --shared-resources is used.
                rjava_build_options = resource_utils.RJavaBuildOptions()
                rjava_build_options.ExportAllResources()
                rjava_build_options.ExportAllStyleables()
                if options.shared_resources:
                    rjava_build_options.GenerateOnResourcesLoaded()

                # Not passing in custom_root_package_name or parent to keep
                # file names unique.
                resource_utils.CreateRJavaFiles(build.srcjar_dir, package,
                                                r_txt_path,
                                                options.extra_res_packages,
                                                options.extra_r_text_files,
                                                rjava_build_options,
                                                options.srcjar_out)

            build_utils.ZipDir(options.srcjar_out, build.srcjar_dir)

        if options.resource_zip_out:
            _GenerateResourcesZip(options.resource_zip_out,
                                  options.resource_dirs,
                                  options.strip_drawables)
コード例 #3
0
def _OnStaleMd5(options):
    with resource_utils.BuildContext() as build:
        dep_subdirs = resource_utils.ExtractDeps(options.dependencies_res_zips,
                                                 build.deps_dir)

        _PackageApk(options, dep_subdirs, build.temp_dir, build.gen_dir,
                    build.r_txt_path)

        r_txt_path = _WriteFinalRTxtFile(options, build.r_txt_path)

        package = resource_utils.ExtractPackageFromManifest(
            options.android_manifest)

        # If --shared-resources-whitelist is used, the all resources listed in
        # the corresponding R.txt file will be non-final, and an onResourcesLoaded()
        # will be generated to adjust them at runtime.
        #
        # Otherwise, if --shared-resources is used, the all resources will be
        # non-final, and an onResourcesLoaded() method will be generated too.
        #
        # Otherwise, all resources will be final, and no method will be generated.
        #
        rjava_build_options = resource_utils.RJavaBuildOptions()
        if options.shared_resources_whitelist:
            rjava_build_options.ExportSomeResources(
                options.shared_resources_whitelist)
            rjava_build_options.GenerateOnResourcesLoaded()
        elif options.shared_resources or options.app_as_shared_lib:
            rjava_build_options.ExportAllResources()
            rjava_build_options.GenerateOnResourcesLoaded()

        resource_utils.CreateRJavaFiles(build.srcjar_dir, package, r_txt_path,
                                        options.extra_res_packages,
                                        options.extra_r_text_files,
                                        rjava_build_options)

        if options.srcjar_out:
            build_utils.ZipDir(options.srcjar_out, build.srcjar_dir)

        if options.check_resources_pkg_id is not None:
            expected_id = options.check_resources_pkg_id
            package_id = _ExtractPackageIdFromApk(options.apk_path,
                                                  options.aapt_path)
            if package_id != expected_id:
                raise Exception('Invalid package ID 0x%x (expected 0x%x)' %
                                (package_id, expected_id))