Skip to content

Commit b5101f8

Browse files
committed
adding pyocd executable to PATH variable
1 parent fdd0a99 commit b5101f8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/desktop/add-to-path.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 { BuiltinToolPath } from './builtin-tool-path';
20+
import * as os from 'os';
21+
22+
const isWindows = os.platform() === 'win32';
23+
const PYOCD_BUILTIN_PATH = 'tools/pyocd/';
24+
25+
export function addPyOCDtoPATH(context: vscode.ExtensionContext): void {
26+
//get pyOCD path from tools folder
27+
const builtinPyocd = new BuiltinToolPath(PYOCD_BUILTIN_PATH);
28+
const pathPyOCD = builtinPyocd.getAbsolutePath()?.toString();
29+
//get PATH variable
30+
const path = process.env.PATH;
31+
//slice unwanted characters from pyOCD path, take care of the Windows case
32+
let slicedPyOCDpath;
33+
if(isWindows) {
34+
slicedPyOCDpath = pathPyOCD?.slice(7, pathPyOCD.length - 4);
35+
} else {
36+
slicedPyOCDpath = pathPyOCD?.slice(7);
37+
}
38+
39+
//add pyOCD path to PATH, set at the beginning so that it gets called before pyOCD installed on the system
40+
const updatepath = slicedPyOCDpath + ':' + path;
41+
//add updated path to PATH variable, but only for the terminal inside of vscode
42+
context.environmentVariableCollection.replace('PATH', updatepath);
43+
}

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)