From 406275abbe294f094bcc05ad99ac20066a8d2c31 Mon Sep 17 00:00:00 2001 From: benn Date: Mon, 5 Sep 2022 23:02:29 +0200 Subject: [PATCH] Upgrade: adapt to use Scons 4.x which uses Python 3 The build system Scons switched from using Python 2.7 to using Python 3.x, so the build breaks on, for example, Debian Bullseye. As a first step use `ato3` to convert Python scripts from 2 to 3. --- admin/scons/BuilderDoxygen.py | 9 +++++---- admin/scons/BuilderGCH.py | 4 ++-- admin/scons/Buildhelper.py | 8 ++++---- admin/scons/IconSvgRenderer.py | 16 ++++++++-------- admin/scons/LumieraEnvironment.py | 8 ++++---- admin/scons/Platform.py | 12 ++++++------ admin/scons/Setup.py | 2 +- admin/scons/ToolCCache.py | 4 ++-- admin/scons/ToolDistCC.py | 4 ++-- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/admin/scons/BuilderDoxygen.py b/admin/scons/BuilderDoxygen.py index 92e47396f..cf20a5ddf 100644 --- a/admin/scons/BuilderDoxygen.py +++ b/admin/scons/BuilderDoxygen.py @@ -23,6 +23,7 @@ import os import os.path import glob from fnmatch import fnmatch +from functools import reduce def DoxyfileParse(file_contents): @@ -62,7 +63,7 @@ def DoxyfileParse(file_contents): key_token = False else: if token == "+=": - if not data.has_key(key): + if key not in data: data[key] = list() elif token == "=": data[key] = list() @@ -78,7 +79,7 @@ def DoxyfileParse(file_contents): append_data(data, key, new_data, '\\') # compress lists of len 1 into single strings - for (k, v) in data.items(): + for (k, v) in list(data.items()): if len(v) == 0: data.pop(k) @@ -146,7 +147,7 @@ def DoxySourceScan(node, env, path): for pattern in file_patterns: sources.extend(glob.glob("/".join([node, pattern]))) - sources = map( lambda path: env.File(path), sources ) + sources = [env.File(path) for path in sources] return sources @@ -172,7 +173,7 @@ def DoxyEmitter(source, target, env): out_dir = data.get("OUTPUT_DIRECTORY", ".") # add our output locations - for (k, v) in output_formats.items(): + for (k, v) in list(output_formats.items()): if data.get("GENERATE_" + k, v[0]) == "YES": targets.append(env.Dir( os.path.join(out_dir, data.get(k + "_OUTPUT", v[1]))) ) diff --git a/admin/scons/BuilderGCH.py b/admin/scons/BuilderGCH.py index 2b6357d70..3bd226ba6 100644 --- a/admin/scons/BuilderGCH.py +++ b/admin/scons/BuilderGCH.py @@ -47,11 +47,11 @@ def setup_dependency(target,source,env, key): path = scanner.path(env) deps = scanner(source[0], env, path) - if env.has_key(key) and env[key]: + if key in env and env[key]: for header in env[key]: header_path = header.path.strip('.gch') if header_path in [x.path for x in deps]: - print "Precompiled header(%s) %s \t <--- %s" % (key,header_path,source[0]) + print("Precompiled header(%s) %s \t <--- %s" % (key,header_path,source[0])) env.Depends(target, header) diff --git a/admin/scons/Buildhelper.py b/admin/scons/Buildhelper.py index e7adfe02b..bfaeb4911 100644 --- a/admin/scons/Buildhelper.py +++ b/admin/scons/Buildhelper.py @@ -113,7 +113,7 @@ def filterNodes(nlist, removeName=None): else: predicate = lambda n : True - return filter(predicate, nlist) + return list(filter(predicate, nlist)) @@ -167,13 +167,13 @@ def checkCommandOption(env, optID, val=None, cmdName=None): if val=='True' or val=='true' or val=='yes' or val=='1' or val == 1 : if not cmdName: - print "WARNING: no default for %s, please specify a full path." % optID + print("WARNING: no default for %s, please specify a full path." % optID) del env[optID] return False else: val = env.WhereIs(cmdName) if not val: - print "WARNING: %s not found, please specify a full path" % cmdName + print("WARNING: %s not found, please specify a full path" % cmdName) del env[optID] return False @@ -218,7 +218,7 @@ def extract_localPathDefs (localDefs): pattern and returns them wrapped into a Record for convenient access """ def relevantPathDefs (mapping): - for (k,v) in mapping.items(): + for (k,v) in list(mapping.items()): if (k.startswith('src') or k.startswith('build') or k.startswith('install')) and Util.is_String(v): v = v.strip() if not v.endswith('/'): v += '/' diff --git a/admin/scons/IconSvgRenderer.py b/admin/scons/IconSvgRenderer.py index 230e16c83..bfc156715 100644 --- a/admin/scons/IconSvgRenderer.py +++ b/admin/scons/IconSvgRenderer.py @@ -54,7 +54,7 @@ def createDirectory (name): if not os.path.exists (name): os.mkdir (name) except: - print 'WARNING: createDirectory("%s") failed. Permission problems?' % name + print('WARNING: createDirectory("%s") failed. Permission problems?' % name) def copyMergeDirectory (src, dst): @@ -91,7 +91,7 @@ def parsePlateLayer (layer): def parseSVG (file_path): - print "Parsing " + file_path + print("Parsing " + file_path) svgdoc = minidom.parse (file_path) for root_node in svgdoc.childNodes: if root_node.nodeType == minidom.Node.ELEMENT_NODE: @@ -114,7 +114,7 @@ def renderSvgRsvg (file_path, out_dir, artwork_name, rectangle, _doc_size): height = int(rectangle[3]) if not os.path.exists(rsvgPath): - print "Error: executable %s not found." % rsvgPath + print("Error: executable %s not found." % rsvgPath) os.spawnlp(os.P_WAIT, rsvgPath, rsvgPath, "--source-rect=%g:%g:%g:%g" % (rectangle[0], rectangle[1], width, height), @@ -135,8 +135,8 @@ def getTargetNames (file_path): def printHelp(): - print "render-icon.py SRCFILE.svg TARGETDIR" - print "An icon rendering utility script for lumiera" + print("render-icon.py SRCFILE.svg TARGETDIR") + print("An icon rendering utility script for lumiera") def parseArguments(argv): _optlist, args = getopt.getopt(argv, "") @@ -152,14 +152,14 @@ def main (argv): in_path, out_dir = parseArguments(argv) if not (in_path and out_dir): - print "Missing arguments in_path and out_dir." + print("Missing arguments in_path and out_dir.") sys.exit(1) if os.path.isfile(out_dir): - print "Unable to use '%s' as output directory, because it\'s a file." % out_dir + print("Unable to use '%s' as output directory, because it\'s a file." % out_dir) sys.exit(1) if not os.path.isdir(out_dir): - print "Output directory '%s' not found." % out_dir + print("Output directory '%s' not found." % out_dir) sys.exit(1) # Create the icons folders diff --git a/admin/scons/LumieraEnvironment.py b/admin/scons/LumieraEnvironment.py index 5397c2fee..f8fb2405b 100644 --- a/admin/scons/LumieraEnvironment.py +++ b/admin/scons/LumieraEnvironment.py @@ -48,7 +48,7 @@ class LumieraEnvironment(Environment): def Configure (self, *args, **kw): kw['env'] = self - return apply(LumieraConfigContext, args, kw) + return LumieraConfigContext(*args, **kw) def mergeConf (self,other): """ extract the library/compiler flags from other Environment. @@ -77,7 +77,7 @@ class LumieraEnvironment(Environment): """ minVersion = str(minVersion) if 0 != os.system('pkg-config --print-errors --exists "%s >= %s"' % (libID,minVersion)): - print "Problems configuring the Library %s (>= %s)" % (libID,minVersion) + print("Problems configuring the Library %s (>= %s)" % (libID,minVersion)) return False self.libInfo[libID] = libInfo = Environment() @@ -104,7 +104,7 @@ class LumieraConfigContext(ConfigBase): ConfigBase.__init__(self,*args,**kw) def CheckPkgConfig (self, libID, minVersion=0, alias=None): - print "Checking for library configuration: %s " % libID + print("Checking for library configuration: %s " % libID) # self.Message(self,"Checking for library configuration: %s " % libID) return self.env.addLibInfo (libID, minVersion, alias) @@ -212,7 +212,7 @@ class WrappedStandardExeBuilder(SCons.Util.Proxy): def __init__(self, originalBuilder): SCons.Util.Proxy.__init__ (self, originalBuilder) - def __nonzero__(self): return True + def __bool__(self): return True def __call__(self, env, target=None, source=None, **kw): """ when the builder gets invoked from the SConscript... diff --git a/admin/scons/Platform.py b/admin/scons/Platform.py index a9002aa4f..19739ce89 100644 --- a/admin/scons/Platform.py +++ b/admin/scons/Platform.py @@ -57,7 +57,7 @@ def configure(env): if conf.CheckCHeader('valgrind/valgrind.h'): conf.env.Append(CPPFLAGS = ' -DHAVE_VALGRIND_H') else: - print 'Valgrind not found. The use of Valgrind is optional; building without.' + print('Valgrind not found. The use of Valgrind is optional; building without.') if not conf.CheckPkgConfig('nobugmt', 201008.1): problems.append('Did not find NoBug [http://nobug.pipapo.org/].') @@ -141,14 +141,14 @@ def configure(env): # report missing dependencies if problems: - print "*** unable to build due to the following problems:" + print("*** unable to build due to the following problems:") for isue in problems: - print " * %s" % isue - print - print "build aborted." + print(" * %s" % isue) + print() + print("build aborted.") Exit(1) - print "** Gathered Library Info: %s" % conf.env.libInfo.keys() + print("** Gathered Library Info: %s" % list(conf.env.libInfo.keys())) # create new env containing the finished configuration diff --git a/admin/scons/Setup.py b/admin/scons/Setup.py index 421cb56de..38c0af7d5 100644 --- a/admin/scons/Setup.py +++ b/admin/scons/Setup.py @@ -111,7 +111,7 @@ def handleNoBugSwitches(env): level = env['BUILDLEVEL'] if level in ['ALPHA', 'BETA']: if not env['DEBUG']: - print 'Warning: NoBug ALPHA or BETA builds requires DEBUG=yes, switching DEBUG on!' + print('Warning: NoBug ALPHA or BETA builds requires DEBUG=yes, switching DEBUG on!') env.Replace( DEBUG = 1 ) env.Append(CPPDEFINES = 'EBUG_'+level) elif level == 'RELEASE': diff --git a/admin/scons/ToolCCache.py b/admin/scons/ToolCCache.py index d95020fe0..139d4d550 100644 --- a/admin/scons/ToolCCache.py +++ b/admin/scons/ToolCCache.py @@ -34,7 +34,7 @@ def generate(env): env['CC'] = env.subst('$CCACHE $CC') if not env['CCACHE'] in env['CXX']: env['CXX'] = env.subst('$CCACHE $CXX') - print env.subst("* Build using $CCACHE") + print(env.subst("* Build using $CCACHE")) for i in ['HOME' ,'CCACHE_DIR' @@ -55,7 +55,7 @@ def generate(env): ,'CCACHE_UNIFY' ,'CCACHE_EXTENSION' ]: - if os.environ.has_key(i) and not env.has_key(i): + if i in os.environ and i not in env: env['ENV'][i] = os.environ[i] diff --git a/admin/scons/ToolDistCC.py b/admin/scons/ToolDistCC.py index 443c2ae14..fab268aa7 100644 --- a/admin/scons/ToolDistCC.py +++ b/admin/scons/ToolDistCC.py @@ -34,7 +34,7 @@ def generate(env): env['CC'] = env.subst('$DISTCC $CC') if not env['DISTCC'] in env['CXX']: env['CXX'] = env.subst('$DISTCC $CXX') - print env.subst("* Build using $DISTCC") + print(env.subst("* Build using $DISTCC")) for i in ['HOME' ,'DISTCC_HOSTS' ,'DISTCC_VERBOSE' @@ -45,7 +45,7 @@ def generate(env): ,'DISTCC_TCP_CORK' ,'DISTCC_SSH' ]: - if os.environ.has_key(i) and not env.has_key(i): + if i in os.environ and i not in env: env['ENV'][i] = os.environ[i]