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