Skip to content

Commit 467038d

Browse files
committed
Merge pull request godotengine#82325 from MarioLiebisch/updated-compiler-version-detection
Updated compiler version detection
2 parents c1b29ea + 7653973 commit 467038d

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

methods.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,19 +1002,32 @@ def is_vanilla_clang(env):
10021002

10031003
def get_compiler_version(env):
10041004
"""
1005-
Returns an array of version numbers as ints: [major, minor, patch].
1006-
The return array should have at least two values (major, minor).
1005+
Returns a dictionary with various version information:
1006+
1007+
- major, minor, patch: Version following semantic versioning system
1008+
- metadata1, metadata2: Extra information
1009+
- date: Date of the build
10071010
"""
1011+
ret = {
1012+
"major": -1,
1013+
"minor": -1,
1014+
"patch": -1,
1015+
"metadata1": None,
1016+
"metadata2": None,
1017+
"date": None,
1018+
}
1019+
10081020
if not env.msvc:
10091021
# Not using -dumpversion as some GCC distros only return major, and
10101022
# Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
10111023
try:
1012-
version = subprocess.check_output([env.subst(env["CXX"]), "--version"]).strip().decode("utf-8")
1024+
version = subprocess.check_output([env.subst(env["CXX"]), "--version"], shell=True).strip().decode("utf-8")
10131025
except (subprocess.CalledProcessError, OSError):
10141026
print("Couldn't parse CXX environment variable to infer compiler version.")
1015-
return None
1016-
else: # TODO: Implement for MSVC
1017-
return None
1027+
return ret
1028+
else:
1029+
# TODO: Implement for MSVC
1030+
return ret
10181031
match = re.search(
10191032
r"(?:(?<=version )|(?<=\) )|(?<=^))"
10201033
r"(?P<major>\d+)"
@@ -1026,9 +1039,13 @@ def get_compiler_version(env):
10261039
version,
10271040
)
10281041
if match is not None:
1029-
return match.groupdict()
1030-
else:
1031-
return None
1042+
for key, value in match.groupdict().items():
1043+
if value is not None:
1044+
ret[key] = value
1045+
# Transform semantic versioning to integers
1046+
for key in ["major", "minor", "patch"]:
1047+
ret[key] = int(ret[key] or -1)
1048+
return ret
10321049

10331050

10341051
def using_gcc(env):

platform/linuxbsd/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def configure(env: "Environment"):
106106
print("Using linker program: " + env["linker"])
107107
if env["linker"] == "mold" and using_gcc(env): # GCC < 12.1 doesn't support -fuse-ld=mold.
108108
cc_version = get_compiler_version(env)
109-
cc_semver = (int(cc_version["major"]), int(cc_version["minor"]))
109+
cc_semver = (cc_version["major"], cc_version["minor"])
110110
if cc_semver < (12, 1):
111111
found_wrapper = False
112112
for path in ["/usr/libexec", "/usr/local/libexec", "/usr/lib", "/usr/local/lib"]:

platform/macos/detect.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,9 @@ def configure(env: "Environment"):
120120
env.Append(CCFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.13"])
121121
env.Append(LINKFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.13"])
122122

123-
cc_version = get_compiler_version(env) or {
124-
"major": None,
125-
"minor": None,
126-
"patch": None,
127-
"metadata1": None,
128-
"metadata2": None,
129-
"date": None,
130-
}
131-
cc_version_major = int(cc_version["major"] or -1)
132-
cc_version_minor = int(cc_version["minor"] or -1)
123+
cc_version = get_compiler_version(env)
124+
cc_version_major = cc_version["major"]
125+
cc_version_minor = cc_version["minor"]
133126
vanilla = is_vanilla_clang(env)
134127

135128
# Workaround for Xcode 15 linker bug.

platform/web/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def configure(env: "Environment"):
203203

204204
# Get version info for checks below.
205205
cc_version = get_compiler_version(env)
206-
cc_semver = (int(cc_version["major"]), int(cc_version["minor"]), int(cc_version["patch"]))
206+
cc_semver = (cc_version["major"], cc_version["minor"], cc_version["patch"])
207207

208208
if env["lto"] != "none":
209209
# Workaround https://github.com/emscripten-core/emscripten/issues/19781.

0 commit comments

Comments
 (0)