build: Add Python 3 support (see issue #2856)

This commit is contained in:
Marshall Greenblatt
2020-01-13 11:04:13 +01:00
parent b98f142e0e
commit 3afa29d499
4 changed files with 136 additions and 105 deletions

View File

@@ -93,6 +93,8 @@ the input will be replaced with "bar":
"""
from __future__ import absolute_import
from __future__ import print_function
from optparse import OptionParser
import os
import sys
@@ -100,7 +102,7 @@ import sys
try:
# May already be in the import path.
import gn_helpers
except ImportError, e:
except ImportError as e:
# Add src/build to import path.
cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
src_dir = os.path.abspath(os.path.join(cef_dir, os.pardir))
@@ -112,10 +114,10 @@ def LoadPythonDictionary(path):
file_string = open(path).read()
try:
file_data = eval(file_string, {'__builtins__': None}, None)
except SyntaxError, e:
except SyntaxError as e:
e.filename = path
raise
except Exception, e:
except Exception as e:
raise Exception("Unexpected error while reading %s: %s" % (path, str(e)))
assert isinstance(file_data, dict), "%s does not eval to a dictionary" % path
@@ -194,11 +196,11 @@ def main():
data[key[:-1]] = data[key]
del data[key]
print gn_helpers.ToGNString(data)
print(gn_helpers.ToGNString(data))
if __name__ == '__main__':
try:
main()
except Exception, e:
print str(e)
except Exception as e:
print(str(e))
sys.exit(1)