Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/desktop/add-to-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2025 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import * as vscode from 'vscode';
import { logger } from '../logger';
import { BuiltinToolPath, isWindows } from './builtin-tool-path';

const PYOCD_BUILTIN_PATH = 'tools/pyocd/pyocd';

export function addPyocdToPath(context: vscode.ExtensionContext): void {
//get pyOCD path from tools folder
const builtinPyocd = new BuiltinToolPath(PYOCD_BUILTIN_PATH);
const pathPyOCD = builtinPyocd.getAbsolutePathDir();
if (!pathPyOCD) {
logger.debug('pyOCD is not available');
return;
}
//get PATH variable
const pathVariable = process.env.PATH;
if (!pathVariable) {
logger.debug('pyOCD is not available');
return;
}
const delimiter = isWindows ? ';' : ':';
const updatePath = pathPyOCD.concat(delimiter, pathVariable);
//add updated path to PATH variable, but only for the terminal inside of vscode
context.environmentVariableCollection.replace('PATH', updatePath);
}
11 changes: 10 additions & 1 deletion src/desktop/builtin-tool-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import * as fs from 'fs';
import { EXTENSION_ID } from '../manifest';
import * as os from 'os';
import * as vscode from 'vscode';
import * as path from 'path';

const isWindows = os.platform() === 'win32';
export const isWindows = os.platform() === 'win32';

export class BuiltinToolPath {
constructor(protected toolPath: string) {
Expand All @@ -33,4 +34,12 @@ export class BuiltinToolPath {
const fsPath = absoluteUri?.fsPath;
return (fsPath && fs.existsSync(fsPath)) ? absoluteUri : undefined;
}

public getAbsolutePathDir(): string | undefined{
const pathToFile = this.getAbsolutePath()?.fsPath;
if (pathToFile) {
return path.dirname(pathToFile);
}
return undefined;
}
}
2 changes: 2 additions & 0 deletions src/desktop/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import * as vscode from 'vscode';
import { GDBTargetDebugTracker } from '../debug-configuration/gdbtarget-debug-tracker';
import { GDBTargetConfigurationProvider } from '../debug-configuration';
import { logger } from '../logger';
import { addPyocdToPath } from './add-to-path';

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

addPyocdToPath(context);
// Activate components
gdbtargetDebugTracker.activate(context);
gdbtargetConfigurationProvider.activate(context);
Expand Down