From 7b2579964ce8fcbdf65f66b30bb872b642abb1b1 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 19 Jan 2015 15:39:21 -0800 Subject: [PATCH 1/2] Automatic bisecting script --- scripts/bisect-test.ts | 48 ++++++++++++++++++++++++++++++++++++++++++ scripts/bisect.cmd | 30 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 scripts/bisect-test.ts create mode 100644 scripts/bisect.cmd diff --git a/scripts/bisect-test.ts b/scripts/bisect-test.ts new file mode 100644 index 00000000000..6ad53991462 --- /dev/null +++ b/scripts/bisect-test.ts @@ -0,0 +1,48 @@ +/// + +import cp = require('child_process'); +import fs = require('fs'); + +var args = process.argv.slice(2); + +var jake = cp.exec('jake clean local', () => void 0); +jake.on('close', code => { + if (code === 0) { + // See what we're being asked to do + if (args[1] === 'compiles' || args[1] === '!compiles') { + var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); + tsc.on('close', tscCode => { + if ((tscCode === 0) === (args[1] === 'compiles')) { + console.log('Good'); + process.exit(0); // Good + } else { + console.log('Bad'); + process.exit(1); // Bad + } + }); + } else if (args[1] === 'emits' || args[1] === '!emits') { + var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); + tsc.on('close', tscCode => { + fs.readFile(args[2], 'utf-8', (err, data) => { + var doesContains = data.indexOf(args[3]) >= 0; + if (doesContains === (args[1] === 'emits')) { + console.log('Good'); + process.exit(0); // Good + } else { + console.log('Bad'); + process.exit(1); // Bad + } + }); + }); + } else { + console.log('Unknown command line arguments.'); + console.log('Usage (compile errors): git bisect run scripts\bisect.js "foo.ts --module amd" compiles'); + console.log('Usage (emit check): git bisect run scripts\bisect.js bar.ts emits bar.js "_this = this"'); + process.exit(-1); + } + } else { + // Build failed + process.exit(125); // bisect skip + } +}); + \ No newline at end of file diff --git a/scripts/bisect.cmd b/scripts/bisect.cmd new file mode 100644 index 00000000000..148722665d4 --- /dev/null +++ b/scripts/bisect.cmd @@ -0,0 +1,30 @@ +echo off +IF NOT EXIST scripts\bisect.cmd GOTO :wrongdir +IF "%1" == "" GOTO :usage +IF "%1" == "GO" GOTO :run +GOTO :copy + +:usage +echo Usage: bisect GoodCommit BadCommit test.ts compiles +echo Usage: bisect GoodCommit BadCommit test.ts emits test.js "var x = 3" +GOTO :eof + +:copy +copy scripts\bisect.cmd scripts\bisect-fresh.cmd +scripts\bisect-fresh GO %* +GOTO :eof + +:run +call jake local +node built/local/tsc.js scripts/bisect-test.ts --module commonjs +git bisect start %2 %3 +git bisect run node scripts/bisect-test.js %4 %5 %6 %7 +del scripts\bisect-test.js +del scripts\bisect-fresh.cmd +GOTO :eof + +:wrongdir +@echo Run this file from the repo folder, not the scripts folder +GOTO :eof + +:eof \ No newline at end of file From 13ba516a7aba85ae50de905a56d680241bf36717 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 19 Jan 2015 21:37:21 -0800 Subject: [PATCH 2/2] Address CR feedback; refactor out tsc invocation --- scripts/bisect-test.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/bisect-test.ts b/scripts/bisect-test.ts index 6ad53991462..93a516bc899 100644 --- a/scripts/bisect-test.ts +++ b/scripts/bisect-test.ts @@ -3,16 +3,23 @@ import cp = require('child_process'); import fs = require('fs'); +// Slice off 'node bisect-test.js' from the commandline args var args = process.argv.slice(2); +function tsc(tscArgs: string, onExit: (exitCode: number) => void) { + var tsc = cp.exec('node built/local/tsc.js ' + tscArgs,() => void 0); + tsc.on('close', tscExitCode => { + onExit(tscExitCode); + }); +} + var jake = cp.exec('jake clean local', () => void 0); -jake.on('close', code => { - if (code === 0) { +jake.on('close', jakeExitCode => { + if (jakeExitCode === 0) { // See what we're being asked to do if (args[1] === 'compiles' || args[1] === '!compiles') { - var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); - tsc.on('close', tscCode => { - if ((tscCode === 0) === (args[1] === 'compiles')) { + tsc(args[0], tscExitCode => { + if ((tscExitCode === 0) === (args[1] === 'compiles')) { console.log('Good'); process.exit(0); // Good } else { @@ -21,8 +28,7 @@ jake.on('close', code => { } }); } else if (args[1] === 'emits' || args[1] === '!emits') { - var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); - tsc.on('close', tscCode => { + tsc(args[0], tscExitCode => { fs.readFile(args[2], 'utf-8', (err, data) => { var doesContains = data.indexOf(args[3]) >= 0; if (doesContains === (args[1] === 'emits')) { @@ -38,10 +44,12 @@ jake.on('close', code => { console.log('Unknown command line arguments.'); console.log('Usage (compile errors): git bisect run scripts\bisect.js "foo.ts --module amd" compiles'); console.log('Usage (emit check): git bisect run scripts\bisect.js bar.ts emits bar.js "_this = this"'); + // Aborts the 'git bisect run' process process.exit(-1); } } else { - // Build failed + // Compiler build failed; skip this commit + console.log('Skip'); process.exit(125); // bisect skip } });