-
Notifications
You must be signed in to change notification settings - Fork 631
[rush] Split ProjectChangeAnalyzer, fix build cache hashes #4476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rush] Split ProjectChangeAnalyzer, fix build cache hashes #4476
Conversation
libraries/rush-lib/src/logic/operations/CacheableOperationPlugin.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do a pre-publish to verify that everything that is changing here doesn't break our flow, since we're very likely the largest customer on this tool.
common/changes/@microsoft/rush/split-project-change-analyzer_2024-01-09-22-11.json
Outdated
Show resolved
Hide resolved
common/changes/@microsoft/rush/split-project-change-analyzer_2024-01-09-22-06.json
Outdated
Show resolved
Hide resolved
libraries/rush-lib/src/logic/operations/CacheableOperationPlugin.ts
Outdated
Show resolved
Hide resolved
c7d98ec
to
1836e05
Compare
f4a0556
to
5a6794d
Compare
common/changes/@rushstack/lookup-by-path/split-project-change-analyzer_2024-09-24-23-54.json
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed feedback.
libraries/rush-lib/src/logic/buildCache/test/ProjectBuildCache.test.ts
Outdated
Show resolved
Hide resolved
13b7dbc
to
2dcdd49
Compare
2dcdd49
to
d8dc986
Compare
d8dc986
to
5638027
Compare
e57e3dc
to
4edbbb8
Compare
Summary
Fixes #4400
Makes #3994 more feasible.
Details
Splits the functionality of ProjectChangeAnalyzer into two components:
ProjectChangeAnalyzer#_tryGetSnapshotProviderAsync
- Performs all the async I/O operations to determine the current state of the repository, including taking a snapshot ofprocess.env
so that per-operation hashes can be lazily computed in a stable manner.InputsSnapshot
- Synchronous data structure representing the state of the repository, which can be queried for operation-level state hashes, or tracked file lists. Performs the evaluation of input/output collisions as part of evaluating said queries. Includes evaluation ofincrementalBuildIgnoredGlobs
anddependsOnEnvVars
, but does not include the hashes from dependencies, since the Operation graph is not provided to this API.Moves build cache hash computation to the
beforeExecuteOperations
tap inCacheableOperationPlugin
and updates the computation to factor in the runtime operation graph, rather than only the npm dependencies.For a specific example of how this alters the build cache, consider a repository with one project and two phases in
rush build
:Project
A
Phases
_phase:first
and_phase:second
, with_phase:second
depends onself: ['_phase:first']
Define a command line parameter
--some-flag-for-first
that is forwarded only to_phase:first
.Before this change, running
rush build
andrush build --some-flag-for-first
would produce different cache IDs forA (_phase:first)
, but the same cache id forA (_phase:second)
.With this change the cache IDs for
A (_phase:second)
are also impacted by the presence of the--some-flag-for-first
, since it can change the output ofA (_phase:first)
.Added a new flag
enabled
toOperation
to control whether or not a given operation in the graph should be executed. Updated graph construction to use this flag for operations that are dependencies of the user's selection, but not directly included (e.g. when using--only
or--impacted-by
), or during watch-mode incremental builds.Added a new property
cacheHashSalt
tobuild-cache.json
to allow repository maintainers to globally force cache misses if they have altered the build process in a way that Rush can't currently detect, for example if Rush plugins emit files that would be picked up by the cache.How it was tested
For the splitting, added unit tests for
InputSnapshot
andProjectChangeAnalyzer#_tryGetSnapshotProviderAsync
.For the build cache IDs, temporarily removed applicability of the
--production
CLI parameter from_phase:test
and validated that runningnode ./apps/rush/lib/start-dev.js test
andnode ./apps/rush/lib/start-dev.js test --production
still produced different cache keys for_phase:test
.For comparison, validated that the command-line.json alternation and existing
rush test
andrush test --production
had a collision on the cache keys for_phase:test
.Validated cache reads/writes using the
heft-node-everything-test
project. Confirmed that cache is not written during arush rebuild -o
, but can be read duringrush build -o
. Confirmed that cache reads can occur duringrush start -o
, even on subsequent iterations that leverage the new:incremental
suffixed scripts.Validate the
cacheHashSalt
property by setting the salt to different values and validating cache/miss hit depending on whether or not a prior build had happened with the same salt.Impacted documentation
Any documentation about how build cache keys are computed.