tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

create_r_java.py (2551B)


      1 #!/usr/bin/env python3
      2 # Copyright 2020 The Chromium Authors
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 """Writes a dummy R.java file from a list of R.txt files."""
      6 
      7 import argparse
      8 import sys
      9 
     10 from util import build_utils
     11 from util import resource_utils
     12 import action_helpers  # build_utils adds //build to sys.path.
     13 import zip_helpers
     14 
     15 
     16 def _ConcatRTxts(rtxt_in_paths, combined_out_path):
     17  all_lines = set()
     18  for rtxt_in_path in rtxt_in_paths:
     19    with open(rtxt_in_path) as rtxt_in:
     20      all_lines.update(rtxt_in.read().splitlines())
     21  with open(combined_out_path, 'w') as combined_out:
     22    combined_out.write('\n'.join(sorted(all_lines)))
     23 
     24 
     25 def _CreateRJava(rtxts, package_name, srcjar_out):
     26  with resource_utils.BuildContext() as build:
     27    _ConcatRTxts(rtxts, build.r_txt_path)
     28    rjava_build_options = resource_utils.RJavaBuildOptions()
     29    rjava_build_options.ExportAllResources()
     30    rjava_build_options.ExportAllStyleables()
     31    rjava_build_options.GenerateOnResourcesLoaded(fake=True)
     32    resource_utils.CreateRJavaFiles(build.srcjar_dir,
     33                                    package_name,
     34                                    build.r_txt_path,
     35                                    extra_res_packages=[],
     36                                    rjava_build_options=rjava_build_options,
     37                                    srcjar_out=srcjar_out,
     38                                    ignore_mismatched_values=True)
     39    with action_helpers.atomic_output(srcjar_out) as f:
     40      zip_helpers.zip_directory(f, build.srcjar_dir)
     41 
     42 
     43 def main(args):
     44  parser = argparse.ArgumentParser(description='Create an R.java srcjar.')
     45  action_helpers.add_depfile_arg(parser)
     46  parser.add_argument('--srcjar-out',
     47                      required=True,
     48                      help='Path to output srcjar.')
     49  parser.add_argument('--deps-rtxts',
     50                      required=True,
     51                      help='List of rtxts of resource dependencies.')
     52  parser.add_argument('--r-package',
     53                      required=True,
     54                      help='R.java package to use.')
     55  options = parser.parse_args(build_utils.ExpandFileArgs(args))
     56  options.deps_rtxts = action_helpers.parse_gn_list(options.deps_rtxts)
     57 
     58  _CreateRJava(options.deps_rtxts, options.r_package, options.srcjar_out)
     59  action_helpers.write_depfile(options.depfile,
     60                               options.srcjar_out,
     61                               inputs=options.deps_rtxts)
     62 
     63 
     64 if __name__ == "__main__":
     65  sys.exit(main(sys.argv[1:]))