Skip to content

Commit 5773536

Browse files
committed
Print an error if the godot-cpp submodule hasn't been initialized
This makes the error that is printed easier to understand, with a command given as a solution to run. The error message is also colored to match how core Godot displays this kind of build errors.
1 parent 9074766 commit 5773536

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

SConstruct

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env python
22
import os
3+
import sys
4+
5+
from methods import print_error
36

47

58
def normalize_path(val, env):
@@ -48,6 +51,19 @@ compilation_db = env.CompilationDatabase(
4851
)
4952
env.Alias("compiledb", compilation_db)
5053

54+
submodule_initialized = False
55+
dir_name = 'godot-cpp'
56+
if os.path.isdir(dir_name):
57+
if os.listdir(dir_name):
58+
submodule_initialized = True
59+
60+
if not submodule_initialized:
61+
print_error("""godot-cpp is not available within this folder, as Git submodules haven't been initialized.
62+
Run the following command to download godot-cpp:
63+
64+
git submodule update --init --recursive""")
65+
sys.exit(1)
66+
5167
env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})
5268

5369
env.Append(CPPPATH=["src/"])

methods.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
import sys
3+
from enum import Enum
4+
5+
# Colors are disabled in non-TTY environments such as pipes. This means
6+
# that if output is redirected to a file, it won't contain color codes.
7+
# Colors are always enabled on continuous integration.
8+
_colorize = bool(sys.stdout.isatty() or os.environ.get("CI"))
9+
10+
11+
class ANSI(Enum):
12+
"""
13+
Enum class for adding ansi colorcodes directly into strings.
14+
Automatically converts values to strings representing their
15+
internal value, or an empty string in a non-colorized scope.
16+
"""
17+
18+
RESET = "\x1b[0m"
19+
20+
BOLD = "\x1b[1m"
21+
ITALIC = "\x1b[3m"
22+
UNDERLINE = "\x1b[4m"
23+
STRIKETHROUGH = "\x1b[9m"
24+
REGULAR = "\x1b[22;23;24;29m"
25+
26+
BLACK = "\x1b[30m"
27+
RED = "\x1b[31m"
28+
GREEN = "\x1b[32m"
29+
YELLOW = "\x1b[33m"
30+
BLUE = "\x1b[34m"
31+
MAGENTA = "\x1b[35m"
32+
CYAN = "\x1b[36m"
33+
WHITE = "\x1b[37m"
34+
35+
PURPLE = "\x1b[38;5;93m"
36+
PINK = "\x1b[38;5;206m"
37+
ORANGE = "\x1b[38;5;214m"
38+
GRAY = "\x1b[38;5;244m"
39+
40+
def __str__(self) -> str:
41+
global _colorize
42+
return str(self.value) if _colorize else ""
43+
44+
45+
def print_warning(*values: object) -> None:
46+
"""Prints a warning message with formatting."""
47+
print(f"{ANSI.YELLOW}{ANSI.BOLD}WARNING:{ANSI.REGULAR}", *values, ANSI.RESET, file=sys.stderr)
48+
49+
50+
def print_error(*values: object) -> None:
51+
"""Prints an error message with formatting."""
52+
print(f"{ANSI.RED}{ANSI.BOLD}ERROR:{ANSI.REGULAR}", *values, ANSI.RESET, file=sys.stderr)

0 commit comments

Comments
 (0)