-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathSettingManager.ts
More file actions
894 lines (728 loc) · 28.7 KB
/
SettingManager.ts
File metadata and controls
894 lines (728 loc) · 28.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
/*
MIT License
Copyright (c) 2019 github0null
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import * as vscode from 'vscode';
import * as events from 'events';
import * as os from 'os';
import * as ini from 'ini';
import * as NodePath from 'path';
import { File } from '../lib/node-utility/File';
import { GlobalEvent } from './GlobalEvents';
import { ExceptionToMessage, newMessage } from './Message';
import * as Utility from './utility';
import { find, exeSuffix, userhome, osType } from './Platform';
import { WorkspaceManager } from './WorkspaceManager';
import { ToolchainName } from './ToolchainManager';
import { view_str$prompt$needReloadToUpdateEnv, WARNING } from './StringTable';
import { xpackRequireDevTools } from './XpackDevTools';
export enum CheckStatus {
All_Verified,
Section_Failed,
All_Failed
}
export interface PortSerialOption {
defaultPort: string;
baudRate: number;
dataBits: number;
parity: number;
stopBits: number;
useUnixCRLF: boolean;
}
let _instance: SettingManager | undefined;
interface INIStatus {
[name: string]: boolean;
}
function formatPath(path: string): string {
return path.trim().replace(/\\\s*$/, '');
}
export class SettingManager {
public static readonly TAG = 'EIDE';
private _event: events.EventEmitter;
private pathCache: Map<string, string>;
private envPathCache: Map<string, string>;
private eideEnv: Map<string, string>;
private _checkStatus: INIStatus = {
'MDK': false,
'C51': false
};
private constructor(context?: vscode.ExtensionContext) {
this._event = new events.EventEmitter();
this.pathCache = new Map();
this.envPathCache = new Map();
this.eideEnv = new Map();
if (context == undefined) {
throw new Error('eide context is undefined !');
}
/* add env */
this.eideEnv.set('${eideRoot}', context.extensionPath);
this.eideEnv.set('${userRoot}', userhome());
this.eideEnv.set('${userHome}', userhome());
try {
this.refreshMDKStatus();
this.refreshC51Status();
} catch (error) {
GlobalEvent.log_warn(error);
}
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration(SettingManager.TAG)) {
try {
if (e.affectsConfiguration('EIDE.ARM.INI.Path')) {
this.refreshMDKStatus();
}
if (e.affectsConfiguration('EIDE.C51.INI.Path')) {
this.refreshC51Status();
}
if (e.affectsConfiguration('EIDE.Builder.EnvironmentVariables')) {
this.syncGlobalEnvVariablesToNodeEnv();
}
if (e.affectsConfiguration('EIDE.Win32.Msys.Enable')) {
Utility.notifyReloadWindow(view_str$prompt$needReloadToUpdateEnv);
}
//! 暂时弃用 ccache
// // for non-win32 platform, we provide a check when user want to use 'ccache'
// if (osType() != 'win32') {
// if (e.affectsConfiguration('EIDE.Option.ccache')) {
// const sel = this.getConfiguration().get<string>('Option.ccache');
// if (sel !== 'never') {
// const path = find(`ccache${exeSuffix()}`);
// if (!path) {
// vscode.window.showWarningMessage(
// `${WARNING}: not found 'ccache', please install it by system packages manager.`);
// }
// }
// }
// }
} catch (error) {
GlobalEvent.log_warn(error);
}
this._event.emit('onChanged', e);
}
});
}
static instance(context?: vscode.ExtensionContext): SettingManager {
if (_instance === undefined)
_instance = new SettingManager(context);
return _instance;
}
/**
* @deprecated please use `instance()` instead of it.
*/
static GetInstance(context?: vscode.ExtensionContext): SettingManager {
if (_instance === undefined) {
_instance = new SettingManager(context);
}
return _instance;
}
on(event: 'onChanged', listener: (e: vscode.ConfigurationChangeEvent) => void): void;
on(event: any, listener: (arg?: any) => void): void {
this._event.on(event, listener);
}
once(event: 'onChanged', listener: (e: vscode.ConfigurationChangeEvent) => void): void;
once(event: any, listener: (arg?: any) => void): void {
this._event.once(event, listener);
}
trimSettingTag(setting_id: string): string {
return setting_id.replace(SettingManager.TAG + '.', '');
}
getConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration(SettingManager.TAG);
}
setConfigValue(key: string, val: any) {
this.getConfiguration().update(key, val, vscode.ConfigurationTarget.Global);
}
private _formatPathForPluginSettings(path_: string): string {
const wsRoot = WorkspaceManager.getInstance().getWorkspaceRoot();
if (wsRoot && !this.eideEnv.has('${workspaceFolder}')) {
this.eideEnv.set('${workspaceFolder}', wsRoot.path);
}
this.eideEnv.forEach((value, key) => {
const regExpr = key.replace('$', '\\$')
.replace('{', '\\{')
.replace('}', '\\}');
path_ = path_.replace(new RegExp(regExpr, 'gi'), value);
});
if (!NodePath.isAbsolute(path_) && wsRoot) {
path_ = wsRoot.path + File.sep + path_;
}
return path_;
}
/**
* 800:"workbench.action.openSettings"
* 801:"workbench.action.openSettings2"
* 802:"workbench.action.openSettingsJson"
*/
static async jumpToSettings(name: string) {
await vscode.commands.executeCommand('workbench.action.openSettings', name);
}
// --- source tree
isAutoSearchIncludePath(): boolean {
return this.getConfiguration().get<boolean>('SourceTree.AutoSearchIncludePath') || false;
}
isAutoSearchObjFile(): boolean {
return this.getConfiguration().get<boolean>('SourceTree.AutoSearchObjFile') || false;
}
//------------------------- env and path --------------------------
private getFullPathByPluginConfig(configName: string): string | undefined {
const path = this.getConfiguration().get<string>(configName);
if (path) {
const p = Utility.formatPath(this._formatPathForPluginSettings(path));
if (File.IsExist(p)) {
return p;
}
}
}
private findExePathInSystemEnv(exeName: string): string | undefined {
if (this.envPathCache.has(exeName)) {
return <string>this.envPathCache.get(exeName);
}
else {
const absPath = find(exeName);
if (absPath) {
this.envPathCache.set(exeName, absPath);
return absPath;
}
}
}
private findExeDirInSystemEnv(exeName: string): string | undefined {
if (this.envPathCache.has(exeName)) {
return <string>this.envPathCache.get(exeName);
}
else {
const absPath = find(exeName);
if (absPath) {
const dirpath = NodePath.dirname(absPath);
this.envPathCache.set(exeName, dirpath);
return dirpath;
}
}
}
private findGccCompilerRootInSystemEnv(gccName: string): string | undefined {
if (this.envPathCache.has(gccName)) {
return <string>this.envPathCache.get(gccName);
}
else {
const absPath = find(gccName);
if (absPath) {
const dirName = NodePath.dirname(NodePath.dirname(absPath));
this.envPathCache.set(gccName, dirName);
return dirName;
}
}
}
//--------------------- Global Option ------------------------
isEnableClangdConfigGenerator(): boolean {
return this.getConfiguration().get<boolean>('Option.EnableClangdConfigGenerator') || false;
}
isSilentBuildOrFlash(): boolean {
return this.getConfiguration().get<boolean>('Option.SilentWhenBuildOrFlash') || false;
}
syncGlobalEnvVariablesToNodeEnv() {
const envs = this.getGlobalEnvVariables();
for (const key in envs) {
process.env[key] = envs[key];
}
}
getGlobalEnvVariables(): { [key: string]: string } {
const lines = this.getConfiguration().get<string[]>('Builder.EnvironmentVariables') || [];
const result: { [key: string]: string } = {};
for (const _line of lines) {
const str = _line.trim();
if (str.startsWith('#'))
continue;
const sep_idx = str.indexOf('=');
if (sep_idx == -1)
continue;
const k = str.substring(0, sep_idx).trim();
if (!/^\w+$/.test(k))
continue;
const v = str.substring(sep_idx + 1).trim();
if (v) {
result[k] = v;
}
}
return result;
}
getForceIncludeList(): string[] {
return this.getConfiguration().get<string[]>('Cpptools.ForceInclude') || [];
}
//! 暂时弃用 ccache
// "EIDE.Option.ccache": {
// "type": "string",
// "scope": "resource",
// "markdownDescription": "%settings.enable.ccache%",
// "default": "never",
// "enum": [
// "auto",
// "always",
// "never"
// ],
// "enumDescriptions": [
// "Auto",
// "Always Use",
// "Never Use"
// ]
// },
isEnableCcache(sourceAmount: number): boolean {
// const sel = this.getConfiguration().get<string>('Option.ccache');
// if (sel === 'always')
// return true;
// if (sel === 'auto' && sourceAmount > 500)
// return true;
return false;
}
isEnableMsys(): boolean {
if (os.platform() != 'win32')
return false; //! not support non-win32 platform
return this.getConfiguration().get<boolean>('Win32.Msys.Enable') || false;
}
isEnableTelemetry(): boolean {
return this.getConfiguration().get<boolean>('Option.EnableTelemetry') || false;
}
isShowOutputFilesInExplorer(): boolean {
return true;
}
getBuilderAdditionalCommandLine(): string | undefined {
return this.getConfiguration().get<string>('Builder.AdditionalCommandLine');
}
getMapViewParserDepth(): number {
return this.getConfiguration().get<number>('Option.MapViewParserDepth') || 0;
}
isDisplaySourceRefs(): boolean {
return true;
}
isGenerateMakefileParams(): boolean {
return false;
}
isPrintRelativePathWhenBuild(): boolean {
return true;
}
getGithubRepositoryToken(): string | undefined {
return this.getConfiguration().get<string>('Repository.Template.GithubPersonalToken')?.trim();
}
getGithubRepositoryUrl(): string {
return (this.getConfiguration().get<string>('Repository.Template.Url') || 'null')
.trim().replace(/^https:\/\//i, '');
}
getCmsisPackRepositoryUrl(): string {
return (this.getConfiguration().get<string>('Repository.CmsisPack.Url') || 'null')
.trim().replace(/^https:\/\//i, '');
}
getExternalToolsIndexUrl(): string | undefined {
const url = this.getConfiguration().get<string>('ExternalTools.IndexUrl');
if (url) {
return url.trim();
}
}
isUseGithubProxy(): boolean {
return this.getConfiguration().get<boolean>('Repository.UseProxy') || false;
}
isUseTaskToBuild(): boolean {
return this.getConfiguration().get<boolean>('Option.UseTaskToBuild') || false;
}
isKeilC51IniReady(): boolean {
return this._checkStatus['C51'];
}
isMDKIniReady(): boolean {
return this._checkStatus['MDK'];
}
isInsertCommandsAtBegin(): boolean {
return this.getConfiguration().get<boolean>('Option.InsertExtraCommandsAtBegin') || false;
}
getCppcheckerExe(): string | undefined {
return this.getFullPathByPluginConfig('Cppcheck.ExecutablePath')
|| this.findExePathInSystemEnv('cppcheck');
}
//----------------------------- Flasher --------------------------------
getJlinkDir(): string {
// on linux: `/usr/bin/JLinkExe`
// on Windows: `C:\Program Files (x86)\SEGGER\JLink\JLink.exe`
return this.getFullPathByPluginConfig('JLink.InstallDirectory')
|| this.findExeDirInSystemEnv(osType() === 'win32' ? 'JLink' : 'JLinkExe')
|| 'null';
}
getJlinkExePath(): string {
const dir = this.getJlinkDir();
const name = osType() === 'win32' ? 'JLink.exe' : 'JLinkExe';
if (dir == 'null')
return name;
return NodePath.join(dir, name);
}
getStvpExePath(): string {
return this.getFullPathByPluginConfig('STM8.STVP.CliExePath')
|| this.findExePathInSystemEnv('STVP_CmdLine')
|| 'null';
}
getSTLinkExePath(): string {
return this.getFullPathByPluginConfig('STLink.ExePath')
|| this.findExePathInSystemEnv('STM32_Programmer_CLI')
|| this.findExePathInSystemEnv('ST-LINK_CLI')
|| 'null';
}
getOpenOCDExePath(): string {
try {
if (vscode.workspace.workspaceFile) {
const dir = File.from(NodePath.dirname(vscode.workspace.workspaceFile.fsPath));
const r = xpackRequireDevTools(dir, 'openocd');
if (r) {
return File.from(r.path, 'bin', `openocd${exeSuffix()}`).path;
}
}
} catch (error) {
GlobalEvent.log_warn(<Error>error);
return `<xpack-dev-tools openocd not-exist>`;
}
return this.getFullPathByPluginConfig('OpenOCD.ExePath')
|| this.findExePathInSystemEnv('openocd')
|| 'null';
}
//--------------------------COSMIC-----------------------------
getCosmicStm8ToolsDir(): File {
const p = this.getFullPathByPluginConfig('STM8.COSMIC.InstallDirectory');
if (p) {
return new File(p);
}
const execName = 'cxstm8';
if (this.envPathCache.has(execName)) {
return new File(<string>this.envPathCache.get(execName))
}
else {
const absPath = find(execName);
if (absPath) {
const dirName = NodePath.dirname(absPath);
this.envPathCache.set(execName, dirName);
return new File(dirName);
}
}
return new File('null');
}
//-----------------------------IAR-------------------------------
getIARForStm8Dir(): File {
const p = this.getFullPathByPluginConfig('IAR.STM8.InstallDirectory');
if (p) {
return new File(p);
}
const execName = 'iccstm8';
if (this.envPathCache.has(execName)) {
return new File(<string>this.envPathCache.get(execName))
}
else {
const absPath = find(execName);
if (absPath) {
const dirName = NodePath.dirname(NodePath.dirname(NodePath.dirname(absPath)));
this.envPathCache.set(execName, dirName);
return new File(dirName);
}
}
return new File('null');
}
getIarForArmDir(): File {
return new File(
this.getFullPathByPluginConfig('IAR.ARM.Toolchain.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv('iccarm') ||
'null'
);
}
//---------------------------- ARM ----------------------------
isUseMultithreadMode(): boolean {
return this.getConfiguration().get<number>('Builder.ThreadNumber') != 1;
}
getThreadNumber(): number {
const num = this.getConfiguration().get<number>('Builder.ThreadNumber') || -1;
if (num <= 0) { return os.cpus().length; }
return num;
}
//! deprecated.
// IsConvertAxf2Elf(): boolean {
// return this.getConfiguration().get<boolean>('ARM.Option.AxfToElf') || false;
// }
IsAutoGenerateRTEHeader(): boolean {
return this.getConfiguration().get<boolean>('ARM.Option.AutoGenerateRTE_Components') || false;
}
getGCCPrefix(): string {
return this.getConfiguration().get<string>('ARM.GCC.Prefix') || '';
}
getGCCDir(): File {
try {
if (vscode.workspace.workspaceFile) {
const dir = File.from(NodePath.dirname(vscode.workspace.workspaceFile.fsPath));
const r = xpackRequireDevTools(dir, `${this.getGCCPrefix()}gcc`);
if (r) {
return r;
}
}
} catch (error) {
GlobalEvent.log_warn(<Error>error);
return File.from(`<xpack-dev-tools ${this.getGCCPrefix()}gcc not-exist>`);
}
return new File(
this.getFullPathByPluginConfig('ARM.GCC.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv(`${this.getGCCPrefix()}gcc`) ||
'null'
);
}
// ---
getLLVMArmDir(): File {
return new File(
this.getFullPathByPluginConfig('ARM.LLVM.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv('clang') ||
'null'
);
}
// ---
getArmcc5Dir(): File {
return new File(
this.getFullPathByPluginConfig('ARM.ARMCC5.InstallDirectory') ||
this.pathCache.get('ARMCC5') ||
this.findGccCompilerRootInSystemEnv('armcc') ||
'null'
);
}
getArmcc6Dir(): File {
return new File(
this.getFullPathByPluginConfig('ARM.ARMCC6.InstallDirectory') ||
this.pathCache.get('ARMCC6') ||
this.findGccCompilerRootInSystemEnv('armclang') ||
'null'
);
}
SetMdkIniOrUv4Path(path: string) {
this.setConfigValue('ARM.INI.Path', path);
}
private GetMdkINIOrUv4File(): File {
const iniPath = this.getConfiguration().get<string>('ARM.INI.Path') || '';
return new File(Utility.formatPath(iniPath));
}
GetMdkArmDir(): File | undefined {
const path = this.pathCache.get('MDK');
if (path) {
return new File(path);
}
}
private refreshMDKStatus(): void {
/* parse from ini file */
const iniFile = this.GetMdkINIOrUv4File();
if (iniFile.IsFile()) {
// is uv4.exe
if (iniFile.suffix.toLowerCase() == '.exe') {
const armccDir = File.fromArray([NodePath.dirname(iniFile.dir), 'ARM', 'ARMCC']);
const armclangDir = File.fromArray([NodePath.dirname(iniFile.dir), 'ARM', 'ARMCLANG']);
let cnt = 0;
if (armccDir.IsDir()) { this.pathCache.set('ARMCC5', armccDir.path); cnt++; };
if (armclangDir.IsDir()) { this.pathCache.set('ARMCC6', armclangDir.path); cnt++; }
if (cnt > 0) {
this._checkStatus['MDK'] = true;
return;
}
}
// is ini
else {
const iniData = ini.parse(iniFile.Read());
if (iniData["ARM"] && iniData["ARM"]["PATH"]) {
// mdk ARM dir
const mdkArmDir = new File(formatPath((<string>iniData["ARM"]["PATH"]).replace(/"/g, '')));
// cache arm dir
if (mdkArmDir.IsDir()) {
this.pathCache.set('MDK', mdkArmDir.path);
}
let cnt = 0;
// cache armcc5 path
const armcc5Dir = File.fromArray([mdkArmDir.path, 'ARMCC', 'bin']);
if (armcc5Dir.IsDir()) { this.pathCache.set('ARMCC5', armcc5Dir.dir); cnt++; }
// cache armcc6 path
const armcc6Dir = File.fromArray([mdkArmDir.path, 'ARMCLANG', 'bin']);
if (armcc6Dir.IsDir()) { this.pathCache.set('ARMCC6', armcc6Dir.dir); cnt++; }
// check all
if (cnt > 0) {
this._checkStatus['MDK'] = true;
return; // mdk path is ok, return
}
}
}
}
/* parse from env */
if (process.env && process.env['Keil_Root']) {
const rootFolder = Utility.formatPath(process.env['Keil_Root']);
const armFolder = File.fromArray([rootFolder, 'ARM']);
if (armFolder.IsDir() &&
File.fromArray([armFolder.path, 'ARMCC']).IsDir()) {
this.pathCache.set('MDK', armFolder.path);
this._checkStatus['MDK'] = true;
return; /* found it, exit */
}
}
// not found any path
this.pathCache.delete('ARMCC5');
this.pathCache.delete('ARMCC6');
this._checkStatus['MDK'] = false;
}
//------------------------------- SDCC --------------------------------
getSdccDir(): File {
return new File(
this.getFullPathByPluginConfig('SDCC.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv('sdcc') ||
'null'
);
}
getGnuSdccStm8Dir(): File {
return new File('null'); // disabled
}
getGnuSdccMcs51Dir(): File {
return new File(
this.getFullPathByPluginConfig('SDCC.GNU_MCS51.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv('i51-elf-as') ||
'null'
);
}
//------------------------------- RISC-V ----------------------------------
getRiscvToolFolder(): File {
try {
if (vscode.workspace.workspaceFile) {
const dir = File.from(NodePath.dirname(vscode.workspace.workspaceFile.fsPath));
const r = xpackRequireDevTools(dir, `${this.getRiscvToolPrefix()}gcc`);
if (r) {
return r;
}
}
} catch (error) {
GlobalEvent.log_warn(<Error>error);
return File.from(`<xpack-dev-tools ${this.getRiscvToolPrefix()}gcc not-exist>`);
}
return new File(
this.getFullPathByPluginConfig('RISCV.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv(`${this.getRiscvToolPrefix()}gcc`) ||
'null'
);
}
getRiscvToolPrefix(): string {
return this.getConfiguration().get<string>('RISCV.ToolPrefix') || '';
}
//------------------------------- MTI GCC ----------------------------------
getMipsToolFolder(): File {
try {
if (vscode.workspace.workspaceFile) {
const dir = File.from(NodePath.dirname(vscode.workspace.workspaceFile.fsPath));
const r = xpackRequireDevTools(dir, `${this.getMipsToolPrefix()}gcc`);
if (r) {
return r;
}
}
} catch (error) {
GlobalEvent.log_warn(<Error>error);
return File.from(`<xpack-dev-tools ${this.getMipsToolPrefix()}gcc not-exist>`);
}
return new File(
this.getFullPathByPluginConfig('MIPS.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv(`${this.getMipsToolPrefix()}gcc`) ||
'null'
);
}
getMipsToolPrefix(): string {
return this.getConfiguration().get<string>('MIPS.ToolPrefix') || '';
}
//------------------------------- Any GCC ----------------------------------
getAnyGccToolFolder(): File {
try {
if (vscode.workspace.workspaceFile) {
const dir = File.from(NodePath.dirname(vscode.workspace.workspaceFile.fsPath));
const r = xpackRequireDevTools(dir, `${this.getAnyGccToolPrefix()}gcc`);
if (r) {
return r;
}
}
} catch (error) {
GlobalEvent.log_warn(<Error>error);
return File.from(`<xpack-dev-tools ${this.getAnyGccToolPrefix()}gcc not-exist>`);
}
return new File(
this.getFullPathByPluginConfig('Toolchain.AnyGcc.InstallDirectory') ||
this.findGccCompilerRootInSystemEnv(`${this.getAnyGccToolPrefix()}gcc`) ||
'null'
);
}
getAnyGccToolPrefix(): string {
return this.getConfiguration().get<string>('Toolchain.AnyGcc.ToolPrefix') || '';
}
setGccFamilyToolPrefix(id: ToolchainName, newPrefix: string, global?: boolean) {
const region = global ? vscode.ConfigurationTarget.Global : vscode.ConfigurationTarget.Workspace;
switch (id) {
case 'GCC':
this.getConfiguration().update('ARM.GCC.Prefix', newPrefix, region);
break;
case 'RISCV_GCC':
this.getConfiguration().update('RISCV.ToolPrefix', newPrefix, region);
break;
case 'ANY_GCC':
this.getConfiguration().update('Toolchain.AnyGcc.ToolPrefix', newPrefix, region);
break;
default:
break;
}
}
//------------------------------- C51 ----------------------------------
SetC51IniOrUv4Path(path: string) {
this.setConfigValue('C51.INI.Path', path);
}
private GetC51INIFile(): File {
const iniPath = this.getConfiguration().get<string>('C51.INI.Path') || '';
return new File(Utility.formatPath(iniPath));
}
GetC51Dir(): File {
return new File(this.pathCache.get('C51') || 'null');
}
private refreshC51Status(): void {
const iniFile = this.GetC51INIFile();
if (iniFile.IsFile()) {
// is uv4.exe
if (iniFile.suffix.toLowerCase() == '.exe') {
const c51BinDir = File.fromArray([NodePath.dirname(iniFile.dir), 'C51', 'BIN']);
if (c51BinDir.IsDir()) {
this.pathCache.set('C51', c51BinDir.dir);
this._checkStatus['C51'] = true;
return;
}
}
// is ini file
else {
const iniData = ini.parse(iniFile.Read());
if (iniData["C51"] && iniData["C51"]["PATH"]) {
const c51BinDir = File.fromArray([formatPath((<string>iniData["C51"]["PATH"]).replace(/"/g, '')), 'BIN']);
if (c51BinDir.IsDir()) {
this.pathCache.set('C51', c51BinDir.dir);
this._checkStatus['C51'] = true;
return;
}
}
}
}
/* parse from env */
if (process.env && process.env['Keil_Root']) {
const rootFolder = Utility.formatPath(process.env['Keil_Root']);
const c51Folder = File.fromArray([rootFolder, 'C51']);
if (c51Folder.IsDir() &&
File.fromArray([c51Folder.path, 'BIN']).IsDir()) {
this.pathCache.set('C51', c51Folder.path);
this._checkStatus['C51'] = true;
return; /* found it, exit */
}
}
// not found any path
this.pathCache.delete('C51');
this._checkStatus['C51'] = false;
}
}