From bb704d03904174d7da48b34133389d6efcb4c8b3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 18 Sep 2025 09:57:11 -0400 Subject: [PATCH] Tests: Refactor RunCMake.FileAPI check script to support more arguments --- Tests/RunCMake/FileAPI/RunCMakeTest.cmake | 6 ++++-- Tests/RunCMake/FileAPI/check_index.py | 12 +++++++++--- Tests/RunCMake/FileAPI/codemodel-v2-check.py | 3 +-- Tests/RunCMake/FileAPI/toolchains-v1-check.py | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Tests/RunCMake/FileAPI/RunCMakeTest.cmake b/Tests/RunCMake/FileAPI/RunCMakeTest.cmake index 20c3d618cb..5261b2f269 100644 --- a/Tests/RunCMake/FileAPI/RunCMakeTest.cmake +++ b/Tests/RunCMake/FileAPI/RunCMakeTest.cmake @@ -108,8 +108,10 @@ function(check_python case prefix) endif() file(GLOB index ${RunCMake_TEST_BINARY_DIR}/.cmake/api/v1/reply/${prefix}-*.json) execute_process( - COMMAND ${Python_EXECUTABLE} "${RunCMake_SOURCE_DIR}/${case}-check.py" "${index}" "${CMAKE_CXX_COMPILER_ID}" - "${RunCMake_TEST_BINARY_DIR}" + COMMAND ${Python_EXECUTABLE} "${RunCMake_SOURCE_DIR}/${case}-check.py" + --build-dir "${RunCMake_TEST_BINARY_DIR}" + --reply-index "${index}" + --cxx-compiler-id "${CMAKE_CXX_COMPILER_ID}" RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE output diff --git a/Tests/RunCMake/FileAPI/check_index.py b/Tests/RunCMake/FileAPI/check_index.py index 64c17d0993..32cc6aa1cf 100644 --- a/Tests/RunCMake/FileAPI/check_index.py +++ b/Tests/RunCMake/FileAPI/check_index.py @@ -2,6 +2,7 @@ import sys import os import json import re +import argparse if sys.version_info[0] >= 3: unicode = str @@ -158,8 +159,13 @@ def check_error_re(value, error): assert is_string(value["error"]) assert re.search(error, value["error"]) -reply_index = sys.argv[1] -reply_dir = os.path.dirname(reply_index) +parser = argparse.ArgumentParser() +parser.add_argument("--build-dir") +parser.add_argument("--reply-index") +parser.add_argument("--cxx-compiler-id") +args = parser.parse_args() -with open(reply_index) as f: +reply_dir = os.path.dirname(args.reply_index) + +with open(args.reply_index) as f: index = json.load(f) diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 84b452a60f..8c90273670 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -900,7 +900,7 @@ def gen_check_targets(c, g, inSource): e["compileGroups"] = apple_exe_framework["compileGroups"] e["link"] = apple_exe_framework["link"] - if cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'CrayClang', 'IBMClang'] and g["name"] != "Xcode": + if args.cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'CrayClang', 'IBMClang'] and g["name"] != "Xcode": for e in expected: if e["name"] == "cxx_exe": if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"): @@ -1087,7 +1087,6 @@ def check_object_codemodel(g, major, minor): check_object_codemodel_configuration(c, g, major, minor, inSource) return _check -cxx_compiler_id = sys.argv[2] assert is_dict(index) assert sorted(index.keys()) == ["cmake", "objects", "reply"] check_objects(index["objects"], index["cmake"]["generator"]) diff --git a/Tests/RunCMake/FileAPI/toolchains-v1-check.py b/Tests/RunCMake/FileAPI/toolchains-v1-check.py index a0e50c2448..bc5ecb9b92 100644 --- a/Tests/RunCMake/FileAPI/toolchains-v1-check.py +++ b/Tests/RunCMake/FileAPI/toolchains-v1-check.py @@ -77,7 +77,7 @@ def check_object_toolchain(o, expected): else: assert False -with open(os.path.join(sys.argv[3], "toolchain_variables.json")) as f: +with open(os.path.join(args.build_dir, "toolchain_variables.json")) as f: variables = json.load(f) assert is_dict(variables)