Skip to content

Commit 3bec1cf

Browse files
authored
Adding CMSIS_PACK_ROOT handling by default for pyOCD (#120)
* adding cmsisPackRoot to the list of environment configuration interface * setting default value for cmsisPackRoot if it's not set by user * adding CMSIS_PACK_ROOT variable by default if it's not set * editing for readability
1 parent 9daa1b5 commit 3bec1cf

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/debug-configuration/gdbtarget-configuration.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
import * as vscode from 'vscode';
1818

19-
interface EnvironmentConfiguration {
20-
additionalProperties?: string;
21-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22-
default?: any;
19+
interface TargetEnvironmentConfiguration {
20+
CMSIS_PACK_ROOT?: string;
2321
};
2422

2523
interface ImageAndSymbolsConfiguration {
@@ -46,8 +44,7 @@ export interface TargetConfiguration {
4644
host?: string;
4745
port?: string;
4846
cwd?: string;
49-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50-
environment?: any;
47+
environment?: TargetEnvironmentConfiguration;
5148
server?: string;
5249
serverParameters?: string[];
5350
serverPortRegExp?: string;
@@ -64,7 +61,8 @@ export interface GDBTargetConfiguration extends vscode.DebugConfiguration {
6461
program?: string; // required as per 'gdbtarget' debugger contribution, but can be omitted anyway
6562
gdb?: string;
6663
cwd?: string;
67-
environment?: EnvironmentConfiguration;
64+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
65+
environment?: any;
6866
gdbAsync?: boolean;
6967
gdbNonStop?: boolean;
7068
verbose?: boolean;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { logger } from '../../logger';
1818
import { GDBTargetConfiguration, TargetConfiguration } from '../gdbtarget-configuration';
1919
import { BuiltinToolPath } from '../../desktop/builtin-tool-path';
2020
import { BaseConfigurationProvider } from './base-configuration-provider';
21+
import * as os from 'os';
22+
import * as path from 'path';
2123

2224
const PYOCD_BUILTIN_PATH = 'tools/pyocd/pyocd';
2325
const PYOCD_EXECUTABLE_ONLY_REGEXP = /^\s*pyocd(|.exe)\s*$/i;
@@ -39,6 +41,23 @@ export class PyocdConfigurationProvider extends BaseConfigurationProvider {
3941
}
4042
}
4143

44+
protected resolveCmsisPackRootPath(target: TargetConfiguration): void {
45+
const environmentValue = process.env['CMSIS_PACK_ROOT'];
46+
if (environmentValue) {
47+
return;
48+
}
49+
50+
if (target.environment?.CMSIS_PACK_ROOT) {
51+
return;
52+
}
53+
const cmsisPackRootDefault = os.platform() === 'win32'
54+
? path.join(process.env['LOCALAPPDATA'] ?? os.homedir(), 'Arm', 'Packs')
55+
: path.join(os.homedir(), '.cache', 'arm', 'packs');
56+
57+
target.environment ??= {};
58+
target.environment.CMSIS_PACK_ROOT = cmsisPackRootDefault;
59+
}
60+
4261
protected async resolveServerParameters(debugConfiguration: GDBTargetConfiguration): Promise<GDBTargetConfiguration> {
4362
logger.debug('Resolving pyOCD server parameters');
4463
if (!debugConfiguration.target) {
@@ -64,6 +83,8 @@ export class PyocdConfigurationProvider extends BaseConfigurationProvider {
6483
if (cbuildRunFile && await this.shouldAppendParameter(parameters, PYOCD_CLI_ARG_CBUILDRUN)) {
6584
parameters.push(PYOCD_CLI_ARG_CBUILDRUN, `${cbuildRunFile}`);
6685
}
86+
// CMSIS_PACK_ROOT
87+
this.resolveCmsisPackRootPath(debugConfiguration.target);
6788
return debugConfiguration;
6889
}
6990

0 commit comments

Comments
 (0)