CMAKE: Python distutils obsoleted.

Python 3.12 will not have the distutils package in the standard library.
The TextFile class is particularly useful when reading [Mm]akefiles, and
recreating its functionality would be painful.

Stash a local copy of the last version of distutils.text_file.py and use
it. Do not rely on distutils being present or installed.
This commit is contained in:
B. Scott Michel 2023-11-16 16:23:53 -08:00 committed by Paul Koning
parent dd49f851a4
commit 625b9e8d45
3 changed files with 5 additions and 9 deletions

View file

@ -22,7 +22,6 @@ import pprint
import simgen.cmake_container as SCC
import simgen.parse_makefile as SPM
import simgen.packaging as SPKG
## from simgen.text_file import TextFile
def process_makefile(makefile_dir, debug=0):
@ -189,4 +188,4 @@ if __name__ == '__main__':
## Emit all of the individual CMakeLists.txt
sims.write_simulators(makefile_dir, debug=debug_level)
## Emit the packaging data
SPKG.write_packaging(makefile_dir)
SPKG.write_packaging(makefile_dir)

View file

@ -23,7 +23,9 @@ def parse_makefile(fn, g_vars=None, g_rules=None, g_actions=None):
Collects all of the variable definitions, rules and actions associated with rules.
"""
from distutils.text_file import TextFile
## Python 3.11 and onward dropped distuitls, so import our local copy.
from simgen.text_file import TextFile
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
if g_vars is None:

View file

@ -2,12 +2,7 @@
provides the TextFile class, which gives an interface to text files
that (optionally) takes care of stripping comments, ignoring blank
lines, and joining lines with backslashes.
NOTE: This Python source code is adapted from the distutils module.
Given that the future of distutils is uncertain, keep and maintain
a local copy here.
"""
lines, and joining lines with backslashes."""
import sys, io