diff options
author | Tobias Markmann <tm@ayena.de> | 2018-07-12 09:02:56 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2018-07-12 09:02:56 (GMT) |
commit | 95b04304452c4cf0a01f676a12779dacc6fa51a4 (patch) | |
tree | 9a8dce3db8213b68901893a0a6d371243684c3ee /BuildTools/SCons | |
parent | 2bb40b14d3d7f5cebc56601dad066d5201040bd2 (diff) | |
download | swift-95b04304452c4cf0a01f676a12779dacc6fa51a4.zip swift-95b04304452c4cf0a01f676a12779dacc6fa51a4.tar.bz2 |
Fix Python 3 compatibility of our SCons and tooling Python code
For the upcoming update to Scons 3, which works with Python 2
and Python 3, this change makes our code compatible with
Python 3 so that it still works with Python 2.
Test-Information:
Tested these changes with SCons 3.0.1 on macOS 10.13.6 with
Python 2.7.15 and Python 3.7.0.
Change-Id: Idb5207b179a79a0dbe89d7e620d182a7d2f1ca6c
Diffstat (limited to 'BuildTools/SCons')
-rw-r--r-- | BuildTools/SCons/SConstruct | 48 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/AppBundle.py | 4 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/InstallWithSymLinks.py | 8 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/qt4.py | 22 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/textfile.py | 2 | ||||
-rw-r--r-- | BuildTools/SCons/Version.py | 6 |
6 files changed, 45 insertions, 45 deletions
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index 55b604b..78f388b 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -7,9 +7,9 @@ root = Dir("../..").abspath # Override SConscript to handle tests oldSConscript = SConscript -def SConscript(*arguments, **keywords) : - if not keywords.get("test_only", False) or env["TEST"] : - return apply(oldSConscript, arguments, keywords) +def SConscript(*args, **kwargs) : + if not kwargs.get("test_only", False) or env["TEST"] : + return oldSConscript(*args, **kwargs) env.SConscript = SConscript ################################################################################ @@ -142,11 +142,11 @@ conf = Configure(conf_env, custom_tests = { }) if not conf.CheckCXX() or not conf.CheckCC() : - print "Error: You need a working compiler" + print("Error: You need a working compiler") Exit(1) if not conf.CheckCpp11Support() : - print "Error: You need a compiler with support for the C++11 standard" + print("Error: You need a compiler with support for the C++11 standard") Exit(1) @@ -170,7 +170,7 @@ if (not zlib_okay) and conf.CheckLib("z") : if zlib_okay : env["ZLIB_FLAGS"] = zlib_flags elif not env.get("zlib_bundled_enable", True) : - print "Error: Zlib not found and zlib_bundled_enable is false" + print("Error: Zlib not found and zlib_bundled_enable is false") Exit(1) else : env["ZLIB_BUNDLED"] = True @@ -238,7 +238,7 @@ if not env.get("boost_force_bundled") and allLibsPresent : # FIXME: Remove this workaround when UUID is available in most distros env["BOOST_BUNDLED_UUID_ONLY"] = True elif not env.get("boost_bundled_enable", True) : - print "Error: Boost not found and boost_bundled_enable is false" + print("Error: Boost not found and boost_bundled_enable is false") Exit(1) else : env["BOOST_BUNDLED"] = True @@ -373,7 +373,7 @@ if env.get("try_expat", True) and not env.get("HAVE_LIBXML",0) : # Bundled expat bundledExpat = False if not env.get("HAVE_EXPAT", 0) and not env.get("HAVE_LIBXML", 0) : - print "Expat or LibXML not found. Using bundled Expat" + print("Expat or LibXML not found. Using bundled Expat") SConscript("#/3rdParty/Expat/SConscript") env["HAVE_EXPAT"] = 1 env["EXPAT_BUNDLED"] = True @@ -424,10 +424,10 @@ if not env.get("HAVE_ICU", False) and not env.get("HAVE_LIBIDN", False) : env["HAVE_LIBIDN"] = 1 env["LIBIDN_BUNDLED"] = 1 elif env.get("need_idn", True): - print "Error: ICU and LIBIDN not found, and libidn_bundled_enable is false" + print("Error: ICU and LIBIDN not found, and libidn_bundled_enable is false") Exit(1) else: - print "Proceeding without an IDN library because need_idn was false. This will break all internal binaries" + print("Proceeding without an IDN library because need_idn was false. This will break all internal binaries") # Unbound if env["unbound"] : @@ -514,7 +514,7 @@ if not env.get("lua_force_bundled", False) and conf.CheckLibWithHeader(env["lua_ if lua_version > 0 : env["LUA_FLAGS"]["LUA_VERSION"] = str(lua_version // 100) + "." + str(lua_version % 100) else : - print "Warning: Unable to determine Lua version. Not installing Lua libraries." + print("Warning: Unable to determine Lua version. Not installing Lua libraries.") env["LUA_FLAGS"].update(lua_flags) else : env["LUA_BUNDLED"] = 1 @@ -670,7 +670,7 @@ try : except SCons.Errors.StopError: env["HAVE_QT"] = False except Exception as e: - print "Info: %s" % str(e) + print("Info: %s" % str(e)) env["HAVE_QT"] = False ################################################################################ @@ -692,7 +692,7 @@ try: if not env.GetOption("clean") and env.get("install_git_hooks", True) : env.Install("#/.git/hooks", Glob("#/BuildTools/Git/Hooks/*")) except TypeError: - print "You seem to be using Swift in a Git submodule. Not installing hooks." + print("You seem to be using Swift in a Git submodule. Not installing hooks.") ################################################################################ @@ -758,7 +758,7 @@ modules.append("QA") env["PROJECTS"] = [m for m in modules if m not in ["Documentation", "QA", "SwifTools"] and not m.startswith("3rdParty")] for stage in ["flags", "build"] : env["SCONS_STAGE"] = stage - SConscript(dirs = map(lambda x : root + "/" + x, modules)) + SConscript(dirs = list(map(lambda x : root + "/" + x, modules))) # SLOCCount if ARGUMENTS.get("sloccount", False) : @@ -770,9 +770,9 @@ if ARGUMENTS.get("sloccount", False) : # Print summary ################################################################################ -print -print " Build Configuration" -print " -------------------" +print("") +print(" Build Configuration") +print(" -------------------") parsers = [] if env.get("HAVE_LIBXML", 0): @@ -781,14 +781,14 @@ if env.get("HAVE_EXPAT", 0): parsers.append("Expat") if env.get("EXPAT_BUNDLED", False) : parsers.append("(Bundled)") -print " Projects: " + ' '.join(env["PROJECTS"]) -print "" -print " XML Parsers: " + ' '.join(parsers) +print(" Projects: " + ' '.join(env["PROJECTS"])) +print("") +print(" XML Parsers: " + ' '.join(parsers)) -print " TLS Support: " + (env.get("HAVE_OPENSSL",0) and "OpenSSL" or env.get("HAVE_SECURETRANSPORT",0) and "Secure Transport" or env.get("HAVE_SCHANNEL", 0) and "Schannel" or "Disabled") -print " DNSSD Support: " + (env.get("HAVE_BONJOUR") and "Bonjour" or (env.get("HAVE_AVAHI") and "Avahi" or "Disabled")) -print +print(" TLS Support: " + (env.get("HAVE_OPENSSL",0) and "OpenSSL" or env.get("HAVE_SECURETRANSPORT",0) and "Secure Transport" or env.get("HAVE_SCHANNEL", 0) and "Schannel" or "Disabled")) +print(" DNSSD Support: " + (env.get("HAVE_BONJOUR") and "Bonjour" or (env.get("HAVE_AVAHI") and "Avahi" or "Disabled"))) +print("") if not GetOption("help") and not env.get("HAVE_OPENSSL", 0) and not env.get("HAVE_SCHANNEL", 0) and not env.get("HAVE_SECURETRANSPORT", 0): - print "Error: A working TLS backend is required. Please check the documentation for more information." + print("Error: A working TLS backend is required. Please check the documentation for more information.") Exit(1) diff --git a/BuildTools/SCons/Tools/AppBundle.py b/BuildTools/SCons/Tools/AppBundle.py index 337e83f..31cfef1 100644 --- a/BuildTools/SCons/Tools/AppBundle.py +++ b/BuildTools/SCons/Tools/AppBundle.py @@ -34,7 +34,7 @@ def generate(env) : """ for key, value in infoDict.items() : plist += "<key>" + key + "</key>\n" - plist += "<string>" + value.encode("utf-8") + "</string>\n" + plist += "<string>" + value + "</string>\n" if handlesXMPPURIs : plist += """<key>CFBundleURLTypes</key> <array> @@ -50,7 +50,7 @@ def generate(env) : if sparklePublicDSAKey : plist += "<key>SUPublicDSAKeyFile</key>" - plist += "<string>" + sparklePublicDSAKey.name.encode("utf-8") + "</string>" + plist += "<string>" + sparklePublicDSAKey.name + "</string>" env.Install(resourcesDir, sparklePublicDSAKey) plist += """</dict> </plist> diff --git a/BuildTools/SCons/Tools/InstallWithSymLinks.py b/BuildTools/SCons/Tools/InstallWithSymLinks.py index 23d12ed..4955192 100644 --- a/BuildTools/SCons/Tools/InstallWithSymLinks.py +++ b/BuildTools/SCons/Tools/InstallWithSymLinks.py @@ -74,21 +74,21 @@ def scons_copytree(src, dst, symlinks=False): else: shutil.copy2(srcname, dstname) # XXX What about devices, sockets etc.? - except (IOError, os.error), why: + except (IOError, os.error) as why: errors.append((srcname, dstname, str(why))) # catch the CopytreeError from the recursive copytree so that we can # continue with other files - except CopytreeError, err: + except CopytreeError as err: errors.extend(err.args[0]) try: shutil.copystat(src, dst) except WindowsError: # can't copy file access times on Windows pass - except OSError, why: + except OSError as why: errors.extend((src, dst, str(why))) if errors: - raise CopytreeError, errors + raise CopytreeError(errors) def symlinkBuilderImpl(target, source, env): diff --git a/BuildTools/SCons/Tools/qt4.py b/BuildTools/SCons/Tools/qt4.py index e859017..372b261 100644 --- a/BuildTools/SCons/Tools/qt4.py +++ b/BuildTools/SCons/Tools/qt4.py @@ -140,23 +140,23 @@ class _Automoc: out_sources = source[:] for obj in source: - if isinstance(obj,basestring): # big kludge! - print "scons: qt4: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj) + if isinstance(obj,str): # big kludge! + print("scons: qt4: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj)) continue if not obj.has_builder(): # binary obj file provided if debug: - print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj) + print("scons: qt: '%s' seems to be a binary. Discarded." % str(obj)) continue cpp = obj.sources[0] if not splitext(str(cpp))[1] in cxx_suffixes: if debug: - print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp) + print("scons: qt: '%s' is no cxx file. Discarded." % str(cpp) ) # c or fortran source continue #cpp_contents = comment.sub('', cpp.get_contents()) try: - cpp_contents = cpp.get_contents() + cpp_contents = str(cpp.get_contents()) except: continue # may be an still not generated source h=None for h_ext in header_extensions: @@ -166,12 +166,12 @@ class _Automoc: h = find_file(hname, (cpp.get_dir(),), env.File) if h: if debug: - print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp)) + print("scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))) #h_contents = comment.sub('', h.get_contents()) - h_contents = h.get_contents() + h_contents = str(h.get_contents()) break if not h and debug: - print "scons: qt: no header for '%s'." % (str(cpp)) + print("scons: qt: no header for '%s'." % (str(cpp))) if h and q_object_search.search(h_contents): # h file with the Q_OBJECT macro found -> add moc_cpp moc_cpp = env.Moc4(h) @@ -179,14 +179,14 @@ class _Automoc: out_sources.append(moc_o) #moc_cpp.target_scanner = SCons.Defaults.CScan if debug: - print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp)) + print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))) if cpp and q_object_search.search(cpp_contents): # cpp file with Q_OBJECT macro found -> add moc # (to be included in cpp) moc = env.Moc4(cpp) env.Ignore(moc, moc) if debug: - print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc)) + print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc))) #moc.source_scanner = SCons.Defaults.CScan # restore the original env attributes (FIXME) objBuilder.env = objBuilderEnv @@ -347,7 +347,7 @@ def generate(env): else: result.append(itemPath) return result - contents = node.get_contents() + contents = str(node.get_contents()) includes = [included[1] for included in qrcinclude_re.findall(contents)] qrcpath = os.path.dirname(node.path) dirs = [included for included in includes if os.path.isdir(os.path.join(qrcpath,included))] diff --git a/BuildTools/SCons/Tools/textfile.py b/BuildTools/SCons/Tools/textfile.py index 9b424f2..02fc54a 100644 --- a/BuildTools/SCons/Tools/textfile.py +++ b/BuildTools/SCons/Tools/textfile.py @@ -107,7 +107,7 @@ def _action(target, source, env): # write the file try: fd = open(target[0].get_path(), "wb") - except (OSError,IOError), e: + except (OSError,IOError) as e: raise SCons.Errors.UserError("Can't write target file %s" % target[0]) # separate lines by 'linesep' only if linesep is not empty lsep = None diff --git a/BuildTools/SCons/Version.py b/BuildTools/SCons/Version.py index d34c2a7..b69cdca 100644 --- a/BuildTools/SCons/Version.py +++ b/BuildTools/SCons/Version.py @@ -6,7 +6,7 @@ def getGitBuildVersion(root, project) : return tag.rstrip()[len(project)+1:] tag = git("describe --tags --match \"" + project + "-*\"", root) if tag : - m = re.match(project + "-(.*)-(.*)-(.*)", tag) + m = re.match(project + "-(.*)-(.*)-(.*)", tag.decode('utf-8')) if m : return m.group(1) + "-dev" + m.group(2) return None @@ -17,7 +17,7 @@ def git(cmd, root) : gitVersion = p.stdout.read() # error = p.stderr.read() # if error: - # print "Git error: " + error + # print("Git error: " + error) p.stdin.close() if p.wait() == 0 : return gitVersion @@ -38,7 +38,7 @@ def getBuildVersion(root, project) : return datetime.date.today().strftime("%Y%m%d") def convertToWindowsVersion(version) : - version_match = re.match("(\d+)\.(\d+)(.*)", version) + version_match = re.match("(\d+)\.(\d+)(.*)", version.decode('utf-8')) major = version_match and int(version_match.group(1)) or 0 minor = version_match and int(version_match.group(2)) or 0 if version_match and len(version_match.group(3)) == 0 : |