SCons: Fix import clash between Godot and system modules

See #24965 for details. `sys.path.insert` is hacky, but should work
relatively well for both Python 2 and Python 3. When we eventually
deprecate Python 2 support, we could look into using importlib.

Fixes #24965.

(cherry picked from commit 644b266bae)
This commit is contained in:
Rémi Verschelde 2019-02-10 15:22:31 +01:00
parent 917d027941
commit f4b3756e85

View file

@ -2,12 +2,13 @@
EnsureSConsVersion(0, 98, 1) EnsureSConsVersion(0, 98, 1)
# System
import string
import os
import os.path
import glob import glob
import os
import string
import sys import sys
# Local
import methods import methods
# moved below to compensate with module version string # moved below to compensate with module version string
@ -30,7 +31,7 @@ for x in glob.glob("platform/*"):
continue continue
tmppath = "./" + x tmppath = "./" + x
sys.path.append(tmppath) sys.path.insert(0, tmppath)
import detect import detect
if (os.path.exists(x + "/export/export.cpp")): if (os.path.exists(x + "/export/export.cpp")):
@ -138,7 +139,6 @@ customs = ['custom.py']
profile = ARGUMENTS.get("profile", False) profile = ARGUMENTS.get("profile", False)
if profile: if profile:
import os.path
if os.path.isfile(profile): if os.path.isfile(profile):
customs.append(profile) customs.append(profile)
elif os.path.isfile(profile + ".py"): elif os.path.isfile(profile + ".py"):
@ -214,7 +214,7 @@ for k in platform_opts.keys():
for x in module_list: for x in module_list:
module_enabled = True module_enabled = True
tmppath = "./modules/" + x tmppath = "./modules/" + x
sys.path.append(tmppath) sys.path.insert(0, tmppath)
import config import config
enabled_attr = getattr(config, "is_enabled", None) enabled_attr = getattr(config, "is_enabled", None)
if (callable(enabled_attr) and not config.is_enabled()): if (callable(enabled_attr) and not config.is_enabled()):
@ -234,14 +234,6 @@ env_base.Append(CPPPATH=['#core', '#core/math', '#editor', '#drivers', '#'])
env_base.platform_exporters = platform_exporters env_base.platform_exporters = platform_exporters
env_base.platform_apis = platform_apis env_base.platform_apis = platform_apis
"""
sys.path.append("./platform/"+env_base["platform"])
import detect
detect.configure(env_base)
sys.path.remove("./platform/"+env_base["platform"])
sys.modules.pop('detect')
"""
if (env_base['target'] == 'debug'): if (env_base['target'] == 'debug'):
env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC'])
env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE']) env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE'])
@ -265,8 +257,8 @@ elif env_base['p'] != "":
if selected_platform in platform_list: if selected_platform in platform_list:
tmppath = "./platform/" + selected_platform
sys.path.append("./platform/" + selected_platform) sys.path.insert(0, tmppath)
import detect import detect
if "create" in dir(detect): if "create" in dir(detect):
env = detect.create(env_base) env = detect.create(env_base)
@ -391,7 +383,7 @@ if selected_platform in platform_list:
suffix += env.extra_suffix suffix += env.extra_suffix
sys.path.remove("./platform/" + selected_platform) sys.path.remove(tmppath)
sys.modules.pop('detect') sys.modules.pop('detect')
env.module_list = [] env.module_list = []
@ -401,7 +393,7 @@ if selected_platform in platform_list:
if not env['module_' + x + '_enabled']: if not env['module_' + x + '_enabled']:
continue continue
tmppath = "./modules/" + x tmppath = "./modules/" + x
sys.path.append(tmppath) sys.path.insert(0, tmppath)
env.current_module = x env.current_module = x
import config import config
if (config.can_build(selected_platform)): if (config.can_build(selected_platform)):