Skip to content

Commit 2271d85

Browse files
committed
add: Create output channel for stdout and stderr
1 parent ba8d64b commit 2271d85

4 files changed

Lines changed: 64 additions & 56 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Debug Solana programs easily",
55
"publisher": "limechain",
66
"icon": "images/logo.png",
7-
"version": "0.1.8",
7+
"version": "0.1.9",
88
"galleryBanner.color": {
99
"color": "#21214c",
1010
"theme": "dark"

src/build/sbpfV1BuildStrategy.js

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const BaseBuildStrategy = require('./baseBuildStrategy');
22
const { getDebuggerSession } = require('../managers/sessionManager');
33
const vscode = require('vscode');
44
const fs = require('fs');
5-
const { exec } = require('child_process');
5+
const { spawn } = require('child_process');
66
const BuildCommands = require('./buildCommands');
77
const gimletConfigManager = require('../config');
88
const { safeReadDir } = require('../projectStructure');
@@ -32,59 +32,69 @@ class SbpfV1BuildStrategy extends BaseBuildStrategy {
3232

3333
async build(progress) {
3434
const buildCmd = this.getBuildCommand();
35-
console.log(` Running command: ${buildCmd}`);
36-
progress.report({ increment: 1, message: 'Building you program!' });
35+
progress.report({ increment: 1, message: 'Building your program!' });
3736

3837
return new Promise((resolve) => {
39-
exec(
38+
const outputChannel = vscode.window.createOutputChannel('Gimlet');
39+
outputChannel.show(true);
40+
outputChannel.appendLine(`Running build command: ${buildCmd}\n`);
41+
42+
const buildProcess = spawn(
4043
buildCmd,
41-
{ cwd: this.workspaceFolder },
42-
async (err, stdout, stderr) => {
43-
if (err) {
44-
vscode.window.showErrorMessage(
45-
`Build error: ${stderr}`
46-
);
47-
resolve();
48-
return;
49-
}
44+
{
45+
cwd: this.workspaceFolder,
46+
shell: true
47+
}
48+
)
5049

51-
progress.report({ increment: 2, message: 'Setting gimlet internals!' });
52-
// Load the depsPath from gimlet config
53-
const { depsPath } = await gimletConfigManager.resolveGimletConfig();
54-
this.depsPath = depsPath;
50+
buildProcess.stdout.on('data', (data) => {
51+
outputChannel.append(data.toString());
52+
});
5553

56-
// Holds all the compiled programs in target/deploy
57-
let newFiles = await safeReadDir(this.depsPath);
58-
if (!newFiles) {
59-
resolve();
60-
return;
61-
}
54+
buildProcess.stderr.on('data', (data) => {
55+
outputChannel.append(data.toString());
56+
});
57+
58+
buildProcess.on('close', async (code) => {
59+
if (code !== 0) {
60+
throw new Error(`Build failed with exit code ${code}`);
61+
}
6262

63-
// Hash all the compiled programs
64-
for (let programCompiledFile of newFiles) {
65-
if (!programCompiledFile.endsWith('.so')) {
66-
continue;
67-
}
68-
69-
const debugBinaryPath = `${this.depsPath}/${programCompiledFile.replace('.so', '.debug')}`;
70-
const bpfCompiledPath = `${this.depsPath}/${programCompiledFile}`;
71-
72-
this.hashProgram(programCompiledFile);
73-
74-
this.debuggerSession.executablesPaths[programCompiledFile] = {
75-
debugBinary: debugBinaryPath,
76-
bpfCompiledPath: bpfCompiledPath
77-
};
63+
// Load the depsPath from gimlet config
64+
const { depsPath } = await gimletConfigManager.resolveGimletConfig();
65+
this.depsPath = depsPath;
66+
67+
// Holds all the compiled programs in target/deploy
68+
let newFiles = await safeReadDir(this.depsPath);
69+
if (!newFiles) {
70+
resolve();
71+
return;
72+
}
73+
74+
// Hash all the compiled programs
75+
for (let programCompiledFile of newFiles) {
76+
if (!programCompiledFile.endsWith('.so')) {
77+
continue;
7878
}
7979

80-
if (progress)
81-
progress.report({
82-
increment: 3,
83-
message: 'Setting up debugger...',
84-
});
85-
resolve(true);
80+
const debugBinaryPath = `${this.depsPath}/${programCompiledFile.replace('.so', '.debug')}`;
81+
const bpfCompiledPath = `${this.depsPath}/${programCompiledFile}`;
82+
83+
this.hashProgram(programCompiledFile);
84+
85+
this.debuggerSession.executablesPaths[programCompiledFile] = {
86+
debugBinary: debugBinaryPath,
87+
bpfCompiledPath: bpfCompiledPath
88+
};
8689
}
87-
);
90+
91+
if (progress)
92+
progress.report({
93+
increment: 3,
94+
message: 'Setting up debugger...',
95+
});
96+
resolve(true);
97+
});
8898
});
8999
}
90100

src/managers/debugConfigManager.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ class DebugConfigManager {
6666

6767
// The test executor for TS anchor tests
6868
async spawnAnchorTestProcess() {
69-
const logFilePath = `${globalState.globalWorkspaceFolder}/.gimlet.log`;
70-
const logStream = fs.createWriteStream(logFilePath, { flags: 'w' });
69+
const outputChannel = vscode.window.createOutputChannel('Gimlet');
70+
outputChannel.show(true);
71+
outputChannel.appendLine(`Running build command: anchor test\n`);
7172

7273
return new Promise((resolve, reject) => {
7374
// Get the active debug console
@@ -82,15 +83,12 @@ class DebugConfigManager {
8283
});
8384

8485
anchorProcess.stderr.on('data', (data) => {
85-
const output = data.toString();
86-
const formatted = `[${new Date().toISOString()}] [stderr] ${output}`;
87-
logStream.write(formatted);
86+
outputChannel.append(data.toString());
87+
8888
});
8989

9090
anchorProcess.stdout.on('data', (data) => {
91-
const output = data.toString();
92-
const formatted = `[${new Date().toISOString()}] [stdout] ${output}`;
93-
logStream.write(formatted);
91+
outputChannel.append(data.toString());
9492
});
9593

9694
anchorProcess.on('error', (error) => {

0 commit comments

Comments
 (0)