Skip to content

Commit 52b7a4c

Browse files
Expose presets info via API (#4532)
* Use shared API types for presets and expose preset getters * Replaced locally defined preset interfaces with those from the public API. * Moved internal-only fields into `*Private` interfaces to preserve encapsulation. * Added getter methods in CMakeProjectWrapper to expose configure, build, test, and package presets, and the useCMakePresets flag. * Improves maintainability by aligning internal structures with API definitions. Fixes: #4510 * update with telemetry * update api dependency * update versions * update changelog * update changelog * update version --------- Co-authored-by: Garrett Campbell <[email protected]> Co-authored-by: Garrett Campbell <[email protected]>
1 parent 7eb9513 commit 52b7a4c

File tree

6 files changed

+47
-133
lines changed

6 files changed

+47
-133
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Features:
1111
- Add a command to substitute CMake Cache variables in `launch.json` and `tasks.json`. [#4422](https://github.com/microsoft/vscode-cmake-tools/pull/4422)
1212
- Add support for presets v10. [#4459](https://github.com/microsoft/vscode-cmake-tools/issues/4459), [#4445](https://github.com/microsoft/vscode-cmake-tools/issues/4452)
1313
- Add pre-fill project name using current folder name [#4533](https://github.com/microsoft/vscode-cmake-tools/pull/4533) [@HO-COOH](https://github.com/HO-COOH)
14+
- Add API v5 which adds presets api. [#4510](https://github.com/microsoft/vscode-cmake-tools/issues/4510) [@OrkunTokdemir](https://github.com/OrkunTokdemir)
1415

1516
Improvements:
1617

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3848,7 +3848,7 @@
38483848
"tsconfig-paths": "^3.11.0",
38493849
"tslint": "^6.1.3",
38503850
"typescript": "^4.1.5",
3851-
"vscode-cmake-tools": "^1.3.0",
3851+
"vscode-cmake-tools": "^1.5.0",
38523852
"vscode-nls-dev": "^3.3.2",
38533853
"webpack": "^5.94.0",
38543854
"webpack-cli": "^4.5.0"

src/api.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { logEvent } from './telemetry';
1414
export class CMakeToolsApiImpl implements api.CMakeToolsApi {
1515
constructor(private readonly manager: ExtensionManager) {}
1616

17-
version: api.Version = api.Version.v4;
17+
version: api.Version = api.Version.v5;
1818

1919
showUIElement(element: api.UIElement): Promise<void> {
2020
logApiTelemetry('showUIElement');
@@ -74,6 +74,7 @@ class CMakeProjectWrapper implements api.Project {
7474
constructor(private readonly project: CMakeProject) {}
7575

7676
get codeModel() {
77+
logApiTelemetry('getCodeModel');
7778
return this.project.codeModelContent ?? undefined;
7879
}
7980

@@ -85,6 +86,31 @@ class CMakeProjectWrapper implements api.Project {
8586
return this.project.onSelectedConfigurationChangedApiEvent;
8687
}
8788

89+
get configurePreset() {
90+
logApiTelemetry('getConfigurePreset');
91+
return this.project.configurePreset ?? undefined;
92+
}
93+
94+
get buildPreset() {
95+
logApiTelemetry('getBuildPreset');
96+
return this.project.buildPreset ?? undefined;
97+
}
98+
99+
get testPreset() {
100+
logApiTelemetry('getTestPreset');
101+
return this.project.testPreset ?? undefined;
102+
}
103+
104+
get packagePreset() {
105+
logApiTelemetry('getPackagePreset');
106+
return this.project.packagePreset ?? undefined;
107+
}
108+
109+
get useCMakePresets() {
110+
logApiTelemetry('getUseCMakePresets');
111+
return this.project.useCMakePresets;
112+
}
113+
88114
configure(): Promise<void> {
89115
logApiTelemetry('configure');
90116
return withErrorCheck('configure', async () => (this.project.configure()));

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@ async function setup(context: vscode.ExtensionContext, progress?: ProgressHandle
24502450

24512451
return { getApi: (version: api.Version) => {
24522452
// Since our API is backwards compatible, we can make our version number match that which was requested.
2453-
if (version === api.Version.v1 || version === api.Version.v2 || version === api.Version.v3 || version === api.Version.v4) {
2453+
if (version === api.Version.v1 || version === api.Version.v2 || version === api.Version.v3 || version === api.Version.v4 || version === api.Version.v5) {
24542454
ext.api.version = version;
24552455
}
24562456
return ext.api;

src/presets/preset.ts

Lines changed: 13 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as nls from 'vscode-nls';
33
import * as path from 'path';
44
import * as vscode from "vscode";
55
import * as lodash from "lodash";
6+
import * as api from 'vscode-cmake-tools';
67

78
import * as util from '@cmt/util';
89
import * as logging from '@cmt/logging';
@@ -34,27 +35,16 @@ export interface PresetsFile {
3435

3536
export type VendorType = { [key: string]: any };
3637

37-
export interface Preset {
38-
name: string;
39-
displayName?: string;
40-
description?: string;
41-
hidden?: boolean;
42-
inherits?: string | string[];
43-
environment?: EnvironmentWithNull;
44-
vendor?: VendorType;
45-
condition?: Condition | boolean | null;
46-
isUserPreset?: boolean;
47-
38+
export interface PresetPrivate {
4839
__parentEnvironment?: EnvironmentWithNull; // Private field that contains the parent environment, which might be a modified VS Dev Env, or simply process.env.
4940
__expanded?: boolean; // Private field to indicate if we have already expanded this preset.
5041
__inheritedPresetCondition?: boolean; // Private field to indicate the fully evaluated inherited preset condition.
5142
__file?: PresetsFile; // Private field to indicate the file where this preset was defined.
5243
}
44+
export interface Preset extends api.Preset, PresetPrivate {}
5345

54-
export interface ValueStrategy {
55-
value?: string;
56-
strategy?: 'set' | 'external';
57-
}
46+
export type ValueStrategy = api.ValueStrategy;
47+
export type CacheVarType = api.CacheVarType;
5848

5949
export interface WarningOptions {
6050
dev?: boolean;
@@ -86,13 +76,6 @@ enum FormatMode {
8676
Json = "json-v1"
8777
}
8878

89-
export interface TraceOptions {
90-
mode?: string;
91-
format?: string;
92-
source?: string[];
93-
redirect: string;
94-
}
95-
9679
export interface Condition {
9780
type: 'const' | 'equals' | 'notEquals' | 'inList' | 'notInList' | 'matches' | 'notMatches' | 'anyOf' | 'allOf' | 'not';
9881
value?: boolean;
@@ -235,8 +218,6 @@ export function evaluatePresetCondition(preset: Preset, allPresets: Preset[], re
235218
return undefined;
236219
}
237220

238-
export type CacheVarType = null | boolean | string | { type: string; value: boolean | string };
239-
240221
export type OsName = "Windows" | "Linux" | "macOS";
241222

242223
export type VendorVsSettings = {
@@ -247,45 +228,19 @@ export type VendorVsSettings = {
247228
[key: string]: any;
248229
};
249230

250-
export interface ConfigurePreset extends Preset {
251-
generator?: string;
252-
architecture?: string | ValueStrategy;
253-
toolset?: string | ValueStrategy;
254-
binaryDir?: string;
255-
cmakeExecutable?: string;
256-
// Make the cache value to be possibly undefined for type checking
257-
cacheVariables?: { [key: string]: CacheVarType | undefined };
258-
warnings?: WarningOptions;
259-
errors?: ErrorOptions;
260-
debug?: DebugOptions;
261-
trace?: TraceOptions;
262-
vendor?: VendorVsSettings | VendorType;
263-
toolchainFile?: string;
264-
installDir?: string;
265-
graphviz?: string;
266-
231+
export interface ConfigurePreset extends PresetPrivate, api.ConfigurePreset {
267232
// Private fields
268233
__developerEnvironmentArchitecture?: string; // Private field to indicate which VS Dev Env architecture we're using, if VS Dev Env is used.
269234
}
270235

271-
export interface InheritsConfigurePreset extends Preset {
272-
configurePreset?: string;
273-
inheritConfigureEnvironment?: boolean; // Defaults to true
274-
}
275-
276-
export interface BuildPreset extends InheritsConfigurePreset {
277-
jobs?: number;
278-
targets?: string | string[];
279-
configuration?: string;
280-
cleanFirst?: boolean;
281-
verbose?: boolean;
282-
nativeToolOptions?: string[];
236+
export interface InheritsConfigurePreset extends api.InheritsConfigurePreset, PresetPrivate {}
283237

284-
// Private fields
238+
export interface BuildPresetPrivate {
285239
__binaryDir?: string; // Getting this from the config preset
286240
__generator?: string; // Getting this from the config preset
287241
__targets?: string | string[]; // This field is translated to build args, so we can overwrite the target arguments.
288242
}
243+
export interface BuildPreset extends api.BuildPreset, BuildPresetPrivate, PresetPrivate {}
289244

290245
/**
291246
* Should NOT cache anything. Need to make a copy if any fields need to be changed.
@@ -296,86 +251,18 @@ export const defaultBuildPreset: BuildPreset = {
296251
description: localize('default.build.preset.description', 'An empty build preset that does not add any arguments')
297252
};
298253

299-
export interface OutputOptions {
300-
shortProgress?: boolean;
301-
verbosity?: 'default' | 'verbose' | 'extra';
302-
debug?: boolean;
303-
outputOnFailure?: boolean;
304-
quiet?: boolean;
305-
outputLogFile?: string;
306-
outputJUnitFile?: string;
307-
labelSummary?: boolean;
308-
subprojectSummary?: boolean;
309-
maxPassedTestOutputSize?: number;
310-
maxFailedTestOutputSize?: number;
311-
testOutputTruncation?: 'tail' | 'heads' | 'middle';
312-
maxTestNameWidth?: number;
313-
}
314-
315-
export interface IncludeFilter {
316-
name?: string;
317-
label?: string;
318-
useUnion?: boolean;
319-
index?: string | { start?: number; end?: number; stride?: number; specificTests?: number[] };
320-
}
321-
322-
export interface ExcludeFilter {
323-
name?: string;
324-
label?: string;
325-
fixtures?: { any?: string; setup?: string; cleanup?: string };
326-
}
327-
328-
export interface TestFilter {
329-
include?: IncludeFilter;
330-
exclude?: ExcludeFilter;
331-
}
332-
333-
export interface ExecutionOptions {
334-
stopOnFailure?: boolean;
335-
enableFailover?: boolean;
336-
jobs?: number;
337-
resourceSpecFile?: string;
338-
testLoad?: number;
339-
showOnly?: 'human' | 'json-v1';
340-
repeat?: { mode: 'until-fail' | 'until-pass' | 'after-timeout'; count: number };
341-
interactiveDebugging?: boolean;
342-
scheduleRandom?: boolean;
343-
timeout?: number;
344-
noTestsAction?: 'default' | 'error' | 'ignore';
345-
}
346-
347-
export interface TestPreset extends InheritsConfigurePreset {
348-
configuration?: string;
349-
overwriteConfigurationFile?: string[];
350-
output?: OutputOptions;
351-
filter?: TestFilter;
352-
execution?: ExecutionOptions;
353-
354-
// Private fields
254+
export interface TestPresetPrivate {
355255
__binaryDir?: string; // Getting this from the config preset
356256
__generator?: string; // Getting this from the config preset
357257
}
358258

359-
export interface PackageOutputOptions {
360-
debug?: boolean;
361-
verbose?: boolean;
362-
}
363-
364-
export interface PackagePreset extends InheritsConfigurePreset {
365-
configurations?: string[];
366-
generators?: string[];
367-
variables?: { [key: string]: string | null | undefined };
368-
configFile?: string;
369-
output?: PackageOutputOptions;
370-
packageName?: string;
371-
packageVersion?: string;
372-
packageDirectory?: string;
373-
vendorName?: string;
259+
export interface TestPreset extends api.TestPreset, TestPresetPrivate, PresetPrivate {}
374260

375-
// Private fields
261+
export interface PackagePresetPrivate {
376262
__binaryDir?: string; // Getting this from the config preset
377263
__generator?: string; // Getting this from the config preset
378264
}
265+
export interface PackagePreset extends api.PackagePreset, PackagePresetPrivate, PresetPrivate {}
379266

380267
export interface WorkflowStepsOptions {
381268
type: string;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7570,10 +7570,10 @@ vinyl@^2.0.0, vinyl@^2.1.0:
75707570
remove-trailing-separator "^1.0.1"
75717571
replace-ext "^1.0.0"
75727572

7573-
vscode-cmake-tools@^1.3.0:
7574-
version "1.3.0"
7575-
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cmake-tools/-/vscode-cmake-tools-1.3.0.tgz#f84707d77468cfcb34c386140eb62f966cccccc8"
7576-
integrity sha1-+EcH13Roz8s0w4YUDrYvlmzMzMg=
7573+
vscode-cmake-tools@^1.5.0:
7574+
version "1.5.0"
7575+
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cmake-tools/-/vscode-cmake-tools-1.5.0.tgz#208d15ab4364861f7bad17282bb4f1d47539248a"
7576+
integrity sha1-II0Vq0Nkhh97rRcoK7Tx1HU5JIo=
75777577

75787578
vscode-cpptools@^7.1.1:
75797579
version "7.1.1"

0 commit comments

Comments
 (0)