The goal of this test is to try to import some critical py scripts with the system python of the building machine. The main target is to ensure that these py scripts remain usable by all buildbot machines, as some of them are using fairly outdated python versions. Current status: * Scripts in `build_files` and `docs` are checked. * Some python scripts in `build_files` were 'reverted' to be compatible with older required python version currently (3.6). * A few scripts are excluded from the test, mostly because they use Blender's `bpy` module, which means they are only intended to be ran with Blender's python anyway. * The test is only enabled for Linux buildbots currently, as they use the oldest Python by far. Notes: * Some more scripts are likely to be moved around in the future. * Whether these tests need to be enabled on windows or macos platforms remains an open question. Pull Request: https://projects.blender.org/blender/blender/pulls/130746
93 lines
2.3 KiB
Python
93 lines
2.3 KiB
Python
# SPDX-FileCopyrightText: 2018-2023 Blender Authors
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# Simple utility that prints all WITH_* options in a CMakeLists.txt
|
|
# Called by 'make help_features'
|
|
|
|
import re
|
|
import sys
|
|
|
|
from typing import (
|
|
Union,
|
|
)
|
|
|
|
cmakelists_file = sys.argv[-1]
|
|
|
|
|
|
def count_backslashes_before_pos(file_data: str, pos: int) -> int:
|
|
slash_count = 0
|
|
pos -= 1
|
|
while pos >= 0:
|
|
if file_data[pos] != '\\':
|
|
break
|
|
pos -= 1
|
|
slash_count += 1
|
|
return slash_count
|
|
|
|
|
|
def extract_cmake_string_at_pos(file_data: str, pos_beg: int) -> Union[str, None]:
|
|
assert file_data[pos_beg - 1] == '"'
|
|
|
|
pos = pos_beg
|
|
# Dummy assignment.
|
|
pos_end = pos_beg
|
|
while True:
|
|
pos_next = file_data.find('"', pos)
|
|
if pos_next == -1:
|
|
raise Exception("Un-terminated string (parse error?)")
|
|
|
|
count_slashes = count_backslashes_before_pos(file_data, pos_next)
|
|
if (count_slashes % 2) == 0:
|
|
pos_end = pos_next
|
|
# Found the closing quote.
|
|
break
|
|
|
|
# The quote was back-slash escaped, step over it.
|
|
pos = pos_next + 1
|
|
file_data[pos_next]
|
|
|
|
assert file_data[pos_end] == '"'
|
|
|
|
if pos_beg == pos_end:
|
|
return None
|
|
|
|
# See: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#escape-sequences
|
|
text = file_data[pos_beg: pos_end].replace(
|
|
# Handle back-slash literals.
|
|
"\\\\", "\\",
|
|
).replace(
|
|
# Handle tabs.
|
|
"\\t", "\t",
|
|
).replace(
|
|
# Handle escaped quotes.
|
|
"\\\"", "\"",
|
|
).replace(
|
|
# Handle tabs.
|
|
"\\;", ";",
|
|
).replace(
|
|
# Handle trailing newlines.
|
|
"\\\n", "",
|
|
)
|
|
|
|
return text
|
|
|
|
|
|
def main() -> None:
|
|
options = []
|
|
with open(cmakelists_file, 'r', encoding="utf-8") as fh:
|
|
file_data = fh.read()
|
|
for m in re.finditer(r"^\s*option\s*\(\s*(WITH_[a-zA-Z0-9_]+)\s+(\")", file_data, re.MULTILINE):
|
|
option_name = m.group(1)
|
|
option_descr = extract_cmake_string_at_pos(file_data, m.span(2)[1])
|
|
if option_descr is None:
|
|
# Possibly a parsing error, at least show something.
|
|
option_descr = "(UNDOCUMENTED)"
|
|
options.append("{:s}: {:s}".format(option_name, option_descr))
|
|
|
|
print('\n'.join(options))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|