SCons: Fix running 'scons' without platform argument

The cache and progress logic assumed the 'env' to be defined,
but it is only when the selected platform is in the supported list.

Fixes #17497.
This commit is contained in:
Rémi Verschelde 2018-03-14 14:42:43 +01:00
parent ea204628ad
commit a44f9ca545
1 changed files with 104 additions and 106 deletions

View File

@ -491,25 +491,22 @@ else:
for x in platform_list: for x in platform_list:
print("\t" + x) print("\t" + x)
print("\nPlease run scons again with argument: platform=<string>") print("\nPlease run scons again with argument: platform=<string>")
sys.exit(255)
screen = sys.stdout # The following only makes sense when the env is defined, and assumes it is
node_count = 0 if 'env' in locals():
node_count_max = 0 screen = sys.stdout
node_count_interval = 1 # Progress reporting is not available in non-TTY environments since it
if ('env' in locals()): # 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_fname = str(env.Dir('#')) + '/.scons_node_count'
# Progress reporting is not available in non-TTY environments since it
# messes with the output (for example, when writing to a file)
if sys.stdout.isatty():
show_progress = env['progress']
else:
show_progress = False
import time, math import time, math
class cache_progress: class cache_progress:
# The default is 1 GB cache and 12 hours half life # The default is 1 GB cache and 12 hours half life
def __init__(self, path = None, limit = 1073741824, half_life = 43200): def __init__(self, path = None, limit = 1073741824, half_life = 43200):
self.path = path self.path = path
@ -590,23 +587,24 @@ class cache_progress:
total_size += os.path.getsize(fp) total_size += os.path.getsize(fp)
return total_size return total_size
def progress_finish(target, source, env): def progress_finish(target, source, env):
global node_count, progressor global node_count, progressor
with open(node_count_fname, 'w') as f: with open(node_count_fname, 'w') as f:
f.write('%d\n' % node_count) f.write('%d\n' % node_count)
progressor.delete(progressor.file_list()) progressor.delete(progressor.file_list())
try: try:
with open(node_count_fname) as f: with open(node_count_fname) as f:
node_count_max = int(f.readline()) node_count_max = int(f.readline())
except: except:
pass pass
cache_directory = os.environ.get("SCONS_CACHE")
# Simple cache pruning, attached to SCons' progress callback. Trim the
# 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_finish_command = Command('progress_finish', [], progress_finish) cache_directory = os.environ.get("SCONS_CACHE")
AlwaysBuild(progress_finish_command) # Simple cache pruning, attached to SCons' progress callback. Trim the
# 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_finish_command = Command('progress_finish', [], progress_finish)
AlwaysBuild(progress_finish_command)