Skip to content

Commit bcf6702

Browse files
authored
Merge pull request microsoft#2856 from dmichon-msft/fix-build-cache-read
[rush] Allow build cache reads downstream of built projects during `rush build`
2 parents 2d23fe9 + e2fe81b commit bcf6702

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

apps/rush-lib/src/logic/taskRunner/BaseBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export abstract class BaseBuilder {
2727
abstract readonly name: string;
2828

2929
/**
30-
* This flag determines if an incremental build is allowed for the task.
30+
* This flag determines if the task is allowed to be skipped if up to date.
3131
*/
32-
abstract isIncrementalBuildAllowed: boolean;
32+
abstract isSkipAllowed: boolean;
3333

3434
/**
3535
* Assigned by execute(). True if the build script was an empty string. Operationally an empty string is

apps/rush-lib/src/logic/taskRunner/ProjectBuilder.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ export class ProjectBuilder extends BaseBuilder {
7777
return ProjectBuilder.getTaskName(this._rushProject);
7878
}
7979

80-
public readonly isIncrementalBuildAllowed: boolean;
80+
/**
81+
* This property is mutated by TaskRunner, so is not readonly
82+
*/
83+
public isSkipAllowed: boolean;
8184
public hadEmptyScript: boolean = false;
8285

8386
private readonly _rushProject: RushConfigurationProject;
8487
private readonly _rushConfiguration: RushConfiguration;
8588
private readonly _buildCacheConfiguration: BuildCacheConfiguration | undefined;
8689
private readonly _commandName: string;
8790
private readonly _commandToRun: string;
91+
private readonly _isCacheReadAllowed: boolean;
8892
private readonly _projectChangeAnalyzer: ProjectChangeAnalyzer;
8993
private readonly _packageDepsFilename: string;
9094

@@ -101,7 +105,8 @@ export class ProjectBuilder extends BaseBuilder {
101105
this._buildCacheConfiguration = options.buildCacheConfiguration;
102106
this._commandName = options.commandName;
103107
this._commandToRun = options.commandToRun;
104-
this.isIncrementalBuildAllowed = options.isIncrementalBuildAllowed;
108+
this._isCacheReadAllowed = options.isIncrementalBuildAllowed;
109+
this.isSkipAllowed = options.isIncrementalBuildAllowed;
105110
this._projectChangeAnalyzer = options.projectChangeAnalyzer;
106111
this._packageDepsFilename = options.packageDepsFilename;
107112
}
@@ -229,7 +234,7 @@ export class ProjectBuilder extends BaseBuilder {
229234
files,
230235
arguments: this._commandToRun
231236
};
232-
} else if (this.isIncrementalBuildAllowed) {
237+
} else if (this.isSkipAllowed) {
233238
// To test this code path:
234239
// Remove the `.git` folder then run "rush build --verbose"
235240
terminal.writeLine({
@@ -250,9 +255,8 @@ export class ProjectBuilder extends BaseBuilder {
250255
});
251256
}
252257

253-
// If the current command is allowed to do incremental builds, attempt to retrieve
254-
// the project from the build cache or skip building, if appropriate.
255-
if (this.isIncrementalBuildAllowed) {
258+
// If allowed to read from the build cache, try retrieving the cache entry.
259+
if (this._isCacheReadAllowed) {
256260
const projectBuildCache: ProjectBuildCache | undefined = await this._getProjectBuildCacheAsync(
257261
terminal,
258262
trackedFiles,
@@ -264,7 +268,10 @@ export class ProjectBuilder extends BaseBuilder {
264268
if (restoreFromCacheSuccess) {
265269
return TaskStatus.FromCache;
266270
}
271+
}
267272

273+
// If allowed, attempt to skip building.
274+
if (this.isSkipAllowed) {
268275
const isPackageUnchanged: boolean = !!(
269276
lastProjectBuildDeps &&
270277
projectBuildDeps &&

apps/rush-lib/src/logic/taskRunner/TaskRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export class TaskRunner {
338338

339339
task.dependents.forEach((dependent: Task) => {
340340
if (!this._changedProjectsOnly) {
341-
dependent.builder.isIncrementalBuildAllowed = false;
341+
dependent.builder.isSkipAllowed = false;
342342
}
343343
dependent.dependencies.delete(task);
344344
});
@@ -355,7 +355,7 @@ export class TaskRunner {
355355
task.status = TaskStatus.SuccessWithWarning;
356356
task.dependents.forEach((dependent: Task) => {
357357
if (!this._changedProjectsOnly) {
358-
dependent.builder.isIncrementalBuildAllowed = false;
358+
dependent.builder.isSkipAllowed = false;
359359
}
360360
dependent.dependencies.delete(task);
361361
});

apps/rush-lib/src/logic/taskRunner/test/MockBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class MockBuilder extends BaseBuilder {
1010
private readonly _action: ((terminal: CollatedTerminal) => Promise<TaskStatus>) | undefined;
1111
public readonly name: string;
1212
public readonly hadEmptyScript: boolean = false;
13-
public readonly isIncrementalBuildAllowed: boolean = false;
13+
public readonly isSkipAllowed: boolean = false;
1414

1515
public constructor(name: string, action?: (terminal: CollatedTerminal) => Promise<TaskStatus>) {
1616
super();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "When build cache is enabled in `rush build`, allow projects downstream to be satisfied from the cache if applicable. Cache reads will still be disabled for `rush rebuild`.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "dmichon-msft@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)