Skip to content

Commit c10f934

Browse files
committed
Merge pull request godotengine#90270 from Repiteo/scons/clean-generated
SCons: Ensure *all* generated files can be cleaned
2 parents 8bbb027 + ccb5e15 commit c10f934

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

methods.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,32 @@ def get_version_info(module_version_string="", silent=False):
228228
return version_info
229229

230230

231+
_cleanup_env = None
232+
_cleanup_bool = False
233+
234+
231235
def write_file_if_needed(path, string):
236+
"""Generates a file only if it doesn't already exist or the content has changed.
237+
238+
Utilizes a dedicated SCons environment to ensure the files are properly removed
239+
during cleanup; will not attempt to create files during cleanup.
240+
241+
- `path` - Path to the file in question; used to create cleanup logic.
242+
- `string` - Content to compare against an existing file.
243+
"""
244+
global _cleanup_env
245+
global _cleanup_bool
246+
247+
if _cleanup_env is None:
248+
from SCons.Environment import Environment
249+
250+
_cleanup_env = Environment()
251+
_cleanup_bool = _cleanup_env.GetOption("clean")
252+
253+
_cleanup_env.Clean("#", path)
254+
if _cleanup_bool:
255+
return
256+
232257
try:
233258
with open(path, "r", encoding="utf-8", newline="\n") as f:
234259
if f.read() == string:

0 commit comments

Comments
 (0)