Merge branch 'preset-schema-refactor' into 'master'

Draft: presets: Refactor JSON schema

See merge request cmake/cmake!11591
This commit is contained in:
Tyler Yankee 2026-01-17 13:26:08 -05:00
commit d59592a556
3 changed files with 389 additions and 738 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,13 +6,11 @@ function(validate_schema file expected_result)
execute_process(
COMMAND "${Python_EXECUTABLE}" "${CMakePresets_VALIDATE_SCRIPT_PATH}" "${file}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _output
ERROR_VARIABLE _error
)
if(NOT _result STREQUAL expected_result)
string(REPLACE "\n" "\n " _output_p "${_output}")
string(REPLACE "\n" "\n " _error_p "${_error}")
string(APPEND RunCMake_TEST_FAILED "Expected result of validating ${file}: ${expected_result}\nActual result: ${_result}\nOutput:\n ${_output_p}\nError:\n ${_error_p}\n")
string(APPEND RunCMake_TEST_FAILED "Expected result of validating ${file}: ${expected_result}\nActual result: ${_result}\nError:\n ${_error_p}")
endif()
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)

View File

@ -13,4 +13,8 @@ schema_file = os.path.join(
with open(schema_file, "r", encoding="utf-8") as f:
schema = json.load(f)
jsonschema.validate(contents, schema)
try:
jsonschema.validate(contents, schema)
except jsonschema.ValidationError as e:
sys.stderr.write(e.message)
sys.exit(1)