Skip to content

Commit

Permalink
CMAKE: Python distutils obsoleted.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bscottm authored and pkoning2 committed Nov 28, 2023
1 parent dd49f85 commit 625b9e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmake/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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):
Expand Down Expand Up @@ -189,4 +188,4 @@ def walk_target_deps(target, defs, rules, actions, simulators, depth='', debug=0
## 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)
4 changes: 3 additions & 1 deletion cmake/simgen/parse_makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions cmake/simgen/text_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 625b9e8

Please sign in to comment.