|
| 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 | +} |
0 commit comments