Skip to content

Commit bf63811

Browse files
Merge pull request #10213 from RyanCavanaugh/baselinePerf
Make baselines faster by not writing out unneeded files
2 parents 9769718 + b0a4e27 commit bf63811

File tree

5 files changed

+78
-76
lines changed

5 files changed

+78
-76
lines changed

Gulpfile.ts

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare module "gulp-typescript" {
1717
stripInternal?: boolean;
1818
types?: string[];
1919
}
20-
interface CompileStream extends NodeJS.ReadWriteStream {} // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
20+
interface CompileStream extends NodeJS.ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
2121
}
2222
import * as insert from "gulp-insert";
2323
import * as sourcemaps from "gulp-sourcemaps";
@@ -65,7 +65,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
6565
}
6666
});
6767

68-
function exec(cmd: string, args: string[], complete: () => void = (() => {}), error: (e: any, status: number) => void = (() => {})) {
68+
function exec(cmd: string, args: string[], complete: () => void = (() => { }), error: (e: any, status: number) => void = (() => { })) {
6969
console.log(`${cmd} ${args.join(" ")}`);
7070
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
7171
const subshellFlag = isWin ? "/c" : "-c";
@@ -116,12 +116,12 @@ const es2015LibrarySources = [
116116
];
117117

118118
const es2015LibrarySourceMap = es2015LibrarySources.map(function(source) {
119-
return { target: "lib." + source, sources: ["header.d.ts", source] };
119+
return { target: "lib." + source, sources: ["header.d.ts", source] };
120120
});
121121

122-
const es2016LibrarySource = [ "es2016.array.include.d.ts" ];
122+
const es2016LibrarySource = ["es2016.array.include.d.ts"];
123123

124-
const es2016LibrarySourceMap = es2016LibrarySource.map(function (source) {
124+
const es2016LibrarySourceMap = es2016LibrarySource.map(function(source) {
125125
return { target: "lib." + source, sources: ["header.d.ts", source] };
126126
});
127127

@@ -130,38 +130,38 @@ const es2017LibrarySource = [
130130
"es2017.sharedmemory.d.ts"
131131
];
132132

133-
const es2017LibrarySourceMap = es2017LibrarySource.map(function (source) {
133+
const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) {
134134
return { target: "lib." + source, sources: ["header.d.ts", source] };
135135
});
136136

137137
const hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"];
138138

139139
const librarySourceMap = [
140-
// Host library
141-
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] },
142-
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] },
143-
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] },
144-
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },
145-
146-
// JavaScript library
147-
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
148-
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] },
149-
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] },
150-
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] },
151-
152-
// JavaScript + all host library
153-
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
154-
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") }
140+
// Host library
141+
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] },
142+
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] },
143+
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] },
144+
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },
145+
146+
// JavaScript library
147+
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
148+
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] },
149+
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] },
150+
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] },
151+
152+
// JavaScript + all host library
153+
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
154+
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") }
155155
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap);
156156

