From bb95aa14c6fe2e01181c20a3821ce1631479f5fa Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Mon, 2 Mar 2020 15:08:41 +0000 Subject: [PATCH] scons: file removed from python3 Change-Id: I95794fec5cc9c6e72c9ae53f586052be71436c87 Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26249 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power --- SConstruct | 5 ++--- src/SConscript | 9 ++++++--- src/mem/ruby/SConscript | 7 +++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/SConstruct b/SConstruct index 110f9c896..932eb819d 100755 --- a/SConstruct +++ b/SConstruct @@ -1014,9 +1014,8 @@ export_vars += ['USE_FENV', 'TARGET_ISA', 'TARGET_GPU_ISA', 'CP_ANNOTATE', # value of the variable. def build_config_file(target, source, env): (variable, value) = [s.get_contents() for s in source] - f = file(str(target[0]), 'w') - print('#define', variable, value, file=f) - f.close() + with open(str(target[0]), 'w') as f: + print('#define', variable, value, file=f) return None # Combine the two functions into a scons Action object. diff --git a/src/SConscript b/src/SConscript index d377ff5e0..e8b90acf5 100644 --- a/src/SConscript +++ b/src/SConscript @@ -284,7 +284,8 @@ def Blob(blob_path, symbol): cpp_path = path_noext + '.cc' hpp_path = path_noext + '.hh' def embedBlob(target, source, env): - data = file(str(source[0]), 'r').read() + with open(str(source[0]), 'rb') as f: + data = f.read() cpp_code = code_formatter() hpp_code = code_formatter() blobToCpp(data, symbol, cpp_code, hpp_code, namespace='Blobs') @@ -767,7 +768,8 @@ class DictImporter(object): mod.__path__ = source.modpath mod.__file__ = source.abspath - exec file(source.abspath, 'r') in mod.__dict__ + compiled = compile(open(source.abspath).read(), source.abspath, 'exec') + exec(compiled, mod.__dict__) return mod @@ -850,7 +852,8 @@ PySource('m5', 'python/m5/defines.py') def makeInfoPyFile(target, source, env): code = code_formatter() for src in source: - data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) + with open(src.srcnode().abspath, 'r') as f: + data = ''.join(f) code('$src = ${{repr(data)}}') code.write(str(target[0])) diff --git a/src/mem/ruby/SConscript b/src/mem/ruby/SConscript index a9c339403..8c22ae495 100644 --- a/src/mem/ruby/SConscript +++ b/src/mem/ruby/SConscript @@ -99,10 +99,9 @@ def do_embed_text(target, source, env): generated_dir = Dir('protocol') def MakeIncludeAction(target, source, env): - f = file(str(target[0]), 'w') - for s in source: - print('#include "%s"' % str(s.abspath), file=f) - f.close() + with open(str(target[0]), 'w') as f: + for s in source: + print('#include "%s"' % str(s.abspath), file=f) def MakeInclude(source): target = generated_dir.File(basename(source)) -- 2.30.2