From: Gabe Black Date: Tue, 4 Aug 2020 06:17:21 +0000 (-0700) Subject: scons: Make src/systemc/tests/SConscript python 3 compatible. X-Git-Tag: v20.1.0.0~340 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bb64849425c3e6c720ed1850f93496a123491403;p=gem5.git scons: Make src/systemc/tests/SConscript python 3 compatible. The os.path.walk method was removed in python 3. Replace it with os.walk which is available in both python 2 and 3. Change-Id: I7919b6a2063c65bc3619927aa4514d8d6d1b2038 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32123 Reviewed-by: Jason Lowe-Power Maintainer: Bobby R. Bruce Tested-by: kokoro --- diff --git a/src/systemc/tests/SConscript b/src/systemc/tests/SConscript index e79105904..cf5051432 100644 --- a/src/systemc/tests/SConscript +++ b/src/systemc/tests/SConscript @@ -31,6 +31,7 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'): from gem5_scons import Transform + import os import os.path import json @@ -75,7 +76,7 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'): # Turn off extra warnings and Werror for the tests. to_remove = ['-Wall', '-Wundef', '-Wextra', '-Werror'] env['CCFLAGS'] = \ - filter(lambda f: f not in to_remove, env['CCFLAGS']) + list(filter(lambda f: f not in to_remove, env['CCFLAGS'])) env.Append(CPPPATH=test_dir.Dir('include')) @@ -112,26 +113,28 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'): def scan_dir_for_tests(subdir): - def visitor(arg, dirname, names): + subdir_src = Dir('.').srcdir.Dir(subdir) + for root, dirs, files in os.walk(str(subdir_src)): # If there's a 'DONTRUN' file in this directory, skip it and any # child directories. - if 'DONTRUN' in names: - del names[:] + if 'DONTRUN' in files: + del dirs[:] return - endswith = lambda sfx: filter(lambda n: n.endswith(sfx), names) + endswith = lambda sfx: list(filter( + lambda n: n.endswith(sfx), files)) cpps = endswith('.cpp') if not cpps: - return + continue def get_entries(fname): - with open(os.path.join(dirname, fname)) as content: + with open(os.path.join(root, fname)) as content: lines = content.readlines # Get rid of leading and trailing whitespace. lines = map(lambda x: x.strip(), content.readlines()) # Get rid of blank lines. - lines = filter(lambda x: x, lines) + lines = list(filter(lambda x: x, lines)) return lines # If there's only one source file, then that files name is the test @@ -139,7 +142,7 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'): if len(cpps) == 1: cpp = cpps[0] - test = new_test(dirname, os.path.splitext(cpp)[0]) + test = new_test(root, os.path.splitext(cpp)[0]) test.add_source(cpp) # Otherwise, expect there to be a file that ends in .f. That files @@ -149,25 +152,22 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'): fs = endswith('.f') if len(fs) != 1: print("In %s, expected 1 *.f file, but found %d.", - dirname, len(fs)) + root, len(fs)) for f in fs: - print(os.path.join(dirname, f)) + print(os.path.join(root, f)) return f = fs[0] - test = new_test(dirname, os.path.splitext(f)[0]) + test = new_test(root, os.path.splitext(f)[0]) # Add all the sources to this test. test.add_sources(get_entries(f)) - if 'COMPILE' in names: + if 'COMPILE' in files: test.compile_only = True - if 'DEPS' in names: + if 'DEPS' in files: test.deps = get_entries('DEPS') - subdir_src = Dir('.').srcdir.Dir(subdir) - os.path.walk(str(subdir_src), visitor, None) - scan_dir_for_tests('systemc') scan_dir_for_tests('tlm')