Skip to content

Commit 225b984

Browse files
authored
Prefer use built-in pyocd if 'server' setting is 'pyocd' (#24)
use builtin pyocd if server says `pyocd` and if available in extension --------- Signed-off-by: Jens Reinecke <[email protected]>
1 parent e3dc0ad commit 225b984

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

src/debug-configuration/gdbtarget-configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface UARTConfiguration {
4040
eolCharacter?: string;
4141
};
4242

43-
interface TargetConfiguration {
43+
export interface TargetConfiguration {
4444
type?: string;
4545
parameters?: string[];
4646
host?: string;

src/debug-configuration/subproviders/pyocd-configuration-provider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616

1717
import * as vscode from 'vscode';
1818
import { logger } from '../../logger';
19-
import { GDBTargetConfiguration } from '../gdbtarget-configuration';
19+
import { GDBTargetConfiguration, TargetConfiguration } from '../gdbtarget-configuration';
20+
import { BuiltinToolPath } from '../../desktop/builtin-tool-path';
2021

22+
const PYOCD_BUILTIN_PATH = 'tools/pyocd/pyocd';
23+
export const PYOCD_EXECUTABLE_ONLY_REGEXP = /^\s*pyocd(|.exe)\s*$/i;
2124
export const PYOCD_SERVER_TYPE_REGEXP = /.*pyocd(|.exe)\s*$/i;
2225

2326
export class PyocdConfigurationProvider implements vscode.DebugConfigurationProvider {
27+
protected builtinPyocd = new BuiltinToolPath(PYOCD_BUILTIN_PATH);
2428

2529
protected async hasCommand(commandName: string): Promise<boolean> {
2630
const commands = await vscode.commands.getCommands();
@@ -35,10 +39,22 @@ export class PyocdConfigurationProvider implements vscode.DebugConfigurationProv
3539
return !this.hasParam(paramName, params) && (!commandName || await this.hasCommand(commandName));
3640
}
3741

42+
protected resolveServerPath(target: TargetConfiguration): void {
43+
const targetServer = target.server;
44+
const useBuiltin = !targetServer || PYOCD_EXECUTABLE_ONLY_REGEXP.test(targetServer);
45+
const builtinUri = useBuiltin ? this.builtinPyocd.getAbsolutePath() : undefined;
46+
if (builtinUri) {
47+
target.server = builtinUri.fsPath;
48+
}
49+
}
50+
3851
protected async resolveServerParameters(debugConfiguration: GDBTargetConfiguration): Promise<GDBTargetConfiguration> {
3952
if (!debugConfiguration.target) {
4053
return debugConfiguration;
4154
}
55+
// server
56+
this.resolveServerPath(debugConfiguration.target);
57+
// serverParameters
4258
const parameters = debugConfiguration.target.serverParameters ??= [];
4359
// gdbserver
4460
if (await this.shouldAppendParam(parameters, 'gdbserver')) {

src/desktop/builtin-tool-path.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2025 Arm Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import assert from 'assert';
18+
import * as fs from 'fs';
19+
import { EXTENSION_ID } from '../manifest';
20+
import * as os from 'os';
21+
import * as vscode from 'vscode';
22+
23+
const isWindows = os.platform() === 'win32';
24+
25+
export class BuiltinToolPath {
26+
constructor(protected toolPath: string) {
27+
assert(toolPath.length, 'BuiltinToolManager: \'toolPath\' must not be empty');
28+
}
29+
30+
public getAbsolutePath(): vscode.Uri | undefined {
31+
const extensionUri = vscode.extensions.getExtension(EXTENSION_ID)?.extensionUri;
32+
const absoluteUri = extensionUri?.with({ path: `${extensionUri.path}/${this.toolPath}${isWindows ? '.exe' : ''}` });
33+
const fsPath = absoluteUri?.fsPath;
34+
return (fsPath && fs.existsSync(fsPath)) ? absoluteUri : undefined;
35+
}
36+
}

src/manifest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
export const PACKAGE_NAME = 'vscode-cmsis-debugger';
17+
export const PUBLISHER_NAME = 'arm';
18+
export const EXTENSION_NAME = 'vscode-cmsis-debugger';
19+
export const EXTENSION_ID = `${PUBLISHER_NAME}.${EXTENSION_NAME}`;
1820
export const DISPLAY_NAME = 'Arm CMSIS Debugger';

0 commit comments

Comments
 (0)