android build: Split process_resources GN rule and script.

This is a reland of [1] which itself was a reland of [2].
Note that [1] was reverted in [3] due to broken package id
generation in monochrome_public_apk and its cousins.

The process_resources() GN template and the associated
process_resources.py script are huge and difficult to understand
because they can be used to perform two slightly related
different things.

In preparation for a future CL that will introduce a new resource
compilation mode, this CL tries to clarify the situation by splitting
them into two sets of GN template + script:

   - prepare_resources() + prepare_resources.py, which are
     used to create .resources.zip archives of raw/uncompiled
     resources for resource related targets, as well as
     generating a corresponding R.txt and .srcjar(R.java)
     file.

     This corresponds to what process_resources() did when
     it was called from android_resources() and junit_binary().

     Note that this always generates non-final resource IDs,
     as well as a dummy onResourcesLoaded() method, necessary
     to compile, but not link, the ResourceRewriter class
     used to implement the system webview feature.

   - compile_resources() + compile_resources.py, which are used
     to compile all resource dependencies of a given binary
     (e.g. android_apk) into an intermediate .ap_ file.

     This corresponds to the behaviour of process_resources()
     when called from android_apk(). This generates final
     resource IDs by default, unless |shared_resources| or
     |shared_resources_whitelist| is used.

     Also, as a simplification, |shared_resources_whitelist|
     now implies |shared_resources|, except that it restrict
     the list of non-final resource IDs.

- Removed generate_constant_ids, since compile_resources()
  will always generate constant ids unless shared resources
  are being used. And prepare_resources() always generates
  non-constant IDs, as before the CL.

+ Add documentation for the prepare_resources() and
  compile_resources() internal GN rules, to make them
  a little less intimidating.

+ Add documentation for shared_resources, app_as_shared_lib,
  shared_resources_whitelist_target for android_apk()
  template.

+ Add sanity checking for the resources table package
  ID of each generated APK. This is done by adding
  (and using) --check-resources-pkg-id=ID option to
  compile_resources.py.

+ Improve --help output for prepare_resources.py and
  compile_resources.py by using option groups for inputs
  and outputs.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/968870
[2] https://chromium-review.googlesource.com/c/chromium/src/+/957095
[3] https://chromium-review.googlesource.com/c/chromium/src/+/972632

R=agrieve@chromium.org,yfriedman@chromium.org,estevenson@chromium.org,trevordixon@chromium.org

Bug: 820459
Change-Id: I34a5018f54c06c110bbe996da88cddb9e3b9a21b
Reviewed-on: https://chromium-review.googlesource.com/973963
Commit-Queue: David Turner <digit@chromium.org>
Reviewed-by: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545392}

CrOS-Libchrome-Original-Commit: 81bb55bc0b81aa61561e93c928eeb2de69980e68
1 file changed
tree: 2db3f8353f994e1ef5517a78e45853f1d7cb15de
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/