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
{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.
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.
See CONTRIBUTING.md