Skip to content

Commit 7aacdaa

Browse files
committed
Build System: Extract validate_arch helper function
Signed-off-by: Yevhen Babiichuk (DustDFG) <dfgdust@gmail.com>
1 parent db66bd3 commit 7aacdaa

File tree

7 files changed

+22
-39
lines changed

7 files changed

+22
-39
lines changed

platform/android/detect.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING
66

77
from methods import print_error, print_warning
8+
from platform_methods import validate_arch
89

910
if TYPE_CHECKING:
1011
from SCons.Script.SConscript import SConsEnvironment
@@ -98,12 +99,7 @@ def install_ndk_if_needed(env: "SConsEnvironment"):
9899
def configure(env: "SConsEnvironment"):
99100
# Validate arch.
100101
supported_arches = ["x86_32", "x86_64", "arm32", "arm64"]
101-
if env["arch"] not in supported_arches:
102-
print_error(
103-
'Unsupported CPU architecture "%s" for Android. Supported architectures are: %s.'
104-
% (env["arch"], ", ".join(supported_arches))
105-
)
106-
sys.exit(255)
102+
validate_arch(env["arch"], get_name(), supported_arches)
107103

108104
if get_min_sdk_version(env["ndk_platform"]) < get_min_target_api():
109105
print_warning(

platform/ios/detect.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
from methods import detect_darwin_sdk_path, print_error, print_warning
6+
from platform_methods import validate_arch
67

78
if TYPE_CHECKING:
89
from SCons.Script.SConscript import SConsEnvironment
@@ -60,12 +61,7 @@ def get_flags():
6061
def configure(env: "SConsEnvironment"):
6162
# Validate arch.
6263
supported_arches = ["x86_64", "arm64"]
63-
if env["arch"] not in supported_arches:
64-
print_error(
65-
'Unsupported CPU architecture "%s" for iOS. Supported architectures are: %s.'
66-
% (env["arch"], ", ".join(supported_arches))
67-
)
68-
sys.exit(255)
64+
validate_arch(env["arch"], get_name(), supported_arches)
6965

7066
## LTO
7167

platform/linuxbsd/detect.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING
55

66
from methods import get_compiler_version, print_error, print_warning, using_gcc
7-
from platform_methods import detect_arch
7+
from platform_methods import detect_arch, validate_arch
88

99
if TYPE_CHECKING:
1010
from SCons.Script.SConscript import SConsEnvironment
@@ -74,12 +74,7 @@ def get_flags():
7474
def configure(env: "SConsEnvironment"):
7575
# Validate arch.
7676
supported_arches = ["x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64"]
77-
if env["arch"] not in supported_arches:
78-
print_error(
79-
'Unsupported CPU architecture "%s" for Linux / *BSD. Supported architectures are: %s.'
80-
% (env["arch"], ", ".join(supported_arches))
81-
)
82-
sys.exit(255)
77+
validate_arch(env["arch"], get_name(), supported_arches)
8378

8479
## Build type
8580

platform/macos/detect.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
from methods import detect_darwin_sdk_path, get_compiler_version, is_vanilla_clang, print_error, print_warning
6-
from platform_methods import detect_arch, detect_mvk
6+
from platform_methods import detect_arch, detect_mvk, validate_arch
77

88
if TYPE_CHECKING:
99
from SCons.Script.SConscript import SConsEnvironment
@@ -68,12 +68,7 @@ def get_flags():
6868
def configure(env: "SConsEnvironment"):
6969
# Validate arch.
7070
supported_arches = ["x86_64", "arm64"]
71-
if env["arch"] not in supported_arches:
72-
print_error(
73-
'Unsupported CPU architecture "%s" for macOS. Supported architectures are: %s.'
74-
% (env["arch"], ", ".join(supported_arches))
75-
)
76-
sys.exit(255)
71+
validate_arch(env["arch"], get_name(), supported_arches)
7772

7873
## Build type
7974

platform/web/detect.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from SCons.Util import WhereIs
1515

1616
from methods import get_compiler_version, print_error, print_warning
17+
from platform_methods import validate_arch
1718

1819
if TYPE_CHECKING:
1920
from SCons.Script.SConscript import SConsEnvironment
@@ -86,12 +87,7 @@ def get_flags():
8687
def configure(env: "SConsEnvironment"):
8788
# Validate arch.
8889
supported_arches = ["wasm32"]
89-
if env["arch"] not in supported_arches:
90-
print_error(
91-
'Unsupported CPU architecture "%s" for Web. Supported architectures are: %s.'
92-
% (env["arch"], ", ".join(supported_arches))
93-
)
94-
sys.exit(255)
90+
validate_arch(env["arch"], get_name(), supported_arches)
9591

9692
try:
9793
env["initial_memory"] = int(env["initial_memory"])

platform/windows/detect.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import methods
88
from methods import print_error, print_warning
9-
from platform_methods import detect_arch
9+
from platform_methods import detect_arch, validate_arch
1010

1111
if TYPE_CHECKING:
1212
from SCons.Script.SConscript import SConsEnvironment
@@ -950,12 +950,7 @@ def configure_mingw(env: "SConsEnvironment"):
950950
def configure(env: "SConsEnvironment"):
951951
# Validate arch.
952952
supported_arches = ["x86_32", "x86_64", "arm32", "arm64"]
953-
if env["arch"] not in supported_arches:
954-
print_error(
955-
'Unsupported CPU architecture "%s" for Windows. Supported architectures are: %s.'
956-
% (env["arch"], ", ".join(supported_arches))
957-
)
958-
sys.exit(255)
953+
validate_arch(env["arch"], get_name(), supported_arches)
959954

960955
# At this point the env has been set up with basic tools/compilers.
961956
env.Prepend(CPPPATH=["#platform/windows"])

platform_methods.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import platform
33
import subprocess
4+
import sys
45

56
import methods
67

@@ -40,6 +41,15 @@ def detect_arch():
4041
return "x86_64"
4142

4243

44+
def validate_arch(arch, platform_name, supported_arches):
45+
if arch not in supported_arches:
46+
methods.print_error(
47+
'Unsupported CPU architecture "%s" for %s. Supported architectures are: %s.'
48+
% (arch, platform_name, ", ".join(supported_arches))
49+
)
50+
sys.exit(255)
51+
52+
4353
def get_build_version(short):
4454
import version
4555

0 commit comments

Comments
 (0)