示例#1
0
def _GenerateRTxt(options, r_txt_path):
    """Generate R.txt file.

  Args:
    options: The command-line options tuple.
    r_txt_path: Locates where the R.txt file goes.
  """
    ignore_pattern = resource_utils.AAPT_IGNORE_PATTERN
    if options.strip_drawables:
        ignore_pattern += ':*drawable*'

    resources_parser.RTxtGenerator(options.resource_dirs,
                                   ignore_pattern).WriteRTxtFile(r_txt_path)
示例#2
0
def main(args):
    parser = argparse.ArgumentParser(
        description='Create an R.txt from resources.')
    parser.add_argument('--resources-zip-path',
                        required=True,
                        help='Path to input resources zip.')
    parser.add_argument('--rtxt-path',
                        required=True,
                        help='Path to output R.txt file.')
    options = parser.parse_args(build_utils.ExpandFileArgs(args))
    with build_utils.TempDir() as temp:
        dep_subdirs = resource_utils.ExtractDeps([options.resources_zip_path],
                                                 temp)
        resources_parser.RTxtGenerator(dep_subdirs).WriteRTxtFile(
            options.rtxt_path)
示例#3
0
def _CreateRJava(resource_zips, package_name, srcjar_out, rtxt_out):
    with resource_utils.BuildContext() as build:
        # TODO(mheikal): maybe we can rewrite resources_parser to just read out of a
        # zipfile without needing to extract first.
        dep_subdirs = resource_utils.ExtractDeps(resource_zips, build.deps_dir)
        resources_parser.RTxtGenerator(dep_subdirs).WriteRTxtFile(rtxt_out)

        rjava_build_options = resource_utils.RJavaBuildOptions()
        rjava_build_options.ExportAllResources()
        rjava_build_options.ExportAllStyleables()
        resource_utils.CreateRJavaFiles(
            build.srcjar_dir,
            package_name,
            rtxt_out,
            extra_res_packages=[],
            rjava_build_options=rjava_build_options,
            srcjar_out=srcjar_out)
        build_utils.ZipDir(srcjar_out, build.srcjar_dir)
示例#4
0
def _GenerateRTxt(options, dep_subdirs, gen_dir):
  """Generate R.txt file.

  Args:
    options: The command-line options tuple.
    dep_subdirs: List of directories containing extracted dependency resources.
    gen_dir: Locates where the aapt-generated files will go. In particular
      the output file is always generated as |{gen_dir}/R.txt|.
  """
  ignore_pattern = resource_utils.AAPT_IGNORE_PATTERN
  if options.strip_drawables:
    ignore_pattern += ':*drawable*'

  # Adding all dependencies as sources is necessary for @type/foo references
  # to symbols within dependencies to resolve. However, it has the side-effect
  # that all Java symbols from dependencies are copied into the new R.java.
  # E.g.: It enables an arguably incorrect usage of
  # "mypackage.R.id.lib_symbol" where "libpackage.R.id.lib_symbol" would be
  # more correct. This is just how Android works.
  resource_dirs = dep_subdirs + options.resource_dirs

  resources_parser.RTxtGenerator(resource_dirs, ignore_pattern).WriteRTxtFile(
      os.path.join(gen_dir, 'R.txt'))