Commit 8e043bcd authored by Timon Stampfli's avatar Timon Stampfli

improved log messages

parent baf594c0
Pipeline #5675 passed with stages
in 41 seconds
......@@ -125,7 +125,7 @@ export async function activate(context: vscode.ExtensionContext) {
// await downloadHelperBinary(store);
await downloadCompilerBundle(store);
console.log("SOICode has been loaded");
store.logInfo("soicode extension", "SOICode has been loaded");
}
async function debugSolutionOnSample() {
......
......@@ -15,7 +15,10 @@ export function getHelperPath(store: Store): string {
export async function downloadCompilerBundle(store: Store) {
return new Promise(async resolve => {
let platform = determinePlatform();
console.log("Fetching Helper binary for platform " + platform);
store.logInfo(
"Download Compiler Bundle",
"Fetching Helper binary for platform " + platform
);
let flavor = "soiheaders";
let url = `https://blob.dolansoft.org/soicode/compilerbundle-${platform}-${flavor}.tar.xz`;
let targetDir = path.join(store.soicodeExtensionDataPath, "bundle", flavor);
......@@ -31,21 +34,14 @@ export async function downloadCompilerBundle(store: Store) {
stdout += chunk;
});
proc.on("exit", (code, signal) => {
console.log(
"fetching the compilerbundle finished, errorcode: " +
code +
" stdout: " +
stdout
);
const msg = `fetching the compilerbundle finished, errorcode: ${code} stdout: '${stdout}'`;
console.log(msg);
store.logInfo("Download Compiler Bundle", msg);
if (code !== 0) {
vscode.window.showErrorMessage(
"Error fetching the compilerbundle, errorcode: " +
code +
" stdout: " +
stdout
);
const msg = `Error fetching the compilerbundle, errorcode: ${code} stdout: '${stdout}'`;
vscode.window.showErrorMessage(msg);
}
resolve();
});
resolve();
});
}
......@@ -77,9 +77,9 @@ export class HelperBinaryResultReceiver {
let parsed = checkServerResponseTyped(JSON.parse(res));
if (parsed === null) {
this.store.handleError(
"Downloading dependencies",
"Downloaded a invalid compiler bundle",
Error("invalid package received")
"run task result handler",
"got unparsable result when executing a task",
Error("invalid result received")
);
}
let [binarypath, samplename, result] = parsed;
......
......@@ -20,6 +20,21 @@ import {
} from "./storeHelper";
import { selectSample } from "./sample";
class Timer extends vscode.Disposable {
timer: Promise<{}>;
timeout?: NodeJS.Timeout;
constructor(ms: number) {
super(() => {
if (this.timeout !== undefined) {
clearTimeout(this.timeout);
}
});
this.timer = new Promise(resolve => {
this.timeout = setTimeout(resolve, ms);
});
}
}
export class Runner {
store: Store;
port: Number;
......@@ -30,92 +45,121 @@ export class Runner {
}
async compile(this: Runner, taskname: string): Promise<"Success" | "Failed"> {
return new Promise(async resolve => {
let workspace = getWorkspaceOrShowError(this.store).workspaceDir;
let soitaskFiles = getSoitaskFilesOfFulltaskOrError(this.store, taskname);
this.store.logInfo("compiler", `starting the compilation of ${taskname}`);
const workspace = getWorkspaceOrShowError(this.store).workspaceDir;
const soitaskFiles = getSoitaskFilesOfFulltaskOrError(this.store, taskname);
let compilerPath = getCompilerPath(this.store);
const compilerPath = getCompilerPath(this.store);
try {
await fs.readFile(compilerPath);
} catch (err) {
vscode.window.showErrorMessage(
"Compiler executable not found at expected path"
let finished: vscode.Disposable[] = [];
let timer = new Timer(10000);
finished.push(timer);
const cleanup = () => {
for (let d of finished) {
d.dispose();
}
};
try {
await fs.readFile(compilerPath);
} catch (err) {
vscode.window.showErrorMessage(
"Compiler executable not found at expected path"
);
this.store.logError(
"compilation",
`file at compilerpath '${compilerPath}' not found`,
err
);
cleanup();
return "Failed";
}
try {
await fs.unlink(soitaskFiles.binaryFsPath);
} catch (err) {
if (err.code === "ENOENT") {
this.store.logInfo(
"compilation",
`compiled binary '${soitaskFiles.binaryFsPath}' not found`,
err
);
this.store.logError(
} else {
cleanup();
this.store.handleError(
"compilation",
`file at compilerpath '${compilerPath}' not found`,
`deleting binary '${soitaskFiles.binaryFsPath}' failed`,
err
);
resolve("Failed");
}
let compileTaskDefinition = {
label: "build " + taskname + " development",
// "command": "clang++",
// "args": ,
type: "process",
group: {
kind: "build",
isDefault: true
}
};
let headerAsFlag = (path: string) => (path === "" ? [] : ["-I", path]);
// Todo: allow customizable flags
let execute = new vscode.ProcessExecution(
compilerPath,
[
soitaskFiles.solutionWorkspacePath!,
...getCompilationFlags(this.store),
...headerAsFlag(getCppHeaderPath(this.store)),
...headerAsFlag(getSoiHeaderPath(this.store)),
"-o",
taskname
],
{
cwd: workspace
}
);
}
try {
await fs.unlink(soitaskFiles.binaryFsPath);
} catch (err) {
if (err.code === "ENOENT") {
this.store.logInfo(
"compilation",
`compiled binary '${compilerPath}' not found`,
err
);
} else {
this.store.handleError(
"compilation",
`deleting binary '${soitaskFiles.binaryFsPath}' failed`,
err
);
}
const compileTaskDefinition = {
label: "build " + taskname + " development",
// "command": "clang++",
// "args": ,
type: "process",
group: {
kind: "build",
isDefault: true
}
};
// let compileTask = new vscode.Task(compileTaskDefinition, vscode.TaskScope.Workspace, "compile" + taskname, "c++", execute, "$gcc");
let compileTask = new vscode.Task(
compileTaskDefinition,
vscode.TaskScope.Workspace,
"compile" + taskname,
"soic",
execute
);
try {
await vscode.tasks.executeTask(compileTask);
} catch (err) {
this.store.logError("compilation", "executing task failed", err);
resolve("Failed");
const headerAsFlag = (path: string) => (path === "" ? [] : ["-I", path]);
// Todo: allow customizable flags
const execute = new vscode.ProcessExecution(
compilerPath,
[
soitaskFiles.solutionWorkspacePath!,
...getCompilationFlags(this.store),
...headerAsFlag(getCppHeaderPath(this.store)),
...headerAsFlag(getSoiHeaderPath(this.store)),
"-o",
taskname
],
{
cwd: workspace
}
);
// let compileTask = new vscode.Task(compileTaskDefinition, vscode.TaskScope.Workspace, "compile" + taskname, "c++", execute, "$gcc");
let compileTask = new vscode.Task(
compileTaskDefinition,
vscode.TaskScope.Workspace,
"compile" + taskname,
"soic",
execute
);
try {
let compileTaskExec = vscode.tasks.executeTask(compileTask);
compileTaskExec.then(e => {
this.store.logInfo("compiler", `finished vscode.task.executeTask`);
});
finished.push(
new vscode.Disposable(() => {
this.store.logError(
"compiler",
"aborted compilation, killing process"
);
compileTaskExec.then(e => {
e.terminate();
});
})
);
} catch (err) {
this.store.logError("compilation", "executing task failed", err);
cleanup();
return "Failed";
}
finished.push(
vscode.tasks.onDidEndTask(taskEnded => {
if (taskEnded.execution.task.name === "compile" + taskname) {
try {
fs.readFile(soitaskFiles.binaryFsPath).then(() => {
resolve("Success");
cleanup();
return "Success";
});
} catch (err) {
this.store.logError(
......@@ -124,17 +168,38 @@ export class Runner {
err
);
if (err.code !== "EEXIST") {
resolve("Failed");
cleanup();
return "Failed";
}
}
}
});
})
);
finished.push(
vscode.tasks.onDidStartTaskProcess(evtStartProc => {
if (evtStartProc.execution.task.name === compileTask.name) {
this.store.logInfo(
"compiler",
`compiling started successfully with pid '${evtStartProc.processId}'`
);
}
})
);
finished.push(
vscode.tasks.onDidEndTaskProcess(evtEndProc => {
if (evtEndProc.execution.task.name === compileTask.name) {
this.store.logInfo(
"compiler",
`compiling ended successfully with exit code '${evtEndProc.exitCode}'`
);
}
})
);
setTimeout(() => {
this.store.logError("compilation", `timed out compilation`);
resolve("Failed");
}, 10000);
});
await timer.timer;
this.store.logError("compilation", `timed out compilation`);
cleanup();
return "Failed";
}
async askAndCompile(
......
......@@ -44,7 +44,9 @@ export class Store {
}
handleError(this: Store, location: string, info: string, err: Error): never {
this.channel.appendLine(`#### Error ${location} ####`);
this.channel.appendLine(
`#### [${new Date().toISOString()}] Error ${location} ####`
);
this.channel.appendLine(info);
this.channel.appendLine("error name:");
this.channel.appendLine(err.name);
......@@ -58,7 +60,9 @@ export class Store {
throw err;
}
logInfo(this: Store, location: string, info: string, err?: Error) {
this.channel.appendLine(`#### info at [${location}] ####`);
this.channel.appendLine(
`#### [${new Date().toISOString()}] info at [${location}] ####`
);
this.channel.appendLine(info);
if (err !== undefined) {
this.channel.appendLine(err.name);
......@@ -71,7 +75,9 @@ export class Store {
}
}
logError(this: Store, location: string, info: string, err?: Error) {
this.channel.appendLine(`#### error at [${location}] ####`);
this.channel.appendLine(
`#### [${new Date().toISOString()}] error at [${location}] ####`
);
this.channel.appendLine(info);
if (err !== undefined) {
this.channel.appendLine(err.name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment