Skip to content

Commit

Permalink
fix: use CLI config path for debug command
Browse files Browse the repository at this point in the history
If the `directories.data` is not the default, debug metadata generation
can fail with false positive missing platform error.

Ref: arduino/arduino-ide#1911

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta authored and kittaakos committed Mar 27, 2023
1 parent 9c296c4 commit 25f018e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import { promises as fs } from 'fs';
import { homedir } from 'os';
import { spawn } from 'child_process';
import deepEqual from 'deep-equal';
import WebRequest from 'web-request';
Expand Down Expand Up @@ -44,6 +45,10 @@ interface DebugConfig {
* If not defined, it falls back to `sketchPath/.vscode/launch.json`.
*/
readonly configPath?: string;
/**
* Absolute path to the `arduino-cli.yaml` file. If not specified, it falls back to `~/.arduinoIDE/arduino-cli.yaml`.
*/
readonly cliConfigPath?: string;
}

interface DebugInfo {
Expand Down Expand Up @@ -133,10 +138,15 @@ async function exec(command: string, args: string[]): Promise<{ stdout: string,
});
}

function resolveCliConfigPath(config: DebugConfig): string {
return config.cliConfigPath ?? path.join(homedir(), '.arduinoIDE', 'arduino-cli.yaml');
}

async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boolean> {
const cliConfigPath = resolveCliConfigPath(config);
let info: DebugInfo | undefined = undefined;
try {
const args = ['debug', '-I', '-b', config.board.fqbn, config.sketchPath, '--format', 'json'];
const args = ['debug', '-I', '-b', config.board.fqbn, config.sketchPath, '--format', 'json', '--config-file', cliConfigPath];
const { stdout, stderr } = await exec(config?.cliPath || '.', args);
if (!stdout && stderr) {
throw new Error(stderr);
Expand Down

0 comments on commit 25f018e

Please sign in to comment.