scons: file removed from python3
authorGiacomo Travaglini <giacomo.travaglini@arm.com>
Mon, 2 Mar 2020 15:08:41 +0000 (15:08 +0000)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Fri, 13 Mar 2020 14:24:07 +0000 (14:24 +0000)
Change-Id: I95794fec5cc9c6e72c9ae53f586052be71436c87
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26249
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>

SConstruct
src/SConscript
src/mem/ruby/SConscript

index 110f9c896f7810b8fdc8d0021be6c6e8255754e1..932eb819d38fb194fcd2e33e8b0d71df217b764d 100755 (executable)
@@ -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.
index d377ff5e0e39aec20b62ca63845f9153ad84a0fb..e8b90acf56af2272a01e9710900126b86bae657d 100644 (file)
@@ -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]))
 
index a9c339403314f9aba05f2f6454b9f2dcd151671d..8c22ae495f29a9f836ec4b0402b245be8769059d 100644 (file)
@@ -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))