Skip to content

Commit

Permalink
Merge pull request #49 from per1234/fix-custom-override
Browse files Browse the repository at this point in the history
Fix regression in overriding remapped debug configuration data via `debug_custom.json`
  • Loading branch information
per1234 authored Mar 5, 2024
2 parents 4938c41 + 8dcb493 commit 0227d28
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ async function mergeLaunchConfig(
(config) => config.configId === configId
);
const name = createName(board, programmer);
const launchConfig = {
// Create base configuration data
let launchConfig = {
configId,
cwd: '${workspaceRoot}',
request: 'launch',
Expand All @@ -315,17 +316,26 @@ async function mergeLaunchConfig(
...(debugInfo.customConfigs
? debugInfo.customConfigs[cortexDebug] ?? {}
: {}),
...(customConfig ? customConfig : {}),
name,
};

// Remap Arduino CLI debug config properties to launch.json keys
replaceValue('serverPath', 'serverpath', launchConfig);
replaceValue('server', 'servertype', launchConfig);
replaceValue('toolchainPath', 'armToolchainPath', launchConfig);
replaceValue('serverConfiguration.scripts', 'configFiles', launchConfig);
// Remove unused Arduino CLI debug config data
unsetValue(launchConfig, 'customConfigs');
unsetValue(launchConfig, 'serverConfiguration');
unsetValue(launchConfig, 'programmer'); // The programmer is not used by the debugger https://github.com/arduino/arduino-cli/pull/2391
unsetValue(launchConfig, 'toolchain'); // The toolchain is also unused by IDE2 or the cortex-debug VSIX

// Merge configuration from debug_custom.json
launchConfig = {
...launchConfig,
...(customConfig ? customConfig : {}),
};

return launchConfig;
}

Expand Down
35 changes: 31 additions & 4 deletions src/test/suite/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,27 @@ describe('debug', () => {
const actual = await mergeLaunchConfig(
board,
programmer,
{ executable },
[{ configId, cwd: 'alma' }]
{
executable,
toolchainPrefix: 'toolchain-prefix',
serverPath: 'path/to/server',
server: 'openocd',
toolchainPath: 'path/to/toolchain',
serverConfiguration: {
scripts: ['path/to/config-file'],
},
},
[
{
configId,
cwd: 'alma',
toolchainPrefix: 'custom-toolchain-prefix',
serverpath: '/path/to/custom-server',
servertype: 'jlink',
armToolchainPath: '/path/to/custom-arm-toolchain',
configFiles: ['/path/to/custom-config'],
},
]
);
assert.deepStrictEqual(actual, {
configId,
Expand All @@ -154,6 +173,11 @@ describe('debug', () => {
name: 'ABC (p1)',
request: 'launch',
type: 'cortex-debug',
toolchainPrefix: 'custom-toolchain-prefix',
serverpath: '/path/to/custom-server',
servertype: 'jlink',
armToolchainPath: '/path/to/custom-arm-toolchain',
configFiles: ['/path/to/custom-config'],
});
});

Expand Down Expand Up @@ -230,8 +254,11 @@ describe('debug', () => {
const actual = await mergeLaunchConfig(
board,
programmer,
{ executable },
[{ configId, [key]: value }]
{
executable,
[key]: value,
},
[]
);
assert.deepStrictEqual(actual, expected);
})
Expand Down

0 comments on commit 0227d28

Please sign in to comment.