[build][bazel] Improve @legacy_ninja_build_outputs generation.

This CL changes how the repository that exposes Ninja outputs
as Bazel input files is generated:

- The repository is now populated by a repository rule
  (see //build/bazel/repository_rules.bzl) which reads
  the same inputs manifest file generated at `gn gen`
  time with metadata collection.

  This allows populating the repository *before* building
  anything with Ninja (except the minimal setup performed
  by 'fx build bazel_workspace'), which in turns allows
  performing Bazel queries before building anything with
  Ninja!

  This also allows breaking the 'testonly' blocking boundary!
  I.e. in the previous implementation, having a single testonly
  bazel_input_xxx() target forced the bazel workspace-generating
  action to be testonly, preventing any use of a non-testonly
  bazel_build_action() targets, which was far too limiting.

  With this new implementation, only
  //build/bazel:legacy_ninja_build_outputs needs to be
  testonly, and nothing actually depends on it in the GN
  graph (though it must be reachable from //BUILD.gn in order
  to generate its metadata file).

+ Move tests from //build/bazel/examples to //build/bazel/tests/

+ generate-workspace.py: Fix the create_dir() function since
  shutil.rmtree() does not work well with the chains of readonly
  symlinks and directories found in the output base
  (resulting in strange NotADirectory errors).

+ test-all.py: Add new test to verify that Bazel queries before
  Ninja builds actually work. Improve error output when a command
  fails. Add --fuchsia-build-dir option, and auto-detect it
  otherwise (will be used in future CL).

Change-Id: Idf88733d7dd534da2a43410c73ca85682ebf12d1
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/718889
Fuchsia-Auto-Submit: David Turner <digit@google.com>
Reviewed-by: Jay Zhuang <jayzhuang@google.com>
Commit-Queue: David Turner <digit@google.com>
27 files changed
tree: 90949a4dcc06a82a192eff693b305da4eb76ee4d
  1. boards/
  2. build/
  3. bundles/
  4. docs/
  5. examples/
  6. products/
  7. scripts/
  8. sdk/
  9. src/
  10. third_party/
  11. tools/
  12. zircon/
  13. .clang-format
  14. .clang-tidy
  15. .editorconfig
  16. .git-blame-ignore-revs
  17. .gitattributes
  18. .gitignore
  19. .gn
  20. .style.yapf
  21. analysis_options.yaml
  22. AUTHORS
  23. BUILD.gn
  24. CODE_OF_CONDUCT.md
  25. CONTRIBUTING.md
  26. LICENSE
  27. OWNERS
  28. PATENTS
  29. pyrightconfig.json
  30. README.md
  31. rustfmt.toml
README.md

Fuchsia

What is Fuchsia?

Fuchsia is an open source, general purpose operating system supporting modern 64-bit Intel and ARM processors.

We expect everyone interacting with our project to respect our code of conduct.

Read more about Fuchsia's principles.

How can I build and run Fuchsia?

See Getting Started.

Where can I learn more about Fuchsia?

See fuchsia.dev.