Skip to content

Commit

Permalink
SCons: Drop support for Python 2
Browse files Browse the repository at this point in the history
We now require SCons 3.0+ (first version with Python 3 support),
and we set min required Python 3 version to 3.5 (3.4 and earlier are
EOL).
  • Loading branch information
akien-mga committed Mar 25, 2020
1 parent 35e700e commit 3d2dd79
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 133 deletions.
5 changes: 3 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

EnsureSConsVersion(0, 98, 1)
EnsureSConsVersion(3, 0, 0)
EnsurePythonVersion(3, 5)

# System
import glob
Expand All @@ -13,7 +14,7 @@ import methods
import gles_builders
from platform_methods import run_in_subprocess

# scan possible build platforms
# Scan possible build platforms

platform_list = [] # list of platforms
platform_opts = {} # options for each platform
Expand Down
68 changes: 0 additions & 68 deletions compat.py

This file was deleted.

46 changes: 32 additions & 14 deletions core/core_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@
"""

from platform_methods import subprocess_main
from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str


def make_certs_header(target, source, env):
def escape_string(s):
def charcode_to_c_escapes(c):
rev_result = []
while c >= 256:
c, low = (c // 256, c % 256)
rev_result.append('\\%03o' % low)
rev_result.append('\\%03o' % c)
return ''.join(reversed(rev_result))

result = ''
if isinstance(s, str):
s = s.encode('utf-8')
for c in s:
if not(32 <= c < 127) or c in (ord('\\'), ord('"')):
result += charcode_to_c_escapes(c)
else:
result += chr(c)
return result


def make_certs_header(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "rb")
g = open_utf8(dst, "w")
g = open(dst, "w", encoding="utf-8")
buf = f.read()
decomp_size = len(buf)
import zlib
Expand All @@ -32,7 +50,7 @@ def make_certs_header(target, source, env):
g.write("static const int _certs_uncompressed_size = " + str(decomp_size) + ";\n")
g.write("static const unsigned char _certs_compressed[] = {\n")
for i in range(len(buf)):
g.write("\t" + byte_to_str(buf[i]) + ",\n")
g.write("\t" + str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif // CERTS_COMPRESSED_GEN_H")

Expand All @@ -46,8 +64,8 @@ def make_authors_header(target, source, env):

src = source[0]
dst = target[0]
f = open_utf8(src, "r")
g = open_utf8(dst, "w")
f = open(src, "r", encoding="utf-8")
g = open(dst, "w", encoding="utf-8")

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef AUTHORS_GEN_H\n")
Expand Down Expand Up @@ -92,8 +110,8 @@ def make_donors_header(target, source, env):

src = source[0]
dst = target[0]
f = open_utf8(src, "r")
g = open_utf8(dst, "w")
f = open(src, "r", encoding="utf-8")
g = open(dst, "w", encoding="utf-8")

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef DONORS_GEN_H\n")
Expand Down Expand Up @@ -163,7 +181,7 @@ def next_tag(self):
projects = OrderedDict()
license_list = []

with open_utf8(src_copyright, "r") as copyright_file:
with open(src_copyright, "r", encoding="utf-8") as copyright_file:
reader = LicenseReader(copyright_file)
part = {}
while reader.current:
Expand All @@ -183,21 +201,21 @@ def next_tag(self):
reader.next_line()

data_list = []
for project in itervalues(projects):
for project in iter(projects.values()):
for part in project:
part["file_index"] = len(data_list)
data_list += part["Files"]
part["copyright_index"] = len(data_list)
data_list += part["Copyright"]

with open_utf8(dst, "w") as f:
with open(dst, "w", encoding="utf-8") as f:

f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
f.write("#ifndef LICENSE_GEN_H\n")
f.write("#define LICENSE_GEN_H\n")
f.write("const char *const GODOT_LICENSE_TEXT =")

with open_utf8(src_license, "r") as license_file:
with open(src_license, "r", encoding="utf-8") as license_file:
for line in license_file:
escaped_string = escape_string(line.strip())
f.write("\n\t\t\"" + escaped_string + "\\n\"")
Expand Down Expand Up @@ -225,7 +243,7 @@ def next_tag(self):
f.write("const ComponentCopyrightPart COPYRIGHT_PROJECT_PARTS[] = {\n")
part_index = 0
part_indexes = {}
for project_name, project in iteritems(projects):
for project_name, project in iter(projects.items()):
part_indexes[project_name] = part_index
for part in project:
f.write("\t{ \"" + escape_string(part["License"][0]) + "\", "
Expand All @@ -239,7 +257,7 @@ def next_tag(self):
f.write("const int COPYRIGHT_INFO_COUNT = " + str(len(projects)) + ";\n")

f.write("const ComponentCopyright COPYRIGHT_INFO[] = {\n")
for project_name, project in iteritems(projects):
for project_name, project in iter(projects.items()):
f.write("\t{ \"" + escape_string(project_name) + "\", "
+ "&COPYRIGHT_PROJECT_PARTS[" + str(part_indexes[project_name]) + "], "
+ str(len(project)) + " },\n")
Expand Down
7 changes: 0 additions & 7 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ doxygen:
mkdir -p $(OUTPUTDIR)/doxygen
doxygen Doxyfile

markdown:
rm -rf $(OUTPUTDIR)/markdown
mkdir -p $(OUTPUTDIR)/markdown
pushd $(OUTPUTDIR)/markdown
python2 $(TOOLSDIR)/makemd.py $(CLASSES)
popd

rst:
rm -rf $(OUTPUTDIR)/rst
mkdir -p $(OUTPUTDIR)/rst
Expand Down
5 changes: 2 additions & 3 deletions editor/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ env.editor_sources = []
import os
import os.path
from platform_methods import run_in_subprocess
from compat import open_utf8
import editor_builders


def _make_doc_data_class_path(to_path):
# NOTE: It is safe to generate this file here, since this is still executed serially
g = open_utf8(os.path.join(to_path, "doc_data_class_path.gen.h"), "w")
g = open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8")
g.write("static const int _doc_data_class_path_count = " + str(len(env.doc_class_path)) + ";\n")
g.write("struct _DocDataClassPath { const char* name; const char* path; };\n")

Expand All @@ -37,7 +36,7 @@ if env['tools']:
reg_exporters += '}\n'

# NOTE: It is safe to generate this file here, since this is still executed serially
with open_utf8("register_exporters.gen.cpp", "w") as f:
with open("register_exporters.gen.cpp", "w", encoding="utf-8") as f:
f.write(reg_exporters_inc)
f.write(reg_exporters)

Expand Down
17 changes: 8 additions & 9 deletions editor/editor_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
import os
import os.path
from platform_methods import subprocess_main
from compat import encode_utf8, byte_to_str, open_utf8


def make_doc_header(target, source, env):

dst = target[0]
g = open_utf8(dst, "w")
g = open(dst, "w", encoding="utf-8")
buf = ""
docbegin = ""
docend = ""
for src in source:
if not src.endswith(".xml"):
continue
with open_utf8(src, "r") as f:
with open(src, "r", encoding="utf-8") as f:
content = f.read()
buf += content

buf = encode_utf8(docbegin + buf + docend)
buf = (docbegin + buf + docend).encode("utf-8")
decomp_size = len(buf)
import zlib
buf = zlib.compress(buf)
Expand All @@ -35,7 +34,7 @@ def make_doc_header(target, source, env):
g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n")
g.write("static const unsigned char _doc_data_compressed[] = {\n")
for i in range(len(buf)):
g.write("\t" + byte_to_str(buf[i]) + ",\n")
g.write("\t" + str(buf[i]) + ",\n")
g.write("};\n")

g.write("#endif")
Expand All @@ -47,7 +46,7 @@ def make_fonts_header(target, source, env):

dst = target[0]

g = open_utf8(dst, "w")
g = open(dst, "w", encoding="utf-8")

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _EDITOR_FONTS_H\n")
Expand All @@ -64,7 +63,7 @@ def make_fonts_header(target, source, env):
g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
g.write("static const unsigned char _font_" + name + "[] = {\n")
for j in range(len(buf)):
g.write("\t" + byte_to_str(buf[j]) + ",\n")
g.write("\t" + str(buf[j]) + ",\n")

g.write("};\n")

Expand All @@ -77,7 +76,7 @@ def make_translations_header(target, source, env, category):

dst = target[0]

g = open_utf8(dst, "w")
g = open(dst, "w", encoding="utf-8")

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))
Expand All @@ -98,7 +97,7 @@ def make_translations_header(target, source, env, category):

g.write("static const unsigned char _{}_translation_{}_compressed[] = {{\n".format(category, name))
for j in range(len(buf)):
g.write("\t" + byte_to_str(buf[j]) + ",\n")
g.write("\t" + str(buf[j]) + ",\n")

g.write("};\n")

Expand Down
3 changes: 2 additions & 1 deletion editor/icons/editor_icons_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
"""

