Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dmichon-msft
Copy link
Contributor

Summary

Fixes #4400

Makes #3994 more feasible.

Details

Splits the functionality of ProjectChangeAnalyzer into two components:

  1. ProjectChangeAnalyzer#_tryGetSnapshotAsync - Performs all the async I/O operations to determine the current state of the repository, including taking a snapshot of process.env so that per-operation hashes can be lazily computed in a stable manner.
  2. InputSnapshot - 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 of incrementalBuildIgnoredGlobs and dependsOnEnvVars, 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 createOperations tap in CacheableOperationPlugin 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 on self: ['_phase:first']

Define a command line parameter --some-flag-for-first that is forwarded only to _phase:first.

Before this change, running rush build and rush build --some-flag-for-first would produce different cache IDs for A (_phase:first), but the same cache id for A (_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 of A (_phase:first).

How it was tested

For the splitting, added unit tests for InputSnapshot and ProjectChangeAnalyzer#_tryGetSnapshotAsync.

For the build cache IDs, temporarily removed applicability of the --production CLI parameter from _phase:test and validated that running node ./apps/rush/lib/start-dev.js test and node ./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 and rush test --production had a collision on the cache keys for _phase:test.

Impacted documentation

Any documentation about how build cache keys are computed.

additionalFilesFromRushProjectConfiguration.add(match);
additionalFilesForOperation.add(match);
} else {
const filePathForGit: string = path.posix.join(project.projectRelativeFolder, match);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be from the root of the rush.json folder. Should verify if that is the correct path root for the git hash for files method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not just concatenate the path parts together with a slash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It is valid for match to start with ../.

Copy link
Member

@D4N14L D4N14L left a 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/reviews/api/rush-lib.api.md Outdated Show resolved Hide resolved
libraries/rush-lib/src/logic/snapshots/InputSnapshot.ts Outdated Show resolved Hide resolved
libraries/rush-lib/src/logic/snapshots/InputSnapshot.ts Outdated Show resolved Hide resolved
additionalFilesFromRushProjectConfiguration.add(match);
additionalFilesForOperation.add(match);
} else {
const filePathForGit: string = path.posix.join(project.projectRelativeFolder, match);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not just concatenate the path parts together with a slash?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[rush] Build cache keys do not correctly account for configuration changes in dependencies
3 participants