okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
538acd098
main
1"""A `cmake -P` script has no cmake_minimum_required, so CMake 3.x applies the OLD behaviour of CMP0057 and `IN_LIST` is not an operator 2(ctest ggml_tq_overlay stopped at its first IN_LIST with CMake 3.31, #3412). Every script in cmake/ that is run with -P and uses IN_LIST 3sets the policy before the first use. (Static check: the project accepts CMake 3.24 and newer, and CMake 4 sets the policy by itself.)""" 4from __future__import annotations 5 6import re 7import unittest 8from pathlib import Path 9 10CMAKE = Path (__file__ ).resolve ().parents [2 ]/ "cmake" 11 12 13class ScriptPolicies (unittest .TestCase ): 14def test_p_scripts_that_use_in_list_set_cmp0057_first (self ): 15found = 0 16for path in sorted (CMAKE .glob ("*_test.cmake" )): 17text = path .read_text (encoding = "utf-8" ) 18code = re .sub (r"(?m)^\s*#.*$" ,"" ,text ) 19if "IN_LIST" not in code : 20continue 21found += 1 22policy = re .search (r"cmake_policy\(\s*SET\s+CMP0057\s+NEW\s*\)" ,code )or re .search (r"cmake_minimum_required\(\s*VERSION\s+3\.(1[0-9]|[2-9]\d)" ,code ) 23self .assertTrue (policy ,f" { path . name } uses IN_LIST without CMP0057 NEW" ) 24self .assertLess (policy .start (),code .index ("IN_LIST" ),f" { path . name } sets the policy after its first IN_LIST" ) 25self .assertGreaterEqual (found ,1 ) 26 27 28if __name__ == "__main__" : 29unittest .main ()