import os
from io import StringIO
from platform_methods import subprocess_main
from compat import StringIO


def make_editor_icons_action(target, source, env):
Expand Down
7 changes: 3 additions & 4 deletions main/main_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
from platform_methods import subprocess_main
from compat import byte_to_str
from collections import OrderedDict


Expand All @@ -22,7 +21,7 @@ def make_splash(target, source, env):
g.write('static const Color boot_splash_bg_color = Color(0.14, 0.14, 0.14);\n')
g.write("static const unsigned char boot_splash_png[] = {\n")
for i in range(len(buf)):
g.write(byte_to_str(buf[i]) + ",\n")
g.write(str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")

Expand All @@ -41,7 +40,7 @@ def make_splash_editor(target, source, env):
g.write('static const Color boot_splash_editor_bg_color = Color(0.14, 0.14, 0.14);\n')
g.write("static const unsigned char boot_splash_editor_png[] = {\n")
for i in range(len(buf)):
g.write(byte_to_str(buf[i]) + ",\n")
g.write(str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")

Expand All @@ -59,7 +58,7 @@ def make_app_icon(target, source, env):
g.write("#define APP_ICON_H\n")
g.write("static const unsigned char app_icon_png[] = {\n")
for i in range(len(buf)):
g.write(byte_to_str(buf[i]) + ",\n")
g.write(str(buf[i]) + ",\n")
g.write("};\n")
g.write("#endif")

Expand Down
Loading

0 comments on commit 3d2dd79

Please sign in to comment.