Write version for baselining in buildinfo (#48602)

Also baseline buildinfo so its easier to detect mistakes
This commit is contained in:
Sheetal Nandi
2022-04-07 13:38:54 -07:00
committed by GitHub
parent b18141b0bc
commit d8edd191ab
9 changed files with 832 additions and 50 deletions

View File

@@ -146,8 +146,7 @@ namespace ts {
commandLineArgs: ["--b", "/src/third", "--verbose"],
compile: sys => {
// Buildinfo will have version which does not match with current ts version
fakes.patchHostForBuildInfoWrite(sys, "FakeTSCurrentVersion");
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
const builder = ts.createSolutionBuilder(buildHost, ["/src/third"], { verbose: true });
sys.exit(builder.build());
}
@@ -181,7 +180,7 @@ namespace ts {
fs: () => outFileFs,
commandLineArgs: ["--build", "/src/second/tsconfig.json"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
sys.exit(builder.build("/src/second/tsconfig.json"));
}
@@ -193,7 +192,7 @@ namespace ts {
fs: getOutFileFsAfterBuild,
commandLineArgs: ["--build", "--clean", "/src/second/tsconfig.json"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], { verbose: true });
sys.exit(builder.clean("/src/second/tsconfig.json"));
}

View File

@@ -84,7 +84,7 @@ namespace ts {
fs: getSampleFsAfterBuild,
commandLineArgs: ["--b", "/src/logic", "--clean"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
sys.exit(builder.clean("/src/logic"));
}
@@ -96,7 +96,7 @@ namespace ts {
fs: getSampleFsAfterBuild,
commandLineArgs: ["--b", "/src/logic2", "--clean"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
sys.exit(builder.clean("/src/logic2"));
}
@@ -158,8 +158,7 @@ namespace ts {
commandLineArgs: ["--b", "/src/tests", "--verbose"],
compile: sys => {
// Buildinfo will have version which does not match with current ts version
fakes.patchHostForBuildInfoWrite(sys, "FakeTSCurrentVersion");
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
const builder = createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
sys.exit(builder.build());
}
@@ -179,8 +178,7 @@ namespace ts {
commandLineArgs: ["--b", "/src/tests", "--verbose"],
compile: sys => {
// Buildinfo will have version which does not match with current ts version
fakes.patchHostForBuildInfoWrite(sys, "FakeTSCurrentVersion");
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
const builder = createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
sys.exit(builder.build());
},
@@ -207,7 +205,7 @@ namespace ts {
fs: () => projFs,
commandLineArgs: ["--build", "/src/logic/tsconfig.json"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = createSolutionBuilder(buildHost, ["/src/tests"], {});
sys.exit(builder.build("/src/logic/tsconfig.json"));
}
@@ -219,7 +217,7 @@ namespace ts {
fs: () => projFs,
commandLineArgs: ["--build", "/src/logic2/tsconfig.json"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = createSolutionBuilder(buildHost, ["/src/tests"], {});
sys.exit(builder.build("/src/logic2/tsconfig.json"));
}
@@ -278,7 +276,7 @@ namespace ts {
fs: () => projFs,
commandLineArgs: ["--build", "/src/logic2/tsconfig.json"],
compile: sys => {
const buildHost = createSolutionBuilderHost(sys);
const buildHost = createSolutionBuilderHostForBaseline(sys);
const builder = createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
sys.exit(builder.buildReferences("/src/tests"));
}

View File

@@ -109,6 +109,37 @@ ${patch ? vfs.formatPatch(patch) : ""}`
return sys;
}
function makeSystemReadyForBaseline(sys: TscCompileSystem, versionToWrite?: string) {
if (versionToWrite) {
fakes.patchHostForBuildInfoWrite(sys, versionToWrite);
}
else {
fakes.patchHostForBuildInfoReadWrite(sys);
}
const writtenFiles = sys.writtenFiles = new Set();
const originalWriteFile = sys.writeFile;
sys.writeFile = (fileName, content, writeByteOrderMark) => {
const path = toPathWithSystem(sys, fileName);
assert.isFalse(writtenFiles.has(path));
writtenFiles.add(path);
return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
};
return originalWriteFile;
}
export function createSolutionBuilderHostForBaseline(sys: TscCompileSystem, versionToWrite?: string) {
makeSystemReadyForBaseline(sys, versionToWrite);
const { cb } = commandLineCallbacks(sys);
const host = createSolutionBuilderHost(sys,
/*createProgram*/ undefined,
createDiagnosticReporter(sys, /*pretty*/ true),
createBuilderStatusReporter(sys, /*pretty*/ true),
);
host.afterProgramEmitAndDiagnostics = cb;
host.afterEmitBundle = cb;
return host;
}
/**
* Initialize Fs, execute command line and save baseline
*/
@@ -122,15 +153,7 @@ ${patch ? vfs.formatPatch(patch) : ""}`
});
function commandLineCompile(sys: TscCompileSystem) {
fakes.patchHostForBuildInfoReadWrite(sys);
const writtenFiles = sys.writtenFiles = new Set();
const originalWriteFile = sys.writeFile;
sys.writeFile = (fileName, content, writeByteOrderMark) => {
const path = toPathWithSystem(sys, fileName);
assert.isFalse(writtenFiles.has(path));
writtenFiles.add(path);
return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
};
const originalWriteFile = makeSystemReadyForBaseline(sys);
actualReadFileMap = {};
const originalReadFile = sys.readFile;
sys.readFile = path => {