Skip to content

Commit d4cfa41

Browse files
committed
To test platform independent buildInfo baselines, move the logic to writeFile of SolutionBuilderHost
1 parent 990b199 commit d4cfa41

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

src/compiler/builder.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ namespace ts {
734734
const computeHash = host.createHash || generateDjb2Hash;
735735
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState);
736736
let backupState: BuilderProgramState | undefined;
737-
newProgram.getProgramBuildInfo = () => result.getProgramBuildInfo();
737+
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state);
738738

739739
// To ensure that we arent storing any references to old program or new program without state
740740
newProgram = undefined!; // TODO: GH#18217
@@ -758,7 +758,6 @@ namespace ts {
758758
releaseCache(state);
759759
backupState = undefined;
760760
};
761-
result.getProgramBuildInfo = () => getProgramBuildInfo(state);
762761

763762
if (kind === BuilderProgramKind.SemanticDiagnosticsBuilderProgram) {
764763
(result as SemanticDiagnosticsBuilderProgram).getSemanticDiagnosticsOfNextAffectedFile = getSemanticDiagnosticsOfNextAffectedFile;
@@ -997,7 +996,6 @@ namespace ts {
997996
getCurrentDirectory: notImplemented,
998997
emitNextAffectedFile: notImplemented,
999998
getSemanticDiagnosticsOfNextAffectedFile: notImplemented,
1000-
getProgramBuildInfo: notImplemented
1001999
};
10021000
}
10031001

@@ -1021,7 +1019,6 @@ namespace ts {
10211019
emit: (sourceFile, writeFile, cancellationToken, emitOnlyDts, customTransformers) => getProgram().emit(sourceFile, writeFile, cancellationToken, emitOnlyDts, customTransformers),
10221020
getAllDependencies: notImplemented,
10231021
getCurrentDirectory: () => getProgram().getCurrentDirectory(),
1024-
getProgramBuildInfo: () => undefined
10251022
};
10261023

10271024
function getProgram() {
@@ -1135,10 +1132,6 @@ namespace ts {
11351132
* Get the current directory of the program
11361133
*/
11371134
getCurrentDirectory(): string;
1138-
/**
1139-
* Returns the program info to be serialised
1140-
*/
1141-
/*@internal*/ getProgramBuildInfo(): ProgramBuildInfo | undefined;
11421135
}
11431136

11441137
/**

src/harness/fakes.ts

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -384,49 +384,12 @@ namespace fakes {
384384
return text;
385385
}
386386

387-
export class SolutionBuilderHost extends CompilerHost implements ts.SolutionBuilderHost<ts.BuilderProgram> {
388-
createProgram(rootNames: ReadonlyArray<string> | undefined, options: ts.CompilerOptions | undefined, host?: CompilerHost, oldProgram?: ts.EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>, projectReferences?: ReadonlyArray<ts.ProjectReference> | undefined) {
389-
const program = ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences);
390-
const originalGetProgramBuildInfo = program.getProgramBuildInfo.bind(program);
391-
program.getProgramBuildInfo = () => {
392-
const program = originalGetProgramBuildInfo() as ts.ProgramBuildInfo | undefined;
393-
if (!program) return program;
394-
// Fix lib signatures
395-
for (const path of ts.getOwnKeys(program.fileInfos)) {
396-
if (ts.startsWith(path, "/lib/")) {
397-
const currentValue = program.fileInfos[path];
398-
ts.Debug.assert(currentValue.signature === currentValue.version);
399-
program.fileInfos[path] = { version: path, signature: path };
400-
}
401-
}
402-
403-
// reference Map
404-
if (program.referencedMap) {
405-
const referencedMap: ts.MapLike<string[]> = {};
406-
for (const path of ts.getOwnKeys(program.referencedMap).sort()) {
407-
referencedMap[path] = program.referencedMap[path].sort();
408-
}
409-
program.referencedMap = referencedMap;
410-
}
411-
412-
// exportedModulesMap
413-
if (program.exportedModulesMap) {
414-
const exportedModulesMap: ts.MapLike<string[]> = {};
415-
for (const path of ts.getOwnKeys(program.exportedModulesMap).sort()) {
416-
exportedModulesMap[path] = program.exportedModulesMap[path].sort();
417-
}
418-
program.exportedModulesMap = exportedModulesMap;
419-
}
420-
421-
// semanticDiagnosticsPerFile
422-
if (program.semanticDiagnosticsPerFile) {
423-
program.semanticDiagnosticsPerFile.sort();
424-
}
387+
function compareProgramBuildInfoDiagnostic(a: ts.ProgramBuildInfoDiagnostic, b: ts.ProgramBuildInfoDiagnostic) {
388+
return ts.compareStringsCaseSensitive(ts.isString(a) ? a : a[0], ts.isString(b) ? b : b[0]);
389+
}
425390

426-
return program;
427-
};
428-
return program;
429-
}
391+
export class SolutionBuilderHost extends CompilerHost implements ts.SolutionBuilderHost<ts.BuilderProgram> {
392+
createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram;
430393

431394
readFile(path: string) {
432395
const value = super.readFile(path);
@@ -447,6 +410,48 @@ namespace fakes {
447410
return ts.getBuildInfoText(buildInfo);
448411
}
449412

413+
public writeFile(fileName: string, content: string, writeByteOrderMark: boolean) {
414+
if (ts.isBuildInfoFile(fileName)) {
415+
const buildInfo = JSON.parse(content) as ts.BuildInfo;
416+
if (buildInfo.program) {
417+
// Fix lib signatures
418+
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
419+
if (ts.startsWith(path, "/lib/")) {
420+
const currentValue = buildInfo.program.fileInfos[path];
421+
ts.Debug.assert(currentValue.signature === currentValue.version);
422+
buildInfo.program.fileInfos[path] = { version: path, signature: path };
423+
}
424+
}
425+
426+
// reference Map
427+
if (buildInfo.program.referencedMap) {
428+
const referencedMap: ts.MapLike<string[]> = {};
429+
for (const path of ts.getOwnKeys(buildInfo.program.referencedMap).sort()) {
430+
referencedMap[path] = buildInfo.program.referencedMap[path].sort();
431+
}
432+
buildInfo.program.referencedMap = referencedMap;
433+
}
434+
435+
// exportedModulesMap
436+
if (buildInfo.program.exportedModulesMap) {
437+
const exportedModulesMap: ts.MapLike<string[]> = {};
438+
for (const path of ts.getOwnKeys(buildInfo.program.exportedModulesMap).sort()) {
439+
exportedModulesMap[path] = buildInfo.program.exportedModulesMap[path].sort();
440+
}
441+
buildInfo.program.exportedModulesMap = exportedModulesMap;
442+
}
443+
444+
// semanticDiagnosticsPerFile
445+
if (buildInfo.program.semanticDiagnosticsPerFile) {
446+
buildInfo.program.semanticDiagnosticsPerFile.sort(compareProgramBuildInfoDiagnostic);
447+
}
448+
449+
content = ts.getBuildInfoText(buildInfo);
450+
}
451+
}
452+
super.writeFile(fileName, content, writeByteOrderMark);
453+
}
454+
450455
now() {
451456
return new Date(this.sys.vfs.time());
452457
}

0 commit comments

Comments
 (0)