Skip to content

Commit

Permalink
SCons: Fix python2 compatibility after godotengine#37198 and godoteng…
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored and h committed Nov 10, 2020
1 parent 8dabf25 commit e922c6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
7 changes: 7 additions & 0 deletions compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def escape_string(s):
result += c
return result

def qualname(obj):
# Not properly equivalent to __qualname__ in py3, but it doesn't matter.
return obj.__name__


else:

Expand Down Expand Up @@ -88,3 +92,6 @@ def escape_string(s):
else:
result += chr(c)
return result

def qualname(obj):
return obj.__qualname__
30 changes: 16 additions & 14 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import glob
import subprocess
from collections import OrderedDict
from compat import iteritems, isbasestring, decode_utf8
from compat import iteritems, isbasestring, decode_utf8, qualname


def add_source_files(self, sources, files, warn_duplicates=True):
Expand Down Expand Up @@ -724,10 +724,12 @@ def show_progress(env):
# Progress reporting is not available in non-TTY environments since it
# messes with the output (for example, when writing to a file)
show_progress = env["progress"] and sys.stdout.isatty()
node_count = 0
node_count_max = 0
node_count_interval = 1
node_count_fname = str(env.Dir("#")) + "/.scons_node_count"
node_count_data = {
"count": 0,
"max": 0,
"interval": 1,
"fname": str(env.Dir("#")) + "/.scons_node_count",
}

import time, math

Expand All @@ -746,10 +748,11 @@ def __init__(self, path=None, limit=1073741824, half_life=43200):
self.delete(self.file_list())

def __call__(self, node, *args, **kw):
nonlocal node_count, node_count_max, node_count_interval, node_count_fname, show_progress
if show_progress:
# Print the progress percentage
node_count += node_count_interval
node_count_data["count"] += node_count_data["interval"]
node_count = node_count_data["count"]
node_count_max = node_count_data["max"]
if node_count_max > 0 and node_count <= node_count_max:
screen.write("\r[%3d%%] " % (node_count * 100 / node_count_max))
screen.flush()
Expand Down Expand Up @@ -817,14 +820,13 @@ def get_size(self, start_path="."):
return total_size

def progress_finish(target, source, env):
nonlocal node_count, progressor
with open(node_count_fname, "w") as f:
f.write("%d\n" % node_count)
with open(node_count_data["fname"], "w") as f:
f.write("%d\n" % node_count_data["count"])
progressor.delete(progressor.file_list())

try:
with open(node_count_fname) as f:
node_count_max = int(f.readline())
with open(node_count_data["fname"]) as f:
node_count_data["max"] = int(f.readline())
except:
pass

Expand All @@ -833,7 +835,7 @@ def progress_finish(target, source, env):
# cache directory to a size not larger than cache_limit.
cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
progressor = cache_progress(cache_directory, cache_limit)
Progress(progressor, interval=node_count_interval)
Progress(progressor, interval=node_count_data["interval"])

progress_finish_command = Command("progress_finish", [], progress_finish)
AlwaysBuild(progress_finish_command)
Expand All @@ -844,7 +846,7 @@ def dump(env):
from json import dump

def non_serializable(obj):
return "<<non-serializable: %s>>" % (type(obj).__qualname__)
return "<<non-serializable: %s>>" % (qualname(type(obj)))

with open(".scons_env.json", "w") as f:
dump(env.Dictionary(), f, indent=4, default=non_serializable)

0 comments on commit e922c6f

Please sign in to comment.