summaryrefslogtreecommitdiff
path: root/methods.py
diff options
context:
space:
mode:
Diffstat (limited to 'methods.py')
-rw-r--r--methods.py112
1 files changed, 82 insertions, 30 deletions
diff --git a/methods.py b/methods.py
index ca6756f95f..f7134b472b 100644
--- a/methods.py
+++ b/methods.py
@@ -4,6 +4,13 @@ import glob
import subprocess
from collections import OrderedDict
+# We need to define our own `Action` method to control the verbosity of output
+# and whenever we need to run those commands in a subprocess on some platforms.
+from SCons.Script import Action
+from SCons import Node
+from SCons.Script import Glob
+from platform_methods import run_in_subprocess
+
def add_source_files(self, sources, files, warn_duplicates=True):
# Convert string to list of absolute paths (including expanding wildcard)
@@ -92,7 +99,7 @@ def update_version(module_version_string=""):
gitfolder = module_folder[8:]
if os.path.isfile(os.path.join(gitfolder, "HEAD")):
- head = open(os.path.join(gitfolder, "HEAD"), "r").readline().strip()
+ head = open(os.path.join(gitfolder, "HEAD"), "r", encoding="utf8").readline().strip()
if head.startswith("ref: "):
head = os.path.join(gitfolder, head[5:])
if os.path.isfile(head):
@@ -180,7 +187,7 @@ def write_modules(module_list):
unregister_cpp += "#ifdef MODULE_" + name.upper() + "_ENABLED\n"
unregister_cpp += "\tunregister_" + name + "_types();\n"
unregister_cpp += "#endif\n"
- except IOError:
+ except OSError:
pass
modules_cpp = """// register_module_types.gen.cpp
@@ -217,14 +224,15 @@ void unregister_module_types() {
def convert_custom_modules_path(path):
if not path:
return path
+ path = os.path.realpath(os.path.expanduser(os.path.expandvars(path)))
err_msg = "Build option 'custom_modules' must %s"
if not os.path.isdir(path):
raise ValueError(err_msg % "point to an existing directory.")
- if os.path.realpath(path) == os.path.realpath("modules"):
+ if path == os.path.realpath("modules"):
raise ValueError(err_msg % "be a directory other than built-in `modules` directory.")
if is_module(path):
raise ValueError(err_msg % "point to a directory with modules, not a single module.")
- return os.path.realpath(os.path.expanduser(path))
+ return path
def disable_module(self):
@@ -516,10 +524,39 @@ def generate_cpp_hint_file(filename):
try:
with open(filename, "w") as fd:
fd.write("#define GDCLASS(m_class, m_inherits)\n")
- except IOError:
+ except OSError:
print("Could not write cpp.hint file.")
+def glob_recursive(pattern, node="."):
+ results = []
+ for f in Glob(str(node) + "/*", source=True):
+ if type(f) is Node.FS.Dir:
+ results += glob_recursive(pattern, f)
+ results += Glob(str(node) + "/" + pattern, source=True)
+ return results
+
+
+def add_to_vs_project(env, sources):
+ for x in sources:
+ if type(x) == type(""):
+ fname = env.File(x).path
+ else:
+ fname = env.File(x)[0].path
+ pieces = fname.split(".")
+ if len(pieces) > 0:
+ basename = pieces[0]
+ basename = basename.replace("\\\\", "/")
+ if os.path.isfile(basename + ".h"):
+ env.vs_incs += [basename + ".h"]
+ elif os.path.isfile(basename + ".hpp"):
+ env.vs_incs += [basename + ".hpp"]
+ if os.path.isfile(basename + ".c"):
+ env.vs_srcs += [basename + ".c"]
+ elif os.path.isfile(basename + ".cpp"):
+ env.vs_srcs += [basename + ".cpp"]
+
+
def generate_vs_project(env, num_jobs):
batch_file = find_visual_c_batch_file(env)
if batch_file:
@@ -528,37 +565,44 @@ def generate_vs_project(env, num_jobs):
common_build_prefix = [
'cmd /V /C set "plat=$(PlatformTarget)"',
'(if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64"))',
- 'set "tools=yes"',
+ 'set "tools=%s"' % env["tools"],
'(if "$(Configuration)"=="release" (set "tools=no"))',
'call "' + batch_file + '" !plat!',
]
- result = " ^& ".join(common_build_prefix + [commands])
+ # windows allows us to have spaces in paths, so we need
+ # to double quote off the directory. However, the path ends
+ # in a backslash, so we need to remove this, lest it escape the
+ # last double quote off, confusing MSBuild
+ common_build_postfix = [
+ "--directory=\"$(ProjectDir.TrimEnd('\\'))\"",
+ "platform=windows",
+ "target=$(Configuration)",
+ "progress=no",
+ "tools=!tools!",
+ "-j%s" % num_jobs,
+ ]
+
+ if env["custom_modules"]:
+ common_build_postfix.append("custom_modules=%s" % env["custom_modules"])
+
+ result = " ^& ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)])
return result
- env.AddToVSProject(env.core_sources)
- env.AddToVSProject(env.main_sources)
- env.AddToVSProject(env.modules_sources)
- env.AddToVSProject(env.scene_sources)
- env.AddToVSProject(env.servers_sources)
- env.AddToVSProject(env.editor_sources)
-
- # windows allows us to have spaces in paths, so we need
- # to double quote off the directory. However, the path ends
- # in a backslash, so we need to remove this, lest it escape the
- # last double quote off, confusing MSBuild
- env["MSVSBUILDCOM"] = build_commandline(
- "scons --directory=\"$(ProjectDir.TrimEnd('\\'))\" platform=windows progress=no target=$(Configuration) tools=!tools! -j"
- + str(num_jobs)
- )
- env["MSVSREBUILDCOM"] = build_commandline(
- "scons --directory=\"$(ProjectDir.TrimEnd('\\'))\" platform=windows progress=no target=$(Configuration) tools=!tools! vsproj=yes -j"
- + str(num_jobs)
- )
- env["MSVSCLEANCOM"] = build_commandline(
- "scons --directory=\"$(ProjectDir.TrimEnd('\\'))\" --clean platform=windows progress=no target=$(Configuration) tools=!tools! -j"
- + str(num_jobs)
- )
+ add_to_vs_project(env, env.core_sources)
+ add_to_vs_project(env, env.drivers_sources)
+ add_to_vs_project(env, env.main_sources)
+ add_to_vs_project(env, env.modules_sources)
+ add_to_vs_project(env, env.scene_sources)
+ add_to_vs_project(env, env.servers_sources)
+ add_to_vs_project(env, env.editor_sources)
+
+ for header in glob_recursive("**/*.h"):
+ env.vs_incs.append(str(header))
+
+ env["MSVSBUILDCOM"] = build_commandline("scons")
+ env["MSVSREBUILDCOM"] = build_commandline("scons vsproj=yes")
+ env["MSVSCLEANCOM"] = build_commandline("scons --clean")
# This version information (Win32, x64, Debug, Release, Release_Debug seems to be
# required for Visual Studio to understand that it needs to generate an NMAKE
@@ -617,6 +661,14 @@ def CommandNoCache(env, target, sources, command, **args):
return result
+def Run(env, function, short_message, subprocess=True):
+ output_print = short_message if not env["verbose"] else ""
+ if not subprocess:
+ return Action(function, output_print)
+ else:
+ return Action(run_in_subprocess(function), output_print)
+
+
def detect_darwin_sdk_path(platform, env):
sdk_name = ""
if platform == "osx":