Prepare OptionsDiff for serialization

This is the first change in a chain that will allow using `OptionsDiff` in the serialization of `BuildConfigurationKey` objects.

A `BuildConfigurationKey` is needed in many different values serialized by Skycache (e.g., derived artifacts). Since their cache keys are obtained by fingerprinting the entire serialized value, any difference in the configuration stored alongside a file path forces us to store the entire value again, even if the path of the artifact itself is identical. With this and follow-up changes, we will be able to significantly reduce the number of novel bytes written to the cache between two invocations with different configurations, as long as they build the same targets.

We do this by either not storing the `BuildOptions` as part of the `BuildConfigurationKey` at all if it matches the baseline configuration present in the `{Serialization|Deserialization}Context`, or by storing a diff between the `BuildOptions` object being serialized and the baseline. Since these diffs are identical across different invocations in the majority of cases (even if the starting baselines differ), we are able to serialize many values to the exact same output bytes across builds.

This CL:
* Expands `OptionsDiff` to track metadata such as Starlark scope types and `onLeave` values, which are necessary to fully restore the original `BuildOptions` objects.
* Introduces the `applyDiff` method, which will be used during deserialization to reconstruct the target `BuildOptions` object by applying the diff to the baseline configuration retrieved from the context.
* Ensures that differing metadata does not affect the `ST-<hash>` path segments created by `OutputPathMnemonicComputer`.
* Updates the data structures used by the `OptionsDiff` class to be deterministic (e.g., using `LinkedHashMap` and `OrderedSetMultimap`).
* Additionally, `ListDiff` is designed to avoid storing the original baseline elements when they are entirely removed or reset in the transitioned options set. This allows a wider range of `BuildConfigurationKey` values to serialize to the exact same representation across builds.

A follow-up CL will introduce a codec for `OptionsDiff`. All the newly introduced logic for `OptionsDiff` will itself be leveraged in a subsequent CL that will introduce a custom codec for `BuildConfigurationKey`.

RELNOTES:none
PiperOrigin-RevId: 933579645
Change-Id: I8add341d87f833f839ce058a620036ac3aed02b9
4 files changed
tree: 3848400866abc456746094f97633cea40f6a3c52
  1. .bazelci/
  2. .devcontainer/
  3. .gemini/
  4. .github/
  5. docs/
  6. examples/
  7. scripts/
  8. site/
  9. src/
  10. third_party/
  11. tools/
  12. .bazelrc
  13. .bazelversion
  14. .gitattributes
  15. .gitignore
  16. AGENTS.md
  17. AUTHORS
  18. bazel_downloader.cfg
  19. BUILD
  20. CHANGELOG.md
  21. CODE_OF_CONDUCT.md
  22. CODEOWNERS
  23. combine_distfiles.py
  24. combine_distfiles_to_tar.sh
  25. compile.sh
  26. CONTRIBUTING.md
  27. CONTRIBUTORS
  28. distdir.bzl
  29. extensions.bzl
  30. LICENSE
  31. maven_install.json
  32. MODULE.bazel
  33. MODULE.bazel.lock
  34. oneversion_allowlist.csv
  35. oneversion_allowlist_for_tests.csv
  36. pyproject.toml
  37. README.md
  38. repositories.bzl
  39. requirements.txt
  40. SECURITY.md
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Reporting a Vulnerability

To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.

Contributing to Bazel

See CONTRIBUTING.md

Build status