SCons: Ensure *all* generated files can be cleaned
This commit is contained in:
parent
febb11f8a3
commit
ccb5e15ac2
25
methods.py
25
methods.py
|
@ -228,7 +228,32 @@ def get_version_info(module_version_string="", silent=False):
|
||||||
return version_info
|
return version_info
|
||||||
|
|
||||||
|
|
||||||
|
_cleanup_env = None
|
||||||
|
_cleanup_bool = False
|
||||||
|
|
||||||
|
|
||||||
def write_file_if_needed(path, string):
|
def write_file_if_needed(path, string):
|
||||||
|
"""Generates a file only if it doesn't already exist or the content has changed.
|
||||||
|
|
||||||
|
Utilizes a dedicated SCons environment to ensure the files are properly removed
|
||||||
|
during cleanup; will not attempt to create files during cleanup.
|
||||||
|
|
||||||
|
- `path` - Path to the file in question; used to create cleanup logic.
|
||||||
|
- `string` - Content to compare against an existing file.
|
||||||
|
"""
|
||||||
|
global _cleanup_env
|
||||||
|
global _cleanup_bool
|
||||||
|
|
||||||
|
if _cleanup_env is None:
|
||||||
|
from SCons.Environment import Environment
|
||||||
|
|
||||||
|
_cleanup_env = Environment()
|
||||||
|
_cleanup_bool = _cleanup_env.GetOption("clean")
|
||||||
|
|
||||||
|
_cleanup_env.Clean("#", path)
|
||||||
|
if _cleanup_bool:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, "r", encoding="utf-8", newline="\n") as f:
|
with open(path, "r", encoding="utf-8", newline="\n") as f:
|
||||||
if f.read() == string:
|
if f.read() == string:
|
||||||
|
|
Loading…
Reference in New Issue