summaryrefslogtreecommitdiffstats
path: root/methods.py
diff options
context:
space:
mode:
Diffstat (limited to 'methods.py')
-rw-r--r--methods.py96
1 files changed, 75 insertions, 21 deletions
diff --git a/methods.py b/methods.py
index 99c47ca077..bfd08cfc7b 100644
--- a/methods.py
+++ b/methods.py
@@ -8,7 +8,7 @@ from collections import OrderedDict
from enum import Enum
from io import StringIO, TextIOWrapper
from pathlib import Path
-from typing import Generator, Optional
+from typing import Generator, List, Optional, Union
# Get the "Godot" folder name ahead of time
base_folder_path = str(os.path.abspath(Path(__file__).parent)) + "/"
@@ -163,7 +163,7 @@ def add_source_files(self, sources, files, allow_gen=False):
def disable_warnings(self):
# 'self' is the environment
- if self.msvc:
+ if self.msvc and not using_clang(self):
# We have to remove existing warning level defines before appending /w,
# otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
self["CCFLAGS"] = [x for x in self["CCFLAGS"] if not (x.startswith("/W") or x.startswith("/w"))]
@@ -268,7 +268,7 @@ def get_version_info(module_version_string="", silent=False):
if os.path.exists(".git"):
try:
version_info["git_timestamp"] = subprocess.check_output(
- ["git", "log", "-1", "--pretty=format:%ct", githash]
+ ["git", "log", "-1", "--pretty=format:%ct", "--no-show-signature", githash]
).decode("utf-8")
except (subprocess.CalledProcessError, OSError):
# `git` not found in PATH.
@@ -495,6 +495,8 @@ def use_windows_spawn_fix(self, platform=None):
rv = proc.wait()
if rv:
print_error(err)
+ elif len(err) > 0 and not err.isspace():
+ print(err)
return rv
def mySpawn(sh, escape, cmd, args, env):
@@ -648,6 +650,7 @@ def detect_visual_c_compiler_version(tools_env):
def find_visual_c_batch_file(env):
+ # TODO: We should investigate if we can avoid relying on SCons internals here.
from SCons.Tool.MSCommon.vc import find_batch_file, find_vc_pdir, get_default_version, get_host_target
msvc_version = get_default_version(env)
@@ -661,10 +664,11 @@ def find_visual_c_batch_file(env):
if env.scons_version < (4, 6, 0):
return find_batch_file(env, msvc_version, host_platform, target_platform)[0]
- # Scons 4.6.0+ removed passing env, so we need to get the product_dir ourselves first,
+ # SCons 4.6.0+ removed passing env, so we need to get the product_dir ourselves first,
# then pass that as the last param instead of env as the first param as before.
- # We should investigate if we can avoid relying on SCons internals here.
- product_dir = find_vc_pdir(env, msvc_version)
+ # Param names need to be explicit, as they were shuffled around in SCons 4.8.0.
+ product_dir = find_vc_pdir(msvc_version=msvc_version, env=env)
+
return find_batch_file(msvc_version, host_platform, target_platform, product_dir)[0]
@@ -676,6 +680,17 @@ def generate_cpp_hint_file(filename):
try:
with open(filename, "w", encoding="utf-8", newline="\n") as fd:
fd.write("#define GDCLASS(m_class, m_inherits)\n")
+ for name in ["GDVIRTUAL", "EXBIND", "MODBIND"]:
+ for count in range(13):
+ for suffix in ["", "R", "C", "RC"]:
+ fd.write(f"#define {name}{count}{suffix}(")
+ if "R" in suffix:
+ fd.write("m_ret, ")
+ fd.write("m_name")
+ for idx in range(1, count + 1):
+ fd.write(f", type{idx}")
+ fd.write(")\n")
+
except OSError:
print_warning("Could not write cpp.hint file.")
@@ -802,21 +817,20 @@ def get_compiler_version(env):
"apple_patch3": -1,
}
- if not env.msvc:
- # Not using -dumpversion as some GCC distros only return major, and
- # Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
- try:
- version = (
- subprocess.check_output([env.subst(env["CXX"]), "--version"], shell=(os.name == "nt"))
- .strip()
- .decode("utf-8")
- )
- except (subprocess.CalledProcessError, OSError):
- print_warning("Couldn't parse CXX environment variable to infer compiler version.")
- return ret
- else:
+ if env.msvc and not using_clang(env):
# TODO: Implement for MSVC
return ret
+
+ # Not using -dumpversion as some GCC distros only return major, and
+ # Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
+ try:
+ version = subprocess.check_output(
+ [env.subst(env["CXX"]), "--version"], shell=(os.name == "nt"), encoding="utf-8"
+ ).strip()
+ except (subprocess.CalledProcessError, OSError):
+ print_warning("Couldn't parse CXX environment variable to infer compiler version.")
+ return ret
+
match = re.search(
r"(?:(?<=version )|(?<=\) )|(?<=^))"
r"(?P<major>\d+)"
@@ -1034,7 +1048,7 @@ def dump(env):
# skip the build process. This lets project files be quickly generated even if there are build errors.
#
# To generate AND build from the command line:
-# scons vsproj=yes vsproj_gen_only=yes
+# scons vsproj=yes vsproj_gen_only=no
def generate_vs_project(env, original_args, project_name="godot"):
# Augmented glob_recursive that also fills the dirs argument with traversed directories that have content.
def glob_recursive_2(pattern, dirs, node="."):
@@ -1502,7 +1516,7 @@ def generate_vs_project(env, original_args, project_name="godot"):
proj_template = proj_template.replace("%%DEFAULT_ITEMS%%", "\n ".join(all_items))
proj_template = proj_template.replace("%%PROPERTIES%%", "\n ".join(properties))
- with open(f"{project_name}.vcxproj", "w", encoding="utf-8", newline="\n") as f:
+ with open(f"{project_name}.vcxproj", "w", encoding="utf-8", newline="\r\n") as f:
f.write(proj_template)
if not get_bool(original_args, "vsproj_props_only", False):
@@ -1628,3 +1642,43 @@ def generated_wrapper(
file.write(f"\n\n#endif // {header_guard}")
file.write("\n")
+
+
+def to_raw_cstring(value: Union[str, List[str]]) -> str:
+ MAX_LITERAL = 16 * 1024
+
+ if isinstance(value, list):
+ value = "\n".join(value) + "\n"
+
+ split: List[bytes] = []
+ offset = 0
+ encoded = value.encode()
+
+ while offset <= len(encoded):
+ segment = encoded[offset : offset + MAX_LITERAL]
+ offset += MAX_LITERAL
+ if len(segment) == MAX_LITERAL:
+ # Try to segment raw strings at double newlines to keep readable.
+ pretty_break = segment.rfind(b"\n\n")
+ if pretty_break != -1:
+ segment = segment[: pretty_break + 1]
+ offset -= MAX_LITERAL - pretty_break - 1
+ # If none found, ensure we end with valid utf8.
+ # https://github.com/halloleo/unicut/blob/master/truncate.py
+ elif segment[-1] & 0b10000000:
+ last_11xxxxxx_index = [i for i in range(-1, -5, -1) if segment[i] & 0b11000000 == 0b11000000][0]
+ last_11xxxxxx = segment[last_11xxxxxx_index]
+ if not last_11xxxxxx & 0b00100000:
+ last_char_length = 2
+ elif not last_11xxxxxx & 0b0010000:
+ last_char_length = 3
+ elif not last_11xxxxxx & 0b0001000:
+ last_char_length = 4
+
+ if last_char_length > -last_11xxxxxx_index:
+ segment = segment[:last_11xxxxxx_index]
+ offset += last_11xxxxxx_index
+
+ split += [segment]
+
+ return " ".join(f'R"<!>({x.decode()})<!>"' for x in split)