157-
const libraryTargets = librarySourceMap.map(function (f) {
157+
const libraryTargets = librarySourceMap.map(function(f) {
158158
return path.join(builtLocalDirectory, f.target);
159159
});
160160

161161
for (const i in libraryTargets) {
162162
const entry = librarySourceMap[i];
163163
const target = libraryTargets[i];
164-
const sources = [copyright].concat(entry.sources.map(function (s) {
164+
const sources = [copyright].concat(entry.sources.map(function(s) {
165165
return path.join(libraryDirectory, s);
166166
}));
167167
gulp.task(target, false, [], function() {
@@ -391,7 +391,7 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
391391
.pipe(sourcemaps.init())
392392
.pipe(tsc(servicesProject));
393393
const completedJs = js.pipe(prependCopyright())
394-
.pipe(sourcemaps.write("."));
394+
.pipe(sourcemaps.write("."));
395395
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
396396
.pipe(insert.transform((contents, file) => {
397397
file.path = standaloneDefinitionsFile;
@@ -434,17 +434,17 @@ const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverli
434434

435435
gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
436436
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
437-
const {js, dts}: {js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream} = serverLibraryProject.src()
437+
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
438438
.pipe(sourcemaps.init())
439439
.pipe(newer(tsserverLibraryFile))
440440
.pipe(tsc(serverLibraryProject));
441441

442442
return merge2([
443443
js.pipe(prependCopyright())
444-
.pipe(sourcemaps.write("."))
445-
.pipe(gulp.dest(builtLocalDirectory)),
444+
.pipe(sourcemaps.write("."))
445+
.pipe(gulp.dest(builtLocalDirectory)),
446446
dts.pipe(prependCopyright())
447-
.pipe(gulp.dest(builtLocalDirectory))
447+
.pipe(gulp.dest(builtLocalDirectory))
448448
]);
449449
});
450450

@@ -476,7 +476,7 @@ gulp.task(specMd, false, [word2mdJs], (done) => {
476476
const specMDFullPath = path.resolve(specMd);
477477
const cmd = "cscript //nologo " + word2mdJs + " \"" + specWordFullPath + "\" " + "\"" + specMDFullPath + "\"";
478478
console.log(cmd);
479-
cp.exec(cmd, function () {
479+
cp.exec(cmd, function() {
480480
done();
481481
});
482482
});
@@ -492,12 +492,12 @@ gulp.task("dontUseDebugMode", false, [], (done) => { useDebugMode = false; done(
492492

493493
gulp.task("VerifyLKG", false, [], () => {
494494
const expectedFiles = [builtLocalCompiler, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile].concat(libraryTargets);
495-
const missingFiles = expectedFiles.filter(function (f) {
495+
const missingFiles = expectedFiles.filter(function(f) {
496496
return !fs.existsSync(f);
497497
});
498498
if (missingFiles.length > 0) {
499499
throw new Error("Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
500-
". The following files are missing:\n" + missingFiles.join("\n"));
500+
". The following files are missing:\n" + missingFiles.join("\n"));
501501
}
502502
// Copy all the targets into the LKG directory
503503
return gulp.src(expectedFiles).pipe(gulp.dest(LKGDirectory));
@@ -531,8 +531,6 @@ const localRwcBaseline = path.join(internalTests, "baselines/rwc/local");
531531
const refRwcBaseline = path.join(internalTests, "baselines/rwc/reference");
532532

533533
const localTest262Baseline = path.join(internalTests, "baselines/test262/local");
534-
const refTest262Baseline = path.join(internalTests, "baselines/test262/reference");
535-
536534

537535
gulp.task("tests", "Builds the test infrastructure using the built compiler", [run]);
538536
gulp.task("tests-debug", "Builds the test sources and automation in debug mode", () => {
@@ -627,7 +625,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
627625
}
628626
args.push(run);
629627
setNodeEnvToDevelopment();
630-
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function (err) {
628+
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function(err) {
631629
// last worker clean everything and runs linter in case if there were no errors
632630
del(taskConfigsFolder).then(() => {
633631
if (!err) {
@@ -679,7 +677,7 @@ gulp.task("runtests",
679677
["build-rules", "tests"],
680678
(done) => {
681679
runConsoleTests("mocha-fivemat-progress-reporter", /*runInParallel*/ false, done);
682-
});
680+
});
683681

684682
const nodeServerOutFile = "tests/webTestServer.js";
685683
const nodeServerInFile = "tests/webTestServer.ts";
@@ -811,32 +809,36 @@ gulp.task("diff-rwc", "Diffs the RWC baselines using the diff tool specified by
811809
exec(getDiffTool(), [refRwcBaseline, localRwcBaseline], done, done);
812810
});
813811

814-
815-
gulp.task("baseline-accept", "Makes the most recent test results the new baseline, overwriting the old baseline", (done) => {
816-
const softAccept = cmdLineOptions["soft"];
817-
if (!softAccept) {
818-
del(refBaseline).then(() => {
819-
fs.renameSync(localBaseline, refBaseline);
820-
done();
821-
}, done);
822-
}
823-
else {
824-
gulp.src(localBaseline)
825-
.pipe(gulp.dest(refBaseline))
826-
.on("end", () => {
827-
del(path.join(refBaseline, "local")).then(() => done(), done);
828-
});
829-
}
812+
gulp.task("baseline-accept", "Makes the most recent test results the new baseline, overwriting the old baseline", () => {
813+
return baselineAccept("");
830814
});
815+
816+
function baselineAccept(subfolder = "") {
817+
return merge2(baselineCopy(subfolder), baselineDelete(subfolder));
818+
}
819+
820+
function baselineCopy(subfolder = "") {
821+
return gulp.src([`tests/baselines/local/${subfolder}/**`, `!tests/baselines/local/${subfolder}/**/*.delete`])
822+
.pipe(gulp.dest(refBaseline));
823+
}
824+
825+
function baselineDelete(subfolder = "") {
826+
return gulp.src(["tests/baselines/local/**/*.delete"])
827+
.pipe(insert.transform((content, fileObj) => {
828+
const target = path.join(refBaseline, fileObj.relative.substr(0, fileObj.relative.length - ".delete".length));
829+
del.sync(target);
830+
del.sync(fileObj.path);
831+
return "";
832+
}));
833+
}
834+
831835
gulp.task("baseline-accept-rwc", "Makes the most recent rwc test results the new baseline, overwriting the old baseline", () => {
832-
return del(refRwcBaseline).then(() => {
833-
fs.renameSync(localRwcBaseline, refRwcBaseline);
834-
});
836+
return baselineAccept("rwc");
835837
});
838+
839+
836840
gulp.task("baseline-accept-test262", "Makes the most recent test262 test results the new baseline, overwriting the old baseline", () => {
837-
return del(refTest262Baseline).then(() => {
838-
fs.renameSync(localTest262Baseline, refTest262Baseline);
839-
});
841+
return baselineAccept("test262");
840842
});
841843

842844

Jakefile.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -937,16 +937,16 @@ task("tests-debug", ["setDebugMode", "tests"]);
937937
// Makes the test results the new baseline
938938
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
939939
task("baseline-accept", function(hardOrSoft) {
940-
if (!hardOrSoft || hardOrSoft === "hard") {
941-
jake.rmRf(refBaseline);
942-
fs.renameSync(localBaseline, refBaseline);
943-
}
944-
else if (hardOrSoft === "soft") {
945-
var files = jake.readdirR(localBaseline);
946-
for (var i in files) {
940+
var files = jake.readdirR(localBaseline);
941+
var deleteEnding = '.delete';
942+
for (var i in files) {
943+
if (files[i].substr(files[i].length - deleteEnding.length) === deleteEnding) {
944+
var filename = path.basename(files[i]);
945+
filename = filename.substr(0, filename.length - deleteEnding.length);
946+
fs.unlink(path.join(refBaseline, filename));
947+
} else {
947948
jake.cpR(files[i], refBaseline);
948949
}
949-
jake.rmRf(path.join(refBaseline, "local"));
950950
}
951951
});
952952

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"mkdirp": "latest",
7070
"mocha": "latest",
7171
"mocha-fivemat-progress-reporter": "latest",
72+
"q": "latest",
7273
"run-sequence": "latest",
7374
"sorcery": "latest",
7475
"through2": "latest",

scripts/types/ambient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare module "gulp-insert" {
1010
export function append(text: string | Buffer): NodeJS.ReadWriteStream;
1111
export function prepend(text: string | Buffer): NodeJS.ReadWriteStream;
1212
export function wrap(text: string | Buffer, tail: string | Buffer): NodeJS.ReadWriteStream;
13-
export function transform(cb: (contents: string, file: {path: string}) => string): NodeJS.ReadWriteStream; // file is a vinyl file
13+
export function transform(cb: (contents: string, file: {path: string, relative: string}) => string): NodeJS.ReadWriteStream; // file is a vinyl file
1414
}
1515

1616
declare module "into-stream" {

src/harness/harness.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ namespace Harness {
15691569

15701570
/** Support class for baseline files */
15711571
export namespace Baseline {
1572+
const NoContent = "<no content>";
15721573

15731574
export interface BaselineOptions {
15741575
Subfolder?: string;
@@ -1635,14 +1636,6 @@ namespace Harness {
16351636
throw new Error("The generated content was \"undefined\". Return \"null\" if no baselining is required.\"");
16361637
}
16371638

1638-
// Store the content in the 'local' folder so we
1639-
// can accept it later (manually)
1640-
/* tslint:disable:no-null-keyword */
1641-
if (actual !== null) {
1642-
/* tslint:enable:no-null-keyword */
1643-
IO.writeFile(actualFileName, actual);
1644-
}
1645-
16461639
return actual;
16471640
}
16481641

@@ -1659,7 +1652,7 @@ namespace Harness {
16591652
/* tslint:disable:no-null-keyword */
16601653
if (actual === null) {
16611654
/* tslint:enable:no-null-keyword */
1662-
actual = "<no content>";
1655+
actual = NoContent;
16631656
}
16641657

16651658
let expected = "<no content>";
@@ -1672,7 +1665,13 @@ namespace Harness {
16721665

16731666
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) {
16741667
const encoded_actual = Utils.encodeString(actual);
1675-
if (expected != encoded_actual) {
1668+
if (expected !== encoded_actual) {
1669+
if (actual === NoContent) {
1670+
IO.writeFile(relativeFileName + ".delete", "");
1671+
}
1672+
else {
1673+
IO.writeFile(relativeFileName, actual);
1674+
}
16761675
// Overwrite & issue error
16771676
const errMsg = "The baseline file " + relativeFileName + " has changed.";
16781677
throw new Error(errMsg);

0 commit comments

Comments
 (0)