Skip to content

Commit 1a6e1a9

Browse files
hanniavaleraHannia Valera
andauthored
Add Support for CMake Presets Version 11 (#4846)
* feat(presets): update to support version 11 and add validation tests - Increased max supported version from 10 to 11 in presetsParser. - Added schema handling for version 11 in presetsParser. - Introduced integration tests for version 10 and version 11 CMake presets. - Validated support for `$comment` and `graphviz` in version 10. - Confirmed rejection of `graphviz` in version 9. - Validated support for `jobs` field as an empty string in version 11. - Confirmed rejection of empty string `jobs` in version 10. * update schema URLs to version 11 and enhance job handling for execution * widen execution.jobs type to support string in TestPreset * refactor(presets): simplify TestPreset interface and update jobs handling --------- Co-authored-by: Hannia Valera <[email protected]>
1 parent ecb534d commit 1a6e1a9

8 files changed

Lines changed: 1934 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.23
44

55
Features:
6+
- Add support for CMake Presets version 11 (added in CMake 4.3). In test presets, the `execution.jobs` field can now be an empty string, equivalent to passing `--parallel` with no value.
67
- Automatically add new source files to `CMakeLists.txt` and remove deleted source files from `CMakeLists.txt`. Two new commands (`cmake.addFileToCMakeLists` and `cmake.removeFileFromCMakeLists`) and nine new `cmake.modifyLists.*` settings provide full control over target selection, variable handling, and confirmation behavior. [#2132](https://github.com/microsoft/vscode-cmake-tools/issues/2132) [#4454](https://github.com/microsoft/vscode-cmake-tools/pull/4454) [@malsyned](https://github.com/malsyned)
78
- Allow specifying a custom debug adapter type in `cmake.debugConfig` via the `type` property. When set, automatic debugger detection is skipped and any debug adapter (e.g., `codelldb`, `lldb`) can be used with arbitrary configuration properties. [#4818](https://github.com/microsoft/vscode-cmake-tools/pull/4818)
89
- Add `${cmake.testEnvironment}` placeholder for launch.json that resolves to the CTest `ENVIRONMENT` test property, and automatically include CTest environment variables when debugging tests without a launch configuration. [#4572](https://github.com/microsoft/vscode-cmake-tools/issues/4572) [#4821](https://github.com/microsoft/vscode-cmake-tools/pull/4821)

docs/cmake-presets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ We recommend `CMakePresets.json` as an alternative to kits and variants files. T
1414

1515
## Supported CMake and `CMakePresets.json` versions
1616

17-
The CMake Tools extension supports version 2 or later for the `CMakePresets.json` and `CMakeUserPresets.json` files. You can update your file version by incrementing the version field in the root object. For an example and more information, see [`CMakePresets.json`](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#format).
17+
The CMake Tools extension supports version 2 through 11 for the `CMakePresets.json` and `CMakeUserPresets.json` files. You can update your file version by incrementing the version field in the root object. For an example and more information, see [`CMakePresets.json`](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#format).
1818

1919
CMake version 3.20 or later is required when you're invoking CMake with `CMakePresets.json` (version 2 or later) from the command line. CMake Tools reads and evaluates `CMakePresets.json` and `CMakeUserPresets.json`. It doesn't invoke CMake directly with the `--preset` option. So, CMake version 3.20 or later isn't strictly required when you're building with `CMakePresets.json` inside Visual Studio Code. We recommend using CMake version 3.14 or later.
2020

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4395,11 +4395,11 @@
43954395
},
43964396
{
43974397
"fileMatch": "CMakePresets.json",
4398-
"url": "cmake-tools-schema://schemas/CMakePresets-v10-schema.json"
4398+
"url": "cmake-tools-schema://schemas/CMakePresets-v11-schema.json"
43994399
},
44004400
{
44014401
"fileMatch": "CMakeUserPresets.json",
4402-
"url": "cmake-tools-schema://schemas/CMakePresets-v10-schema.json"
4402+
"url": "cmake-tools-schema://schemas/CMakePresets-v11-schema.json"
44034403
}
44044404
]
44054405
},
@@ -4476,7 +4476,7 @@
44764476
"tsconfig-paths": "^3.11.0",
44774477
"tslint": "^6.1.3",
44784478
"typescript": "^4.1.5",
4479-
"vscode-cmake-tools": "^1.5.0",
4479+
"vscode-cmake-tools": "^1.6.0",
44804480
"vscode-nls-dev": "^3.3.2",
44814481
"webpack": "^5.104.1",
44824482
"webpack-cli": "^5.1.4"

schemas/CMakePresets-v11-schema.json

Lines changed: 1771 additions & 0 deletions
Large diffs are not rendered by default.

src/presets/preset.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,16 @@ export function testArgs(preset: TestPreset): string[] {
22972297
if (preset.execution) {
22982298
preset.execution.stopOnFailure && result.push('--stop-on-failure');
22992299
preset.execution.enableFailover && result.push('-F');
2300-
(preset.execution.jobs !== undefined) && result.push('--parallel', preset.execution.jobs.toString());
2300+
if (preset.execution.jobs !== undefined) {
2301+
// v11+: jobs can be an empty string meaning --parallel with no value (auto-detect).
2302+
// The API type currently declares jobs as number; will be updated to number | string.
2303+
const jobs = preset.execution.jobs as number | string;
2304+
if (jobs === '') {
2305+
result.push('--parallel');
2306+
} else {
2307+
result.push('--parallel', jobs.toString());
2308+
}
2309+
}
23012310
preset.execution.resourceSpecFile && result.push('--resource-spec-file', preset.execution.resourceSpecFile);
23022311
preset.execution.testLoad && result.push('--test-load', preset.execution.testLoad.toString());
23032312
preset.execution.showOnly && result.push('--show-only', preset.execution.showOnly);

src/presets/presetsParser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class PresetsParser {
154154
)
155155
);
156156
let schemaFile;
157-
const maxSupportedVersion = 10;
157+
const maxSupportedVersion = 11;
158158
const validationErrorsAreWarnings =
159159
presetsFile.version > maxSupportedVersion &&
160160
allowUnsupportedPresetsVersions;
@@ -176,8 +176,11 @@ export class PresetsParser {
176176
} else if (presetsFile.version === 8 || presetsFile.version === 9) {
177177
// This can be used for v9 as well, there is no schema difference.
178178
schemaFile = "./schemas/CMakePresets-v8-schema.json";
179-
} else {
179+
} else if (presetsFile.version === 10) {
180180
schemaFile = "./schemas/CMakePresets-v10-schema.json";
181+
} else {
182+
// v11+
183+
schemaFile = "./schemas/CMakePresets-v11-schema.json";
181184
}
182185

183186
const validator = await loadSchema(schemaFile);

test/integration-tests/presets/validation.test.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,145 @@ suite('Presets validation, inclusion, and expansion tests', () => {
881881
expect(preset.packagePresets(sourceDirectory).length).to.be.equal(1);
882882
expect(preset.workflowPresets(sourceDirectory).length).to.be.equal(1);
883883
}).timeout(100000);
884+
885+
const version10SupportedPresets: any = {
886+
"version": 10,
887+
"$comment": "This is a top-level comment",
888+
"configurePresets": [
889+
{
890+
"$comment": "Comment on configure preset",
891+
"name": "configure",
892+
"hidden": false,
893+
"generator": "Ninja",
894+
"installDir": "${workspaceFolder}/install",
895+
"condition": {
896+
"type": "equals",
897+
"lhs": "${hostSystemName}",
898+
"rhs": "Windows"
899+
},
900+
"toolchainFile": "",
901+
"trace": {},
902+
"graphviz": "${sourceDir}/build/deps.dot"
903+
}
904+
],
905+
"buildPresets": [
906+
{
907+
"name": "x64-debug",
908+
"configurePreset": "configure",
909+
"cleanFirst": true,
910+
"resolvePackageReferences": "on"
911+
}
912+
],
913+
"testPresets": [
914+
{
915+
"name": "x64-debug",
916+
"configurePreset": "configure",
917+
"output": {
918+
"testOutputTruncation": "tail"
919+
}
920+
}
921+
],
922+
"packagePresets": [
923+
{
924+
"name": "x64-debug-package"
925+
}
926+
],
927+
"workflowPresets": [
928+
{
929+
"name": "x64-debug-workflow",
930+
"steps": [
931+
{
932+
"type": "configure",
933+
"name": "configure"
934+
}
935+
]
936+
}
937+
]
938+
};
939+
940+
/**
941+
* Validate v10 supports `$comment` at any level and `graphviz` on configure presets.
942+
* Then confirm that `graphviz` is rejected on v9.
943+
*/
944+
test('Validate version 10 CMake Presets', async () => {
945+
fs.writeFileSync(presetsParser.presetsPath,
946+
JSON.stringify(version10SupportedPresets));
947+
948+
await presetsParser.resetPresetsFiles(
949+
new Map<string, PresetsFile>(),
950+
false,
951+
false
952+
);
953+
954+
expect(presetsFileErrors).to.have.lengthOf(0);
955+
expect(preset.configurePresets(sourceDirectory).length).to.be.equal(1);
956+
expect(preset.buildPresets(sourceDirectory).length).to.be.equal(1);
957+
expect(preset.testPresets(sourceDirectory).length).to.be.equal(1);
958+
expect(preset.packagePresets(sourceDirectory).length).to.be.equal(1);
959+
expect(preset.workflowPresets(sourceDirectory).length).to.be.equal(1);
960+
961+
// Confirm graphviz is NOT allowed in v9
962+
const v9WithGraphviz = lodash.cloneDeep(version10SupportedPresets);
963+
v9WithGraphviz.version = 9;
964+
delete v9WithGraphviz["$comment"];
965+
delete v9WithGraphviz.configurePresets[0]["$comment"];
966+
967+
fs.writeFileSync(presetsParser.presetsPath,
968+
JSON.stringify(v9WithGraphviz));
969+
970+
await presetsParser.resetPresetsFiles(
971+
new Map<string, PresetsFile>(),
972+
false,
973+
false
974+
);
975+
976+
expect(presetsFileErrors.length).to.be.greaterThan(0);
977+
expect(presetsFileErrors.filter((e) => e.includes("graphviz"))).to.have.lengthOf(1);
978+
}).timeout(100000);
979+
980+
/**
981+
* Validate v11 supports the `jobs` field as an empty string in test preset execution.
982+
* Then confirm that an empty string `jobs` is rejected on v10.
983+
*/
984+
test('Validate version 11 CMake Presets', async () => {
985+
const v11Presets: any = lodash.cloneDeep(version10SupportedPresets);
986+
v11Presets.version = 11;
987+
v11Presets.testPresets[0].execution = {
988+
"jobs": ""
989+
};
990+
991+
fs.writeFileSync(presetsParser.presetsPath,
992+
JSON.stringify(v11Presets));
993+
994+
await presetsParser.resetPresetsFiles(
995+
new Map<string, PresetsFile>(),
996+
false,
997+
false
998+
);
999+
1000+
expect(presetsFileErrors).to.have.lengthOf(0);
1001+
expect(preset.configurePresets(sourceDirectory).length).to.be.equal(1);
1002+
expect(preset.buildPresets(sourceDirectory).length).to.be.equal(1);
1003+
expect(preset.testPresets(sourceDirectory).length).to.be.equal(1);
1004+
expect(preset.packagePresets(sourceDirectory).length).to.be.equal(1);
1005+
expect(preset.workflowPresets(sourceDirectory).length).to.be.equal(1);
1006+
1007+
// Confirm that empty string `jobs` is rejected on v10
1008+
const v10WithStringJobs: any = lodash.cloneDeep(v11Presets);
1009+
v10WithStringJobs.version = 10;
1010+
1011+
fs.writeFileSync(presetsParser.presetsPath,
1012+
JSON.stringify(v10WithStringJobs));
1013+
1014+
await presetsParser.resetPresetsFiles(
1015+
new Map<string, PresetsFile>(),
1016+
false,
1017+
false
1018+
);
1019+
1020+
expect(presetsFileErrors.length).to.be.greaterThan(0);
1021+
expect(presetsFileErrors.filter((e) => e.includes("jobs"))).to.have.lengthOf(1);
1022+
}).timeout(100000);
8841023
});
8851024

8861025
suite('Presets include field and CMakePresets+CMakeUserPresets', () => {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7843,10 +7843,10 @@ vinyl@^3.0.0, vinyl@^3.0.1:
78437843
replace-ext "^2.0.0"
78447844
teex "^1.0.1"
78457845

7846-
vscode-cmake-tools@^1.5.0:
7847-
version "1.5.0"
7848-
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"
7849-
integrity sha1-II0Vq0Nkhh97rRcoK7Tx1HU5JIo=
7846+
vscode-cmake-tools@^1.6.0:
7847+
version "1.6.0"
7848+
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cmake-tools/-/vscode-cmake-tools-1.6.0.tgz#cc2d373f54b68e6198f1de6589b1aa4e379f6def"
7849+
integrity sha1-zC03P1S2jmGY8d5libGqTjefbe8=
78507850

78517851
vscode-cpptools@^7.1.1:
78527852
version "7.1.1"

0 commit comments

Comments
 (0)