File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff 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+
231235def 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 :
You can’t perform that action at this time.
0 commit comments