-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathconfiguration.ts
2745 lines (2515 loc) · 102 KB
/
configuration.ts
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
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// Configuration support
import { extension } from "./extension";
import * as logger from "./logger";
import * as make from "./make";
import * as ui from "./ui";
import * as util from "./util";
import * as vscode from "vscode";
import * as path from "path";
import * as telemetry from "./telemetry";
import * as nls from "vscode-nls";
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
let statusBar: ui.UI = ui.getUI();
// Each different scenario of building the same makefile, in the same environment, represents a configuration.
// Example: "make BUILD_TYPE=Debug" and "make BUILD_TYPE=Release" can be the debug and release configurations.
// The user can save several different such configurations in makefile.configurations setting,
// from which one can be picked via this extension and saved in settings.
// Priority rules for where is the Makefile Tools extension parsing the needed information from:
// 1. makefile.configurations.buildLog setting
// 2. makefile.buildLog setting
// 3. makefile.configurations.makePath, makefile.configurations.makeArgs
// 4. makefile.makePath and default args
// 5. default make tool and args
export interface MakefileConfiguration {
// A name associated with a particular build command process and args/options
name: string;
// The path (full or relative to the workspace folder) to the makefile
makefilePath?: string;
// make, nmake, specmake...
// This is sent to spawnChildProcess as process name
// It can have full path, relative path to the workspace folder or only tool name
// Don't include args in makePath
makePath?: string;
// a folder path (full or relative) containing the entrypoint makefile
makeDirectory?: string;
// options used in the build invocation
// don't use more than one argument in a string
makeArgs?: string[];
// list of problem matcher names to be used when building the current target
problemMatchers?: string[];
// a pre-generated build log, from which it is preffered to parse from,
// instead of the dry-run output of the make tool
buildLog?: string;
// arguments for the pre configure script
preConfigureArgs?: string[];
// arguments for the post configure script
postConfigureArgs?: string[];
// TODO: investigate how flexible this is to integrate with other build systems than the MAKE family
// (basically anything that can produce a dry-run output is sufficient)
// Implement set-able dry-run, verbose, change-directory and always-make switches
// since different tools may use different arguments for the same behavior
}
// Last configuration name picked from the set defined in makefile.configurations setting.
// Saved into the workspace state. Also reflected in the configuration status bar button.
// If no particular current configuration is defined in settings, set to 'Default'.
let currentMakefileConfiguration: string;
export function getCurrentMakefileConfiguration(): string {
return currentMakefileConfiguration;
}
export async function setCurrentMakefileConfiguration(
configuration: string
): Promise<void> {
currentMakefileConfiguration = configuration;
statusBar.setConfiguration(currentMakefileConfiguration);
await analyzeConfigureParams();
}
// Read the current configuration from workspace state, update status bar item
export function readCurrentMakefileConfiguration(): void {
let buildConfiguration: string | undefined =
extension.getState().buildConfiguration;
if (!buildConfiguration) {
logger.message(
localize(
"no.current.configuration.defined.workspace.state",
"No current configuration is defined in the workspace state. Assuming 'Default'."
)
);
currentMakefileConfiguration = "Default";
} else {
logger.message(
localize(
"reading.current.configuration.workspace.state",
'Reading current configuration "{0}" from the workspace state.',
buildConfiguration
)
);
currentMakefileConfiguration = buildConfiguration;
}
statusBar.setConfiguration(currentMakefileConfiguration);
}
// as described in makefile.panel.visibility
type MakefilePanelVisibility = {
debug: boolean;
run: boolean;
};
// internal, runtime representation of an optional feature
type MakefilePanelVisibilityDescription = {
propertyName: string;
default: boolean;
value: boolean;
enablement?: string;
};
// To add an optional feature (one that can be enabled/disabled based
// on a property stored in settings.json):
// * define property under makefile.panel.visibility in package.json
// * initialize here the default values
// * if the feature controls the UI via enablement,
// * make sure enablement is handled in package.json, you are done
// * if not, then add code to check Feature state wherever is needed.
class MakefilePanelVisibilityDescriptions {
features: MakefilePanelVisibilityDescription[] = [
{
propertyName: "debug",
enablement: "makefile:localDebugFeature",
default: true,
value: false,
},
{
propertyName: "run",
enablement: "makefile:localRunFeature",
default: true,
value: false,
},
];
}
let panelVisibility: MakefilePanelVisibilityDescriptions =
new MakefilePanelVisibilityDescriptions();
// Set all features to their defaults (enabled or disabled)
function initOptionalFeatures(): void {
for (let feature of panelVisibility.features) {
feature.value = feature.default;
}
}
export function isOptionalFeatureEnabled(propertyName: string): boolean {
for (let feature of panelVisibility.features) {
if (feature.propertyName === propertyName) {
return feature.value;
}
}
return false;
}
// Override default settings for each feature based on workspace current information
async function updateOptionalFeaturesWithWorkspace(): Promise<void> {
// optionalFeatures will be set with default values.
// override with values from the workspace
let features: MakefilePanelVisibility | undefined =
(await util.getExpandedSetting<MakefilePanelVisibility>(
"panel.visibility"
)) || undefined;
if (features) {
if (Object.entries(features).length < panelVisibility.features.length) {
// At least one feature is missing from the settings, which means we need to use defaults.
// If we don't refresh defaults here, we won't cover the following scenario:
// - default TRUE feature
// - which was set to false in the settings, causing knownFeature.value to be false
// - just got removed from settings now, meaning it won't be included in the features varibale and the FOR won't loop through it
// giving it no opportunity to switch .value back to the default of TRUE.
initOptionalFeatures();
}
for (let propEntry of Object.entries(features)) {
for (let knownFeature of panelVisibility.features) {
if (propEntry[0] === knownFeature.propertyName) {
knownFeature.value = propEntry[1];
}
}
}
} else {
initOptionalFeatures(); // no info in workspace, use defaults
}
}
export function disableAllOptionallyVisibleCommands(): void {
for (let feature of panelVisibility.features) {
if (feature.enablement) {
vscode.commands.executeCommand("setContext", feature.enablement, false);
}
}
}
function enableOptionallyVisibleCommands(): void {
for (let feature of panelVisibility.features) {
if (feature.enablement) {
vscode.commands.executeCommand(
"setContext",
feature.enablement,
feature.value
);
}
}
}
async function readFeaturesVisibility(): Promise<void> {
await updateOptionalFeaturesWithWorkspace();
}
let makePath: string | undefined;
export function getMakePath(): string | undefined {
return makePath;
}
export function setMakePath(path: string): void {
makePath = path;
}
// Read the path (full or directory only) of the make tool if defined in settings.
// It represents a default to look for if no other path is already included
// in "makefile.configurations.makePath".
async function readMakePath(): Promise<void> {
makePath = await util.getExpandedSetting<string>("makePath");
if (!makePath) {
logger.message(
localize(
"no.make.tool.defined",
"No path to the make tool is defined in the settings file."
)
);
}
}
let makefilePath: string | undefined;
export function getMakefilePath(): string | undefined {
return makefilePath;
}
export function setMakefilePath(path: string): void {
makefilePath = path;
}
// Read the full path to the makefile if defined in settings.
// It represents a default to look for if no other makefile is already provided
// in makefile.configurations.makefilePath.
// TODO: validate and integrate with "-f [Makefile]" passed in makefile.configurations.makeArgs.
async function readMakefilePath(): Promise<void> {
makefilePath = await util.getExpandedSetting<string>("makefilePath");
if (!makefilePath) {
logger.message(
localize(
"no.makefile.defined.in.settings",
"No path to the makefile is defined in the settings file."
)
);
} else {
makefilePath = util.resolvePathToRoot(makefilePath);
}
}
let makeDirectory: string | undefined;
export function getMakeDirectory(): string | undefined {
return makeDirectory;
}
export function setMakeDirectory(dir: string): void {
makeDirectory = dir;
}
// Read the make working directory path if defined in settings.
// It represents a default to look for if no other makeDirectory is already provided
// in makefile.configurations.makeDirectory.
// TODO: validate and integrate with "-C [DIR_PATH]" passed in makefile.configurations.makeArgs.
async function readMakeDirectory(): Promise<void> {
makeDirectory = await util.getExpandedSetting<string>("makeDirectory");
if (!makeDirectory) {
logger.message(
localize(
"no.folder.path.defined.in.settings",
"No folder path to the makefile is defined in the settings file."
)
);
} else {
makeDirectory = util.resolvePathToRoot(makeDirectory);
}
}
// Command property accessible from launch.json:
// the folder in which the current "make" invocation operates:
// passed with -C (otherwise it is the workspace folder).
// Note: -f does not change the current working directory. It only points to a makefile somewhere else.
export function makeBaseDirectory(): string {
// In case more than one -C arguments are given to "make", it will chose the last one.
// getConfigurationMakeArgs will contain the final command we calculate for the "make" executable.
// We don't need to know here which -C gets pushed last (global makeDirectory,
// configuration local makeDirectory or one in makeArgs). Just reverse to easily get the last one.
const makeArgs: string[] = getConfigurationMakeArgs().concat().reverse();
let prevArg: string = "";
for (const arg of makeArgs) {
if (arg === "-C") {
return prevArg;
} else if (arg.startsWith("--directory")) {
const eqIdx: number = arg.indexOf("=");
return arg.substring(eqIdx + 1, arg.length);
}
// Since we reversed the "make" command line arguments, the path of a -C will be seen before the switch.
// Remember every previous argument to have it available in case we find the first -C.
prevArg = arg;
}
return util.getWorkspaceRoot();
}
let buildLog: string | undefined;
export function getBuildLog(): string | undefined {
return buildLog;
}
export function setBuildLog(path: string): void {
buildLog = path;
}
// Read from settings the path of the build log that is desired to be parsed
// instead of a dry-run command output.
// Useful for complex, tricky and corner case repos for which make --dry-run
// is not working as the extension expects.
// Example: --dry-run actually running configure commands, instead of only displaying them,
// possibly changing unexpectedly a previous configuration set by the repo developer.
// This scenario may also result in infinite loop, depending on how the makefile
// and the configuring process are written, thus making the extension unusable.
// Defining a build log to be parsed instead of a dry-run output represents a good alternative.
// Also useful for developing unit tests based on real world code,
// that would not clone a whole repo for testing.
// It is recommended to produce the build log with all the following commands,
// so that the extension has the best content to operate on.
// --always-make (to make sure no target is skipped because it is up to date)
// --keep-going (to not stumble on the first error)
// --print-data-base (special verbose printing which this extension is using for parsing the makefile targets)
// If any of the above switches is missing, the extension may have less log to parse from,
// therefore offering less intellisense information for source files,
// identifying less possible binaries to debug or not providing any makefile targets (other than the 'all' default).
export async function readBuildLog(): Promise<boolean> {
buildLog = await util.getExpandedSetting<string>("buildLog");
if (buildLog) {
buildLog = util.resolvePathToRoot(buildLog);
logger.message(
localize("build.log.defined.at", 'Build log defined at "{0}"', buildLog)
);
if (!util.checkFileExistsSync(buildLog)) {
logger.message(
localize("build.log.not.found.disk", "Build log not found on disk.")
);
return false;
}
}
return true;
}
let loggingLevel: string | undefined;
export function getLoggingLevel(): string | undefined {
return loggingLevel;
}
export function setLoggingLevel(logLevel: string): void {
loggingLevel = logLevel;
}
// Read from settings the desired logging level for the Makefile Tools extension.
export async function readLoggingLevel(): Promise<void> {
loggingLevel =
(await util.getExpandedSetting<string>("loggingLevel")) || "Normal";
logger.message(localize("logging.level", "Logging level: {0}", loggingLevel));
}
let extensionOutputFolder: string | undefined;
export function getExtensionOutputFolder(): string | undefined {
return extensionOutputFolder;
}
export function setExtensionOutputFolder(folder: string): void {
extensionOutputFolder = folder;
}
// Read from settings the path to a folder where the extension is dropping various output files
// (like extension.log, dry-run.log, targets.log).
// Useful to control where such potentially large files should reside.
export async function readExtensionOutputFolder(): Promise<void> {
extensionOutputFolder = await util.getExpandedSetting<string>(
"extensionOutputFolder"
);
if (extensionOutputFolder) {
extensionOutputFolder = util.resolvePathToRoot(extensionOutputFolder);
} else {
extensionOutputFolder = extension.extensionContext.storagePath;
}
// Check one more time because the value can still be undefined if no folder was opened.
if (extensionOutputFolder) {
if (!util.checkDirectoryExistsSync(extensionOutputFolder)) {
if (!util.createDirectorySync(extensionOutputFolder)) {
extensionOutputFolder = extension.extensionContext.storagePath;
logger.message(
localize(
"extension.output.folder.does.not.exist.no.creation",
"Extension output folder does not exist and could not be created: {0}.",
extensionOutputFolder
)
);
logger.message(
localize(
"reverting.to.default.output.folder",
"Reverting to '{0}' default for extension output folder.",
extensionOutputFolder
)
);
return;
}
}
logger.message(
localize(
"dropping.various.extension.output.files",
"Dropping various extension output files at {0}",
extensionOutputFolder
)
);
}
}
let extensionLog: string | undefined;
export function getExtensionLog(): string | undefined {
return extensionLog;
}
export function setExtensionLog(path: string): void {
extensionLog = path;
}
// Read from settings the path to a log file capturing all the "Makefile Tools" output channel content.
// Useful for very large repos, which would produce with a single command a log larger
// than the "Makefile Tools" output channel capacity.
// Also useful for developing unit tests based on real world code,
// that would not clone a whole repo for testing.
// If an extension log is specified, its content is cleared during activation.
// Any messages that are being logged throughout the lifetime of the extension
// are going to be appended to this file.
export async function readExtensionLog(): Promise<void> {
extensionLog = await util.getExpandedSetting<string>("extensionLog");
if (extensionLog) {
// If there is a directory defined within the extension log path,
// honor it and don't append to extensionOutputFolder.
let parsePath: path.ParsedPath = path.parse(extensionLog);
if (extensionOutputFolder && !parsePath.dir) {
extensionLog = path.join(extensionOutputFolder, extensionLog);
} else {
extensionLog = util.resolvePathToRoot(extensionLog);
}
logger.message(
localize(
"writing.extension.log",
"Writing extension log at {0}",
extensionLog
)
);
}
}
let preConfigureScript: string | undefined;
export function getPreConfigureScript(): string | undefined {
return preConfigureScript;
}
export function setPreConfigureScript(path: string): void {
preConfigureScript = path;
}
let preConfigureArgs: string[] = [];
export function getPreConfigureArgs(): string[] {
return preConfigureArgs;
}
export function setPreConfigureArgs(args: string[]): void {
preConfigureArgs = args;
}
let postConfigureScript: string | undefined;
export function getPostConfigureScript(): string | undefined {
return postConfigureScript;
}
export function setPostConfigureScript(path: string): void {
postConfigureScript = path;
}
let postConfigureArgs: string[] = [];
export function getPostConfigureArgs(): string[] {
return postConfigureArgs;
}
export function setPostConfigureArgs(args: string[]): void {
postConfigureArgs = args;
}
// Read from settings the path to a script file that needs to have been run at least once
// before a sucessful configure of this project.
export async function readPreConfigureScript(): Promise<void> {
preConfigureScript = await util.getExpandedSetting<string>(
"preConfigureScript"
);
if (preConfigureScript) {
preConfigureScript = util.resolvePathToRoot(preConfigureScript);
logger.message(
localize(
"found.preconfigure.script",
"Found pre-configure script defined as {0}",
preConfigureScript
)
);
if (!util.checkFileExistsSync(preConfigureScript)) {
logger.message(
localize(
"preconfigure.script.not.found.on.disk",
"Pre-configure script not found on disk."
)
);
}
}
}
export async function readPreConfigureArgs(): Promise<void> {
preConfigureArgs =
(await util.getExpandedSetting<string[]>("preConfigureArgs")) ?? [];
if (preConfigureArgs && preConfigureArgs.length > 0) {
logger.message(
localize(
"preconfigure.arguments",
"Pre-configure arguments: '{0}'",
preConfigureArgs.join("', '")
)
);
}
}
export async function readPostConfigureScript(): Promise<void> {
postConfigureScript = await util.getExpandedSetting<string>(
"postConfigureScript"
);
if (postConfigureScript) {
postConfigureScript = util.resolvePathToRoot(postConfigureScript);
logger.message(
localize(
"post.configure.script.defined.as",
"Found post-configure script defined as {0}",
postConfigureScript
)
);
if (!util.checkFileExistsSync(postConfigureScript)) {
logger.message(
localize(
"post.configure.not.found.on.disk",
"Post-configure script not found on disk"
)
);
}
}
}
export async function readPostConfigureArgs(): Promise<void> {
postConfigureArgs =
(await util.getExpandedSetting<string[]>("postConfigureArgs")) ?? [];
if (postConfigureArgs && postConfigureArgs.length > 0) {
logger.message(
localize(
"post.configure.arguments.listed",
"Post-configure arguments: '{0}'",
postConfigureArgs.join("', '")
)
);
}
}
let alwaysPreConfigure: boolean | undefined;
export function getAlwaysPreConfigure(): boolean | undefined {
return alwaysPreConfigure;
}
export function setAlwaysPreConfigure(path: boolean): void {
alwaysPreConfigure = path;
}
let alwaysPostConfigure: boolean | undefined;
export function getAlwaysPostConfigure(): boolean | undefined {
return alwaysPostConfigure;
}
export function setAlwaysPostConfigure(path: boolean): void {
alwaysPostConfigure = path;
}
// Read from settings whether the pre-configure step is supposed to be executed
// always before the configure operation.
export async function readAlwaysPreConfigure(): Promise<void> {
alwaysPreConfigure = await util.getExpandedSetting<boolean>(
"alwaysPreConfigure"
);
logger.message(
localize(
"always.pre.configure",
"Always pre-configure: {0}",
alwaysPreConfigure
)
);
}
export async function readAlwaysPostConfigure(): Promise<void> {
alwaysPostConfigure = await util.getExpandedSetting<boolean>(
"alwaysPostConfigure"
);
logger.message(
localize(
"always.post.configure",
"Always post-configure: {0}",
alwaysPostConfigure
)
);
}
let configurationCachePath: string | undefined;
export function getConfigurationCachePath(): string | undefined {
return configurationCachePath;
}
export function setConfigurationCachePath(path: string): void {
configurationCachePath = path;
}
// Read from settings the path to a cache file containing the output of the last dry-run make command.
// This file is recreated when opening a project, when changing the build configuration or the build target
// and when the settings watcher detects a change of any properties that may impact the dryrun output.
export async function readConfigurationCachePath(): Promise<void> {
let oldConfigurationCachePath = configurationCachePath;
configurationCachePath = await util.getExpandedSetting<string>(
"configurationCachePath"
);
if (!configurationCachePath && extensionOutputFolder) {
configurationCachePath = path.join(
extensionOutputFolder,
"configurationCache.log"
);
}
if (configurationCachePath) {
// If there is a directory defined within the configuration cache path,
// honor it and don't append to extensionOutputFolder.
let parsePath: path.ParsedPath = path.parse(configurationCachePath);
if (extensionOutputFolder && !parsePath.dir) {
configurationCachePath = path.join(
extensionOutputFolder,
configurationCachePath
);
} else {
configurationCachePath = util.resolvePathToRoot(configurationCachePath);
}
if (oldConfigurationCachePath !== configurationCachePath) {
logger.message(
localize(
"configurations.cached",
"Configurations cached at {0}",
configurationCachePath
)
);
}
}
}
let compileCommandsPath: string | undefined;
export function getCompileCommandsPath(): string | undefined {
return compileCommandsPath;
}
export function setCompileCommandsPath(path: string): void {
compileCommandsPath = path;
}
export async function readCompileCommandsPath(): Promise<void> {
compileCommandsPath = await util.getExpandedSetting<string>(
"compileCommandsPath"
);
if (compileCommandsPath) {
compileCommandsPath = util.resolvePathToRoot(compileCommandsPath);
}
logger.message(
localize(
"compile.commands.json.path",
"compile_commands.json path: {0}",
compileCommandsPath
)
);
}
let additionalCompilerNames: string[] | undefined;
export function getAdditionalCompilerNames(): string[] | undefined {
return additionalCompilerNames;
}
export function setAdditionalCompilerNames(compilerNames: string[]): void {
additionalCompilerNames = compilerNames;
}
export async function readAdditionalCompilerNames(): Promise<void> {
additionalCompilerNames = await util.getExpandedSetting<string[]>(
"additionalCompilerNames"
);
if (additionalCompilerNames && additionalCompilerNames.length > 0) {
logger.message(
localize(
"additional.compiler.names",
"Additional compiler names: '{0}'",
additionalCompilerNames?.join("', '")
)
);
}
}
let excludeCompilerNames: string[] | undefined;
export function getExcludeCompilerNames(): string[] | undefined {
return excludeCompilerNames;
}
export function setExcludeCompilerNames(compilerNames: string[]): void {
excludeCompilerNames = compilerNames;
}
export async function readExcludeCompilerNames(): Promise<void> {
excludeCompilerNames = await util.getExpandedSetting<string[]>(
"excludeCompilerNames"
);
if (excludeCompilerNames && excludeCompilerNames.length > 0) {
logger.message(
localize(
"exclude.compiler.names",
"Exclude compiler names: '{0}'",
excludeCompilerNames?.join("', '")
)
);
}
}
let safeCommands: string[] | undefined;
export function getSafeCommands(): string[] | undefined {
return safeCommands;
}
export function setSafeCommands(commands: string[]): void {
safeCommands = commands;
}
export async function readSafeCommands(): Promise<void> {
safeCommands = await util.getExpandedSetting<string[]>("safeCommands");
if (safeCommands && safeCommands.length > 0) {
logger.message(
localize(
"safe.commands",
"Safe commands: '{0}'",
safeCommands?.join("', '")
),
"Debug"
);
}
}
let dryrunSwitches: string[] | undefined;
export function getDryrunSwitches(): string[] | undefined {
return dryrunSwitches;
}
export function setDryrunSwitches(switches: string[]): void {
dryrunSwitches = switches;
}
// Read from settings the dry-run switches array. If there is no user definition, the defaults are:
// --always-make: to not skip over up-to-date targets
// --keep-going: to not stop at the first error that is encountered
// --print-data-base: to generate verbose log output that can be parsed to identify all the makefile targets
// Some code bases have various issues with the above make parameters: infrastructure (not build) errors,
// infinite reconfiguration loops, resulting in the extension being unusable.
// To work around this, the setting makefile.dryrunSwitches is providing a way to skip over the problematic make arguments,
// even if this results in not ideal behavior: less information available to be parsed, which leads to incomplete IntelliSense or missing targets.
export async function readDryrunSwitches(): Promise<void> {
dryrunSwitches = await util.getExpandedSetting<string[]>("dryrunSwitches");
if (dryrunSwitches && dryrunSwitches.length > 0) {
logger.message(
localize(
"dry.run.switches",
"Dry-run switches: '{0}'",
dryrunSwitches?.join("', '")
)
);
}
}
// Currently, the makefile extension supports debugging only an executable.
// TODO: Parse for symbol search paths
// TODO: support dll debugging.
export interface LaunchConfiguration {
// The following properties constitute a minimal launch configuration object.
// They all can be deduced from the dry-run output or build log.
// When the user is selecting a launch configuration, the extension is verifying
// whether there is an entry in the launch configurations array in settings
// and if not, it is generating a new one with the values computed by the parser.
binaryPath: string; // full path to the binary that this launch configuration is tied to
binaryArgs: string[]; // arguments that this binary is called with for this launch configuration
cwd: string; // folder from where the binary is run
// The following represent optional properties that can be additionally defined by the user in settings.
MIMode?: string;
miDebuggerPath?: string;
stopAtEntry?: boolean;
symbolSearchPath?: string;
}
let launchConfigurations: LaunchConfiguration[] = [];
export function getLaunchConfigurations(): LaunchConfiguration[] {
return launchConfigurations;
}
export function setLaunchConfigurations(
configurations: LaunchConfiguration[]
): void {
launchConfigurations = configurations;
}
// Read launch configurations defined by the user in settings: makefile.launchConfigurations[]
async function readLaunchConfigurations(): Promise<void> {
launchConfigurations =
(await util.getExpandedSetting<LaunchConfiguration[]>(
"launchConfigurations"
)) || [];
}
// Helper used to fill the launch configurations quick pick.
// The input object for this method is either read from the settings or it is an object
// constructed by the parser while analyzing the dry-run output (or the build log),
// when the extension is trying to determine if and how (from what folder, with what arguments)
// the makefile is invoking any of the programs that are built by the current target.
// Properties other than cwd, binary path and args could be manually defined by the user
// in settings (after the extension creates a first minimal launch configuration object) and are not relevant
// for the strings being used to populate the quick pick.
// Syntax:
// [CWD path]>[binaryPath]([binaryArg1,binaryArg2,binaryArg3,...])
export function launchConfigurationToString(
configuration: LaunchConfiguration
): string {
let binPath: string = util.makeRelPath(
configuration.binaryPath,
configuration.cwd
);
let binArgs: string = configuration.binaryArgs.join(",");
return `${configuration.cwd}>${binPath}(${binArgs})`;
}
// Helper used to construct a minimal launch configuration object
// (only cwd, binary path and arguments) from a string that respects
// the syntax of its quick pick.
export async function stringToLaunchConfiguration(
str: string
): Promise<LaunchConfiguration | undefined> {
let regexp: RegExp = /(.*)\>(.*)\((.*)\)/gm;
let match: RegExpExecArray | null = regexp.exec(str);
if (match) {
let fullPath: string = await util.makeFullPath(match[2], match[1]);
let splitArgs: string[] = match[3] === "" ? [] : match[3].split(",");
return {
cwd: match[1],
binaryPath: fullPath,
binaryArgs: splitArgs,
};
} else {
return undefined;
}
}
let currentLaunchConfiguration: LaunchConfiguration | undefined;
export function getCurrentLaunchConfiguration():
| LaunchConfiguration
| undefined {
return currentLaunchConfiguration;
}
export async function setCurrentLaunchConfiguration(
configuration: LaunchConfiguration | undefined
): Promise<void> {
currentLaunchConfiguration = configuration;
let launchConfigStr: string = currentLaunchConfiguration
? launchConfigurationToString(currentLaunchConfiguration)
: "";
statusBar.setLaunchConfiguration(launchConfigStr);
await extension._projectOutlineProvider.updateLaunchTarget(launchConfigStr);
}
function getLaunchConfiguration(name: string): LaunchConfiguration | undefined {
return launchConfigurations.find((k) => {
if (launchConfigurationToString(k) === name) {
return { ...k, keep: true };
}
});
}
// Construct the current launch configuration object:
// Read the identifier from workspace state storage, then find the corresponding object
// in the launch configurations array from settings.
// Also update the status bar item.
async function readCurrentLaunchConfiguration(): Promise<void> {
await readLaunchConfigurations();
let currentLaunchConfigurationName: string | undefined =
extension.getState().launchConfiguration;
if (currentLaunchConfigurationName) {
currentLaunchConfiguration = getLaunchConfiguration(
currentLaunchConfigurationName
);
}
let launchConfigStr: string = "No launch configuration set.";
if (currentLaunchConfiguration) {
launchConfigStr = launchConfigurationToString(currentLaunchConfiguration);
logger.message(
localize(
"reading.current.launch.configuration",
'Reading current launch configuration "{0}" from the workspace state.',
launchConfigStr
)
);
} else {
// A null launch configuration after a non empty launch configuration string name
// means that the name stored in the project state does not match any of the entries in settings.
// This typically happens after the user modifies manually "makefile.launchConfigurations"
// in the .vscode/settings.json, specifically the entry that corresponds to the current launch configuration.
// Make sure to unset the launch configuration in this scenario.
if (
currentLaunchConfigurationName !== undefined &&
currentLaunchConfigurationName !== ""
) {
logger.message(
localize(
"launch.configuration.no.longer.defined.settings",
'Launch configuration "{0}" is no longer defined in settings "makefile.launchConfigurations".',
currentLaunchConfigurationName
)
);
await setLaunchConfigurationByName("");
} else {
logger.message(
localize(
"no.current.launch.configurations.in.state",
"No current launch configuration is set in the workspace state."
)
);
}
}
statusBar.setLaunchConfiguration(launchConfigStr);
await extension._projectOutlineProvider.updateLaunchTarget(launchConfigStr);
}
export interface DefaultLaunchConfiguration {
MIMode?: string;
miDebuggerPath?: string;
stopAtEntry?: boolean;
symbolSearchPath?: string;
}
let defaultLaunchConfiguration: DefaultLaunchConfiguration | undefined;
export function getDefaultLaunchConfiguration():
| DefaultLaunchConfiguration
| undefined {
return defaultLaunchConfiguration;
}
// No setter needed. Currently only the user can define makefile.defaultLaunchConfiguration
export async function readDefaultLaunchConfiguration(): Promise<void> {
defaultLaunchConfiguration =
await util.getExpandedSetting<DefaultLaunchConfiguration>(
"defaultLaunchConfiguration"
);
logger.message(
localize(
"default.launch.configuration",
"Default launch configuration: MIMode = {0},\n miDebuggerPath = {1},\n stopAtEntry = {2},\n symbolSearchPath = {3}",
defaultLaunchConfiguration?.MIMode,
defaultLaunchConfiguration?.miDebuggerPath,
defaultLaunchConfiguration?.stopAtEntry,
defaultLaunchConfiguration?.symbolSearchPath
)
);
}
// Command name and args are used when building from within the VS Code Makefile Tools Extension,
// when parsing all the targets that exist and when updating the cpptools configuration provider
// for IntelliSense.
let configurationMakeCommand: string;
export function getConfigurationMakeCommand(): string {
return configurationMakeCommand;
}
export function setConfigurationMakeCommand(name: string): void {
configurationMakeCommand = name;
}