Skip to content

Commit 8760be1

Browse files
author
Akos Kitta
committed
fix: programmer is optional for debug -I check
Ref: arduino/arduino-ide#2371 Signed-off-by: Akos Kitta <[email protected]>
1 parent 666dd48 commit 8760be1

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/debug.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ async function createLaunchConfig(
142142
params: StartDebugParams
143143
): Promise<ArduinoDebugLaunchConfig> {
144144
const { programmer, board } = params;
145-
if (!programmer) {
146-
throw new Error('Missing programmer');
147-
}
148145
const { file, args } = buildDebugInfoArgs(params);
149146
const [stdout, customConfigs] = await Promise.all([
150147
withProgress(
@@ -206,8 +203,14 @@ async function parseRawDebugInfo(
206203
return config;
207204
}
208205

209-
function createConfigId(board: BoardIdentifier, programmer: string): string {
206+
function createConfigId(
207+
board: BoardIdentifier,
208+
programmer: string | undefined
209+
): string {
210210
const fqbn = new FQBN(board.fqbn);
211+
if (!programmer) {
212+
return fqbn.toString();
213+
}
211214
if (hasConfigOptions(fqbn)) {
212215
// if already has config options, append the programmer as an ordinary custom board config option
213216
return `${fqbn.toString()},programmer=${programmer}`;
@@ -294,7 +297,7 @@ function resolveCliConfigPath(
294297

295298
async function mergeLaunchConfig(
296299
board: BoardIdentifier,
297-
programmer: string,
300+
programmer: string | undefined,
298301
debugInfo: DebugInfo & Executable,
299302
customConfigs: CustomDebugConfigs
300303
): Promise<ArduinoDebugLaunchConfig> {
@@ -326,7 +329,10 @@ async function mergeLaunchConfig(
326329
return launchConfig;
327330
}
328331

329-
function createName(board: BoardIdentifier, programmer: string): string {
332+
function createName(
333+
board: BoardIdentifier,
334+
programmer: string | undefined
335+
): string {
330336
if (!board.name) {
331337
const configId = createConfigId(board, programmer);
332338
return `Arduino (${configId})`;
@@ -336,9 +342,9 @@ function createName(board: BoardIdentifier, programmer: string): string {
336342
const options = Object.entries(fqbn.options)
337343
.map(([key, value]) => `${key}=${value}`)
338344
.join(',');
339-
return `${board.name} (${options},${programmer})`;
345+
return `${board.name} (${options}${programmer ? `,${programmer}` : ''})`;
340346
}
341-
return `${board.name} (${programmer})`;
347+
return `${board.name}${programmer ? ` (${programmer})` : ''}`;
342348
}
343349

344350
function replaceValue(

src/test/suite/debug.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,21 @@ describe('debug', () => {
363363
const actual = createConfigId({ fqbn: 'a:b:c' }, 'p');
364364
assert.strictEqual(actual, 'a:b:c:programmer=p');
365365
});
366+
367+
it('should create the configuration ID when the FQBN has no custom board options (no programmer)', () => {
368+
const actual = createConfigId({ fqbn: 'a:b:c' }, undefined);
369+
assert.strictEqual(actual, 'a:b:c');
370+
});
371+
366372
it('should create the configuration ID when the FQBN has custom board options', () => {
367373
const actual = createConfigId({ fqbn: 'a:b:c:o1=v1' }, 'p');
368374
assert.strictEqual(actual, 'a:b:c:o1=v1,programmer=p');
369375
});
376+
377+
it('should create the configuration ID when the FQBN has custom board options (no programmer)', () => {
378+
const actual = createConfigId({ fqbn: 'a:b:c:o1=v1' }, undefined);
379+
assert.strictEqual(actual, 'a:b:c:o1=v1');
380+
});
370381
});
371382
describe('createName', () => {
372383
it('should use the generated config ID if the board name is absent', () => {
@@ -386,19 +397,37 @@ describe('debug', () => {
386397
);
387398
});
388399

400+
it('should use the generated config ID with the custom board options if the board name is absent (no programmer)', () => {
401+
const board = { fqbn: 'a:b:c:UsbMode=default' };
402+
const actual = createName(board, undefined);
403+
assert.strictEqual(actual, 'Arduino (a:b:c:UsbMode=default)');
404+
});
405+
389406
it('should use the board name', () => {
390407
const board = { fqbn: 'a:b:c', name: 'board name' };
391408
const programmer = 'p1';
392409
const actual = createName(board, programmer);
393410
assert.strictEqual(actual, 'board name (p1)');
394411
});
395412

413+
it('should use the board name (no programmer)', () => {
414+
const board = { fqbn: 'a:b:c', name: 'board name' };
415+
const actual = createName(board, undefined);
416+
assert.strictEqual(actual, 'board name');
417+
});
418+
396419
it('should use the board name and all custom board options', () => {
397420
const board = { fqbn: 'a:b:c:UsbMode=default', name: 'board name' };
398421
const programmer = 'p1';
399422
const actual = createName(board, programmer);
400423
assert.strictEqual(actual, 'board name (UsbMode=default,p1)');
401424
});
425+
426+
it('should use the board name and all custom board options (no programmer)', () => {
427+
const board = { fqbn: 'a:b:c:UsbMode=default', name: 'board name' };
428+
const actual = createName(board, undefined);
429+
assert.strictEqual(actual, 'board name (UsbMode=default)');
430+
});
402431
});
403432

404433
describe('isCustomDebugConfig', () => {

0 commit comments

Comments
 (0)