Android: Add features to dep_operations.py

Add --target-name-filter to allow dep removal only for the deps lists in
targets that match this filter. This allows removing deps only in a
specific target, making it faster to run on a dep that is in a large
build file (e.g. //chrome/android/BUILD.gn).

Add --all-java-deps and allow not passing any specific deps to the
remove operation. This will automatically use list_java_deps.py to fetch
the list of all java deps and attempt to remove all of them. This option
is best used with --file or --target-name-filter or both, otherwise it
may take O(days) or never complete. Speed-ups are in the works.

Batch dep removal so that instead of taking each dep and then iterating
through the lists of deps in a build file, iterate through the list of
deps first, and remove all matching deps one by one. This aligns better
with intuitive removal order (going down the build file line by line).

Improve detection of build changes that affect targets not built by the
current output directory. Before and after making potential removals for
a target, the remove operation runs `gn gen --ide=json` to check whether
project.json changed. If there were no changes to project.json, that
means this list of deps is not part of the current build and should not
have any deps removed. This ensures that only deps that are built
successfully in the current output directory are removed.

Other:
- Use 'autoninja' on PATH instead of in the repo.
- Rename --targets to --extra-build-targets to make its intent clearer.
- Ensure timestamps for build files are updated when they are restored
  since otherwise it can lead to build failures later.
- Improve logging to show the target name and variable name of the dep
  list being modified.

Bug: 1258168
Change-Id: I8fd8af4c10455deff795c82bac742427e6820a7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3655694
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1007524}
NOKEYCHECK=True
GitOrigin-RevId: 63ac504130a73d61faf29d77c1c880178eafc759
2 files changed