From 4c94e7d07872ee76a822c1376e508d74e7bca55f Mon Sep 17 00:00:00 2001 From: Daniel Brondani Date: Tue, 17 Nov 2026 14:14:50 +0100 Subject: [PATCH] [projmgr] Improve layer pattern validation in schema --- tools/projmgr/schemas/common.schema.json | 3 +- .../src/ProjMgrSchemaCheckerUnitTests.cpp | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tools/projmgr/schemas/common.schema.json b/tools/projmgr/schemas/common.schema.json index f9da9e9b8..ffb1f62b8 100644 --- a/tools/projmgr/schemas/common.schema.json +++ b/tools/projmgr/schemas/common.schema.json @@ -1147,7 +1147,8 @@ "layer": { "title": "layer:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#layers", "type": "string", - "description": "Path to the '*.clayer.yml' file that defines the layer." + "pattern": "^.*[/]([^.+]*\\.clayer\\.(yml|yaml))$|^([^.+]+)\\.clayer\\.(yml|yaml)$|^\\$[^$]+\\$$|^$", + "description": "Path to the valid layer file or layer variable. May be empty to leave the layer unspecified." }, "type": { "title": "type:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#layer-type", diff --git a/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp b/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp index 296dd022b..438bb327e 100644 --- a/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp @@ -52,6 +52,39 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Empty_Object) { EXPECT_TRUE(GetErrors().empty()); } +TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_LayerPattern) { + const vector> testCases = { + { "test.clayer.yml", true }, + { "test.clayer.yaml", true }, + { "../path.with+symbols/test.clayer.yml", true }, + { "../path.with+symbols/test.clayer.yaml", true }, + { "$variable$", true }, + { "$Layer_Path$/test.clayer.yml", true }, + { "test.yml", false }, + { "test.cproject.yml", false }, + { "test.clayer.yml.bak", false }, + { "test.layer.clayer.yml", false }, + { "../layers/test+layer.clayer.yml", false }, + { "$variable", false }, + { "variable$", false }, + { "$$", false }, + { "$one$two$", false }, + { "", true }, + }; + const string filename = testoutput_folder + "/layer-pattern.cproject.yml"; + for (const auto& [layer, expected] : testCases) { + { + ofstream fileStream(filename); + fileStream << "project:\n" + " layers:\n" + " - layer: '" << layer << "'\n"; + } + EXPECT_EQ(expected, Validate(filename)) << "layer: " << layer; + EXPECT_EQ(expected, GetErrors().empty()) << "layer: " << layer; + } + RteFsUtils::RemoveFile(filename); +} + TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Fail) { vector> expectedErrPos = { // line, col