Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Logging and post-build commands
Browse files Browse the repository at this point in the history
* Error logging for exceptions during build cleanup
* Compacted log message filter regexes
* Moved pre-build command after initialization of the output folder in case this command somehow wants to operate on it somehow
* Better error message handling when post-build command fails
* Forwarding post-build command error
  • Loading branch information
elektronikworkshop authored and adiazulay committed Jan 19, 2021
1 parent 7c1104c commit d3bcf6e
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ export class ArduinoApp {
})
.catch((reason) => {
this._building = false;
// TODO EW, 2020-02-19: Report unhandled error (Logger?)
logger.notifyUserError("ArduinoApp.build",
reason,
`Unhandled exception when cleaning up build (${buildMode}).`);
return false;
});
}
Expand Down Expand Up @@ -328,13 +330,6 @@ export class ArduinoApp {
arduinoChannel.show();
arduinoChannel.start(`${buildMode} sketch '${dc.sketch}'`);

// TODO EW: What should we do with pre-/post build commands when running
// analysis? Some could use it to generate/manipulate code which could
// be a prerequisite for a successful build
if (!await this.runPrePostBuildCommand(dc, "pre")) {
return false;
}

if ((buildDir || dc.output) && compile) {
const outputPath = path.resolve(ArduinoWorkspace.rootPath, buildDir || dc.output);
const dirPath = path.dirname(outputPath);
Expand All @@ -356,6 +351,13 @@ export class ArduinoApp {
arduinoChannel.warning(msg);
}

// TODO EW: What should we do with pre-/post build commands when running
// analysis? Some could use it to generate/manipulate code which could
// be a prerequisite for a successful build
if (!await this.runPrePostBuildCommand(dc, "pre")) {
return false;
}

// stop serial monitor when everything is prepared and good
// what makes restoring of its previous state easier
if (buildMode === BuildMode.Upload || buildMode === BuildMode.UploadProgrammer) {
Expand All @@ -365,10 +367,10 @@ export class ArduinoApp {

// Push sketch as last argument
args.push(path.join(ArduinoWorkspace.rootPath, dc.sketch));

const cleanup = async (result: "ok" | "error") => {
let ret = true;
if (result === "ok") {
await this.runPrePostBuildCommand(dc, "post");
ret = await this.runPrePostBuildCommand(dc, "post");
}
await cocopa.conclude();
if (buildMode === BuildMode.Upload || buildMode === BuildMode.UploadProgrammer) {
Expand All @@ -377,6 +379,7 @@ export class ArduinoApp {
await SerialMonitor.getInstance().openSerialMonitor();
}
}
return ret;
}
const stdoutcb = (line: string) => {
if (cocopa.callback) {
Expand All @@ -396,17 +399,13 @@ export class ArduinoApp {
line = `${line}${os.EOL}`;
}
if (!verbose) {
// Don't spill log with spurious info from the backend
// This list could be fetched from a config file to
// accommodate messages of unknown board packages, newer
// backend revisions etc.
// Don't spill log with spurious info from the backend. This
// list could be fetched from a config file to accommodate
// messages of unknown board packages, newer backend revisions
const filters = [
/^Picked\sup\sJAVA_TOOL_OPTIONS:\s+/,
/^\d+\d+-\d+-\d+T\d+:\d+:\d+.\d+Z\sINFO\s/,
/^\d+\d+-\d+-\d+T\d+:\d+:\d+.\d+Z\sWARN\s/,
/^DEBUG\s+/,
/^TRACE\s+/,
/^INFO\s+/,
/^\d+\d+-\d+-\d+T\d+:\d+:\d+.\d+Z\s(?:INFO|WARN)\s/,
/^(?:DEBUG|TRACE|INFO)\s+/,
];
for (const f of filters) {
if (line.match(f)) {
Expand All @@ -423,9 +422,11 @@ export class ArduinoApp {
undefined,
{ stdout: stdoutcb, stderr: stderrcb },
).then(async () => {
await cleanup("ok");
arduinoChannel.end(`${buildMode} sketch '${dc.sketch}'${os.EOL}`);
return true;
const ret = await cleanup("ok");
if (ret) {
arduinoChannel.end(`${buildMode} sketch '${dc.sketch}'${os.EOL}`);
}
return ret;
}, async (reason) => {
await cleanup("error");
const msg = reason.code
Expand Down

0 comments on commit d3bcf6e

Please sign in to comment.