Skip to content

Commit 9daa1b5

Browse files
authored
adding pyocd executable to PATH variable (#107)
* adding pyocd executable to PATH variable
1 parent fdd0a99 commit 9daa1b5

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/desktop/add-to-path.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
18+
import * as vscode from 'vscode';
19+
import { logger } from '../logger';
20+
import { BuiltinToolPath, isWindows } from './builtin-tool-path';
21+
22+
const PYOCD_BUILTIN_PATH = 'tools/pyocd/pyocd';
23+
24+
export function addPyocdToPath(context: vscode.ExtensionContext): void {
25+
//get pyOCD path from tools folder
26+
const builtinPyocd = new BuiltinToolPath(PYOCD_BUILTIN_PATH);
27+
const pathPyOCD = builtinPyocd.getAbsolutePathDir();
28+
if (!pathPyOCD) {
29+
logger.debug('pyOCD is not available');
30+
return;
31+
}
32+
//get PATH variable
33+
const pathVariable = process.env.PATH;
34+
if (!pathVariable) {
35+
logger.debug('pyOCD is not available');
36+
return;
37+
}
38+
const delimiter = isWindows ? ';' : ':';
39+
const updatePath = pathPyOCD.concat(delimiter, pathVariable);
40+
//add updated path to PATH variable, but only for the terminal inside of vscode
41+
context.environmentVariableCollection.replace('PATH', updatePath);
42+
}

src/desktop/builtin-tool-path.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import * as fs from 'fs';
1919
import { EXTENSION_ID } from '../manifest';
2020
import * as os from 'os';
2121
import * as vscode from 'vscode';
22+
import * as path from 'path';
2223

23-
const isWindows = os.platform() === 'win32';
24+
export const isWindows = os.platform() === 'win32';
2425

2526
export class BuiltinToolPath {
2627
constructor(protected toolPath: string) {
@@ -33,4 +34,12 @@ export class BuiltinToolPath {
3334
const fsPath = absoluteUri?.fsPath;
3435
return (fsPath && fs.existsSync(fsPath)) ? absoluteUri : undefined;
3536
}
37+
38+
public getAbsolutePathDir(): string | undefined{
39+
const pathToFile = this.getAbsolutePath()?.fsPath;
40+
if (pathToFile) {
41+
return path.dirname(pathToFile);
42+
}
43+
return undefined;
44+
}
3645
}

src/desktop/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import * as vscode from 'vscode';
1818
import { GDBTargetDebugTracker } from '../debug-configuration/gdbtarget-debug-tracker';
1919
import { GDBTargetConfigurationProvider } from '../debug-configuration';
2020
import { logger } from '../logger';
21+
import { addPyocdToPath } from './add-to-path';
2122

2223
export const activate = async (context: vscode.ExtensionContext): Promise<void> => {
2324
const gdbtargetDebugTracker = new GDBTargetDebugTracker();
2425
const gdbtargetConfigurationProvider = new GDBTargetConfigurationProvider();
2526

27+
addPyocdToPath(context);
2628
// Activate components
2729
gdbtargetDebugTracker.activate(context);
2830
gdbtargetConfigurationProvider.activate(context);

0 commit comments

Comments
 (0)