Merge pull request #20617 from viktor-ferenczi/issue-20613
Fix Mac build
This commit is contained in:
commit
6c569c90b6
|
@ -7,6 +7,11 @@ import subprocess
|
||||||
|
|
||||||
# NOTE: The multiprocessing module is not compatible with SCons due to conflict on cPickle
|
# NOTE: The multiprocessing module is not compatible with SCons due to conflict on cPickle
|
||||||
|
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
JSON_SERIALIZABLE_TYPES = (bool, int, long, float, basestring)
|
||||||
|
else:
|
||||||
|
JSON_SERIALIZABLE_TYPES = (bool, int, float, str)
|
||||||
|
|
||||||
|
|
||||||
def run_in_subprocess(builder_function):
|
def run_in_subprocess(builder_function):
|
||||||
|
|
||||||
|
@ -17,9 +22,9 @@ def run_in_subprocess(builder_function):
|
||||||
target = [node.srcnode().abspath for node in target]
|
target = [node.srcnode().abspath for node in target]
|
||||||
source = [node.srcnode().abspath for node in source]
|
source = [node.srcnode().abspath for node in source]
|
||||||
|
|
||||||
# Short circuit on non-Windows platforms
|
# Short circuit on non-Windows platforms, no need to run in subprocess
|
||||||
if os.name != 'nt':
|
if sys.platform not in ('win32', 'cygwin'):
|
||||||
return builder_function(target, source, None)
|
return builder_function(target, source, env)
|
||||||
|
|
||||||
# Identify module
|
# Identify module
|
||||||
module_name = builder_function.__module__
|
module_name = builder_function.__module__
|
||||||
|
@ -32,14 +37,25 @@ def run_in_subprocess(builder_function):
|
||||||
subprocess_env = os.environ.copy()
|
subprocess_env = os.environ.copy()
|
||||||
subprocess_env['PYTHONPATH'] = os.pathsep.join([os.getcwd()] + sys.path)
|
subprocess_env['PYTHONPATH'] = os.pathsep.join([os.getcwd()] + sys.path)
|
||||||
|
|
||||||
|
# Keep only JSON serializable environment items
|
||||||
|
filtered_env = dict(
|
||||||
|
(key, value)
|
||||||
|
for key, value in env.items()
|
||||||
|
if isinstance(value, JSON_SERIALIZABLE_TYPES)
|
||||||
|
)
|
||||||
|
|
||||||
# Save parameters
|
# Save parameters
|
||||||
args = (target, source, None)
|
args = (target, source, filtered_env)
|
||||||
data = dict(fn=function_name, args=args)
|
data = dict(fn=function_name, args=args)
|
||||||
json_path = os.path.join(os.environ['TMP'], uuid.uuid4().hex + '.json')
|
json_path = os.path.join(os.environ['TMP'], uuid.uuid4().hex + '.json')
|
||||||
with open(json_path, 'wt') as json_file:
|
with open(json_path, 'wt') as json_file:
|
||||||
json.dump(data, json_file, indent=2)
|
json.dump(data, json_file, indent=2)
|
||||||
|
json_file_size = os.stat(json_path).st_size
|
||||||
|
|
||||||
|
print('Executing builder function in subprocess: '
|
||||||
|
'module_path=%r, parameter_file=%r, parameter_file_size=%r, target=%r, source=%r' % (
|
||||||
|
module_path, json_path, json_file_size, target, source))
|
||||||
try:
|
try:
|
||||||
print('Executing builder function in subprocess: module_path=%r; data=%r' % (module_path, data))
|
|
||||||
exit_code = subprocess.call([sys.executable, module_path, json_path], env=subprocess_env)
|
exit_code = subprocess.call([sys.executable, module_path, json_path], env=subprocess_env)
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue