okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-ctl: GitHub setup, Docker, docs and bench items for 0.2.7538acd098

main
1.4 KiB29 linesraw
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):
14    def test_p_scripts_that_use_in_list_set_cmp0057_first(self):
15        found = 0
16        for path in sorted(CMAKE.glob("*_test.cmake")):
17            text = path.read_text(encoding="utf-8")
18            code = re.sub(r"(?m)^\s*#.*$", "", text)
19            if "IN_LIST" not in code:
20                continue
21            found += 1
22            policy = 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)
23            self.assertTrue(policy, f"{path.name} uses IN_LIST without CMP0057 NEW")
24            self.assertLess(policy.start(), code.index("IN_LIST"), f"{path.name} sets the policy after its first IN_LIST")
25        self.assertGreaterEqual(found, 1)
26
27
28if __name__ == "__main__":
29    unittest.main()