python,scons,mem-ruby: Tag origin of generated files

This will make it easier to backtrack and modify
such files when needed.

Change-Id: If09b6f848e607fb21a0acf2114ce0b9b0aa4751f
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/47301
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2021-06-05 20:55:02 -03:00
committed by Daniel Carvalho
parent 297fa863de
commit 30e770e137
5 changed files with 32 additions and 42 deletions

View File

@@ -154,6 +154,36 @@ class code_formatter(object, metaclass=code_formatter_meta):
def write(self, *args):
f = open(os.path.join(*args), "w")
name, extension = os.path.splitext(f.name)
# Add a comment to inform which file generated the generated file
# to make it easier to backtrack and modify generated code
frame = inspect.currentframe().f_back
if re.match('\.(cc|hh|c|h)', extension) is not None:
f.write(f'''/**
* DO NOT EDIT THIS FILE!
* File automatically generated by
* {frame.f_code.co_filename}:{frame.f_lineno}
*/
''')
elif re.match('\.py', extension) is not None:
f.write(f'''#
# DO NOT EDIT THIS FILE!
# File automatically generated by
# {frame.f_code.co_filename}:{frame.f_lineno}
#
''')
elif re.match('\.html', extension) is not None:
f.write(f'''<!--
DO NOT EDIT THIS FILE!
File automatically generated by
{frame.f_code.co_filename}:{frame.f_lineno}
-->
''')
for data in self._data:
f.write(data)
f.close()