Skip to content

Commit 017f265

Browse files
committed
Build: enhance check messages
1 parent 4279f27 commit 017f265

1 file changed

Lines changed: 44 additions & 13 deletions

File tree

build-system/luxmake/check.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import subprocess
99
import re
1010
from dataclasses import dataclass
11+
from enum import Enum
1112

12-
from .utils import logger, fail
13+
from .utils import logger, fail, Colors
1314

1415

1516
@dataclass
@@ -21,6 +22,14 @@ class Require:
2122
mandatory: bool
2223

2324

25+
class Status(Enum):
26+
"""Requirement status."""
27+
28+
OK = 0
29+
WARN = 1
30+
ERROR = 2
31+
32+
2433
REQUIREMENTS = (
2534
Require("conan", None, True),
2635
Require("wheel", None, True),
@@ -47,14 +56,28 @@ def _version_tuple(version_str):
4756
def check(name, min_version=None, mandatory=True):
4857
"""Check whether an app exists and whether its version is correct."""
4958

59+
# Prepare display
60+
display_name = name if mandatory else f"{name} (optional)"
61+
prefix = f"Looking for '{display_name}' - "
62+
5063
def error(*args):
51-
log = logger.error if mandatory else logger.warning
52-
log(*args)
53-
return not mandatory
64+
if mandatory:
65+
log = logger.error
66+
color = Colors.FAIL
67+
status = Status.ERROR
68+
else:
69+
log = logger.warning
70+
color = Colors.WARNING
71+
status = Status.WARN
72+
73+
msg, *others = args
74+
msg = f"{color}{prefix}{msg}{Colors.ENDC}"
75+
log(msg, *others)
76+
return status
5477

5578
# Existence
5679
if not (app := shutil.which(name)):
57-
return error("'%s' is missing!", name)
80+
return error("'%s' is missing!", display_name)
5881

5982
# Get version
6083
result = subprocess.run(
@@ -73,28 +96,36 @@ def error(*args):
7396

7497
# Translate version
7598
if not (version := _version_tuple(version_str)):
76-
return error("Cannot read '%s' version", name)
99+
return error("Cannot read '%s' version", display_name)
77100
if version < min_version:
78101
return error(
79102
"'%s': installed version ('%s') is lower than required ('%s')",
80-
app,
103+
display_name,
81104
version_str,
82105
min_version_str,
83106
)
84107
if version_str:
85-
logger.info("Looking for '%s' - Found '%s', version '%s'", name, app, version_str)
108+
logger.info(
109+
prefix + "Found '%s', version '%s'",
110+
app,
111+
version_str,
112+
)
86113
else:
87-
logger.info("Looking for '%s' - Found '%s'", name, app)
114+
logger.info(prefix + "Found '%s'", app)
88115

89116
return True
90117

91118

92119
def check_requirements():
93120
"""Check all requirements."""
94121
logger.info("Checking requirements:")
95-
checks = (
122+
checks = [
96123
check(req.name, req.min_version, req.mandatory) for req in REQUIREMENTS
97-
)
98-
if not all(checks):
124+
]
125+
if all(c == Status.OK for c in checks):
126+
logger.info("Requirements - OK")
127+
128+
if any(c == Status.ERROR for c in checks):
99129
fail("Some mandatory requirements are missing. Please check...")
100-
logger.info("Requirements - OK")
130+
131+
logger.info("Requirements - OK (some warnings)")

0 commit comments

Comments
 (0)