2015-03-04 09:12:06 +03:00
|
|
|
/// <reference path="..\src\compiler\sys.ts"/>
|
|
|
|
/// <reference path="..\src\compiler\types.ts"/>
|
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
namespace perftest {
|
2015-03-04 09:12:06 +03:00
|
|
|
interface IOLog {
|
|
|
|
resolvePath: ts.Map<string>;
|
|
|
|
fileNames: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IO {
|
|
|
|
getOut(): string;
|
|
|
|
}
|
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
export const readFile = ts.sys.readFile;
|
|
|
|
const writeFile = ts.sys.writeFile;
|
|
|
|
export const write = ts.sys.write;
|
|
|
|
const resolvePath = ts.sys.resolvePath;
|
|
|
|
export const getExecutingFilePath = ts.sys.getExecutingFilePath;
|
|
|
|
export const getCurrentDirectory = ts.sys.getCurrentDirectory;
|
|
|
|
// const exit = ts.sys.exit;
|
2015-03-04 09:12:06 +03:00
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
const args = ts.sys.args;
|
2015-03-04 09:12:06 +03:00
|
|
|
|
|
|
|
// augment sys so first ts.executeCommandLine call will be finish silently
|
|
|
|
ts.sys.write = (s: string) => { };
|
|
|
|
ts.sys.exit = (code: number) => { };
|
2016-07-27 17:26:28 +03:00
|
|
|
ts.sys.args = [];
|
2015-03-04 09:12:06 +03:00
|
|
|
|
|
|
|
export function restoreSys() {
|
|
|
|
ts.sys.args = args;
|
|
|
|
ts.sys.write = write;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hasLogIOFlag() {
|
|
|
|
return args.length > 2 && args[0] === "--logio";
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getArgsWithoutLogIOFlag() {
|
|
|
|
return args.slice(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getArgsWithoutIOLogFile() {
|
|
|
|
return args.slice(1);
|
|
|
|
}
|
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
const resolvePathLog: ts.Map<string> = {};
|
|
|
|
|
2015-03-04 09:12:06 +03:00
|
|
|
export function interceptIO() {
|
|
|
|
ts.sys.resolvePath = (s) => {
|
2016-07-27 17:26:28 +03:00
|
|
|
const result = resolvePath(s);
|
2015-03-04 09:12:06 +03:00
|
|
|
resolvePathLog[s] = result;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function writeIOLog(fileNames: string[]) {
|
2016-07-27 17:26:28 +03:00
|
|
|
const path = args[1];
|
|
|
|
const log: IOLog = {
|
2015-03-04 09:12:06 +03:00
|
|
|
fileNames: fileNames,
|
|
|
|
resolvePath: resolvePathLog
|
|
|
|
};
|
|
|
|
|
|
|
|
writeFile(path, JSON.stringify(log));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function prepare(): IO {
|
2016-07-27 17:26:28 +03:00
|
|
|
const log = <IOLog>JSON.parse(readFile(args[0]));
|
|
|
|
|
|
|
|
const files: ts.Map<string> = {};
|
|
|
|
log.fileNames.forEach(f => { files[f] = readFile(f); });
|
2015-03-04 09:12:06 +03:00
|
|
|
|
|
|
|
ts.sys.createDirectory = (s: string) => { };
|
|
|
|
ts.sys.directoryExists = (s: string) => true;
|
|
|
|
ts.sys.fileExists = (s: string) => true;
|
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
const currentDirectory = ts.sys.getCurrentDirectory();
|
2015-03-04 09:12:06 +03:00
|
|
|
ts.sys.getCurrentDirectory = () => currentDirectory;
|
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
const executingFilePath = ts.sys.getExecutingFilePath();
|
2015-03-04 09:12:06 +03:00
|
|
|
ts.sys.getExecutingFilePath = () => executingFilePath;
|
|
|
|
|
|
|
|
ts.sys.readFile = (s: string) => {
|
|
|
|
return files[s];
|
2016-07-27 17:26:28 +03:00
|
|
|
};
|
2015-03-04 09:12:06 +03:00
|
|
|
|
|
|
|
ts.sys.resolvePath = (s: string) => {
|
2016-07-27 17:26:28 +03:00
|
|
|
const path = log.resolvePath[s];
|
2015-03-04 09:12:06 +03:00
|
|
|
if (!path) {
|
|
|
|
throw new Error("Unexpected path '" + s + "'");
|
|
|
|
}
|
2016-07-27 17:26:28 +03:00
|
|
|
return path;
|
|
|
|
};
|
2015-03-04 09:12:06 +03:00
|
|
|
|
|
|
|
ts.sys.writeFile = (path: string, data: string) => { };
|
|
|
|
|
2016-07-27 17:26:28 +03:00
|
|
|
let out = "";
|
2015-03-04 09:12:06 +03:00
|
|
|
|
|
|
|
ts.sys.write = (s: string) => { out += s; };
|
|
|
|
|
|
|
|
return {
|
|
|
|
getOut: () => out,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|