MCPcopy Create free account
hub / github.com/Marus/cortex-debug / resolveCubePath

Function resolveCubePath

src/stlink.ts:37–64  ·  view source on GitHub ↗

* Resolves the path location of a STM32CubeIDE plugin irrespective of version number. * Works for most recent version STM32CubeIDE_1.4.0 and STM32CubeIDE_1.5.0.

(dirSegments: string[], regex: RegExp, suffix: string, executable = '')

Source from the content-addressed store, hash-verified

35 * Works for most recent version STM32CubeIDE_1.4.0 and STM32CubeIDE_1.5.0.
36 */
37function resolveCubePath(dirSegments: string[], regex: RegExp, suffix: string, executable = '')
38{
39 const dir = path.join(...dirSegments);
40 let resolvedDir: string;
41 try {
42 for (const subDir of fs.readdirSync(dir).sort()) {
43 const fullPath = path.join(dir, subDir);
44 const stats = fs.statSync(fullPath);
45 if (!stats.isDirectory()) {
46 continue;
47 }
48
49 const match = subDir.match(regex);
50 if (match) {
51 const fullPath = path.join(dir, match[0], suffix, executable);
52 if (fs.existsSync(fullPath)) {
53 if (!resolvedDir || (resolvedDir.localeCompare(fullPath, undefined, {sensitivity: 'base', numeric: true})) < 0) {
54 resolvedDir = fullPath; // Many times, multiple versions exist. Take latest. Hopefully!!
55 }
56 }
57 }
58 }
59 }
60 catch (error) {
61 // Ignore
62 }
63 return resolvedDir ? resolvedDir : executable;
64}
65
66export class STLinkServerController extends EventEmitter implements GDBServerController {
67 public readonly name: string = 'ST-LINK';

Callers 4

getSTMCubeIdeDirMethod · 0.85
getArmToolchainPathMethod · 0.85
serverExecutableMethod · 0.85
serverArgumentsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected