Skip to content

Commit

Permalink
[FIX] ProjectBuilder: Skip build for projects that do not require to …
Browse files Browse the repository at this point in the history
…be built
  • Loading branch information
RandomByte committed Jul 26, 2022
1 parent fe14a3b commit ac5f1f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
10 changes: 6 additions & 4 deletions lib/build/ProjectBuilder.js
Expand Up @@ -133,11 +133,13 @@ class ProjectBuilder {

for (const projectBuildContext of buildQueue) {
const projectName = projectBuildContext.getProject().getName();
buildLogger.startWork(`Building project ${projectName}...`);
await this._buildProject(projectBuildContext);
buildLogger.completeWork(1);
if (projectBuildContext.getTaskRunner().requiresBuild()) {
buildLogger.startWork(`Building project ${projectName}...`);
await this._buildProject(projectBuildContext);
buildLogger.completeWork(1);

log.verbose(`Finished building project ${projectName}`);
log.verbose(`Finished building project ${projectName}`);
}
if (!requestedProjects.includes(projectName)) {
// Project has not been requested
// => Its resources shall not be part of the build result
Expand Down
24 changes: 13 additions & 11 deletions test/lib/build/ProjectBuilder.js
Expand Up @@ -126,7 +126,7 @@ test("build", async (t) => {
"project.a", "project.b", "project.c"
], "_createRequiredBuildContexts got called with correct arguments");

t.is(requiresBuildStub.callCount, 1, "TaskRunner#requiresBuild got called once");
t.is(requiresBuildStub.callCount, 2, "TaskRunner#requiresBuild got called twice");
t.is(registerCleanupSigHooksStub.callCount, 1, "_registerCleanupSigHooksStub got called once");

t.is(buildProjectStub.callCount, 1, "_buildProject got called once");
Expand Down Expand Up @@ -225,27 +225,29 @@ test.serial("build: Multiple projects", async (t) => {
const filterProjectStub = sinon.stub().returns(true).onFirstCall().returns(false);
const getProjectFilterStub = sinon.stub(builder, "_getProjectFilter").resolves(filterProjectStub);

const requiresBuildStub = sinon.stub().returns(true);
const requiresBuildAStub = sinon.stub().returns(true);
const requiresBuildBStub = sinon.stub().returns(false);
const requiresBuildCStub = sinon.stub().returns(true);
const projectBuildContextMockA = {
getTaskRunner: () => {
return {
requiresBuild: requiresBuildStub
requiresBuild: requiresBuildAStub
};
},
getProject: sinon.stub().returns(getMockProject("library", "a"))
};
const projectBuildContextMockB = {
getTaskRunner: () => {
return {
requiresBuild: requiresBuildStub
requiresBuild: requiresBuildBStub
};
},
getProject: sinon.stub().returns(getMockProject("library", "b"))
};
const projectBuildContextMockC = {
getTaskRunner: () => {
return {
requiresBuild: requiresBuildStub
requiresBuild: requiresBuildCStub
};
},
getProject: sinon.stub().returns(getMockProject("library", "c"))
Expand Down Expand Up @@ -280,18 +282,18 @@ test.serial("build: Multiple projects", async (t) => {
"project.b", "project.c"
], "_createRequiredBuildContexts got called with correct arguments");

t.is(requiresBuildStub.callCount, 3, "TaskRunner#requiresBuild got called three times");
t.is(requiresBuildAStub.callCount, 2, "TaskRunner#requiresBuild got called twice times for library.a");
t.is(requiresBuildBStub.callCount, 2, "TaskRunner#requiresBuild got called twice times for library.b");
t.is(requiresBuildCStub.callCount, 2, "TaskRunner#requiresBuild got called twice times for library.c");
t.is(registerCleanupSigHooksStub.callCount, 1, "_registerCleanupSigHooksStub got called once");

t.is(buildProjectStub.callCount, 3, "_buildProject got called three times");
t.is(buildProjectStub.callCount, 2, "_buildProject got called three times"); // library.b does not require a build
t.is(buildProjectStub.getCall(0).args[0], projectBuildContextMockA,
"_buildProject got called with correct arguments");
t.is(buildProjectStub.getCall(1).args[0], projectBuildContextMockB,
"_buildProject got called with correct arguments");
t.is(buildProjectStub.getCall(2).args[0], projectBuildContextMockC,
t.is(buildProjectStub.getCall(1).args[0], projectBuildContextMockC,
"_buildProject got called with correct arguments");

t.is(writeResultsStub.callCount, 2, "_writeResults got called twice"); // not all projects have been requested
t.is(writeResultsStub.callCount, 2, "_writeResults got called twice"); // library.a has not been requested
t.is(writeResultsStub.getCall(0).args[0], projectBuildContextMockB,
"_writeResults got called with correct first argument");
t.is(writeResultsStub.getCall(0).args[1]._fsBasePath, path.resolve("dest/path"),
Expand Down

0 comments on commit ac5f1f8

Please sign in to comment.