From f4b3756e850fb61eda989ae933e58fd33150b321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 10 Feb 2019 15:22:31 +0100 Subject: [PATCH] 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 644b266bae483c903d7c588b38002e4c0ad21054) --- SConstruct | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/SConstruct b/SConstruct index bc6d37a6f29..ba309cea3c3 100644 --- a/SConstruct +++ b/SConstruct @@ -2,12 +2,13 @@ EnsureSConsVersion(0, 98, 1) - -import string -import os -import os.path +# System import glob +import os +import string import sys + +# Local import methods # moved below to compensate with module version string @@ -30,7 +31,7 @@ for x in glob.glob("platform/*"): continue tmppath = "./" + x - sys.path.append(tmppath) + sys.path.insert(0, tmppath) import detect if (os.path.exists(x + "/export/export.cpp")): @@ -138,7 +139,6 @@ customs = ['custom.py'] profile = ARGUMENTS.get("profile", False) if profile: - import os.path if os.path.isfile(profile): customs.append(profile) elif os.path.isfile(profile + ".py"): @@ -214,7 +214,7 @@ for k in platform_opts.keys(): for x in module_list: module_enabled = True tmppath = "./modules/" + x - sys.path.append(tmppath) + sys.path.insert(0, tmppath) import config enabled_attr = getattr(config, "is_enabled", None) 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_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'): env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE']) @@ -265,8 +257,8 @@ elif env_base['p'] != "": if selected_platform in platform_list: - - sys.path.append("./platform/" + selected_platform) + tmppath = "./platform/" + selected_platform + sys.path.insert(0, tmppath) import detect if "create" in dir(detect): env = detect.create(env_base) @@ -391,7 +383,7 @@ if selected_platform in platform_list: suffix += env.extra_suffix - sys.path.remove("./platform/" + selected_platform) + sys.path.remove(tmppath) sys.modules.pop('detect') env.module_list = [] @@ -401,7 +393,7 @@ if selected_platform in platform_list: if not env['module_' + x + '_enabled']: continue tmppath = "./modules/" + x - sys.path.append(tmppath) + sys.path.insert(0, tmppath) env.current_module = x import config if (config.can_build(selected_platform)):