Skip to content

Commit 6db3475

Browse files
committed
Fix internal logging and problem matching
There were two problems with the recently merged internal logging improvements: 1. I assumed that print_yellow() was only called when warning but it is also used for informational prints. 2. The regex did not work. Simplify the regex by avoiding brackets and just using a simple ERROR: and WARNING: prefix to the message. Introduce new logging functions: die() to print a message and exit with error code 1, warn() to print a warning, and info() to print information. Use these consistently throughout the scripts. Adjust certain messages so that they will be caught by the new problem matcher. Signed-off-by: Nathan Chancellor <[email protected]>
1 parent 5802870 commit 6db3475

File tree

4 files changed

+52
-50
lines changed

4 files changed

+52
-50
lines changed

.github/problem-matchers/internal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"owner": "internal",
66
"pattern": [
77
{
8-
"__comment_regexp1": "[CI ERROR] Build is not finished on TuxSuite's side!",
9-
"regexp": "^\\[CI (WARNING|ERROR)\\]\\s+(.*)$",
8+
"__comment_regexp1": "ERROR: Build is not finished on TuxSuite's side!",
9+
"regexp": "^(WARNING|ERROR):\\s+(.*)$",
1010
"severity": 1,
1111
"message": 2
1212
}

generator/generate_workflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import yaml
88

9-
from utils import CI_ROOT, LLVM_TOT_VERSION, disable_subsys_werror_configs, get_config_from_generator, get_llvm_versions, get_repo_ref, patch_series_flag, print_red
9+
from utils import CI_ROOT, LLVM_TOT_VERSION, disable_subsys_werror_configs, get_config_from_generator, get_llvm_versions, get_repo_ref, patch_series_flag, die
1010

1111

1212
def parse_args(trees):
@@ -279,8 +279,8 @@ def get_cron_schedule(schedules, tree_name, llvm_version):
279279
if item["name"] == tree_name and \
280280
item["llvm_version"] == llvm_version:
281281
return item["schedule"]
282-
print_red(f"Could not find schedule for {tree_name} clang-{llvm_version}?")
283-
sys.exit(1)
282+
return die(
283+
f"Could not find schedule for {tree_name} clang-{llvm_version}?")
284284

285285

286286
def print_builds(config, tree_name, llvm_version):

scripts/check-logs.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import time
1111
import urllib.request
1212

13-
from utils import CI_ROOT, get_build, get_image_name, get_requested_llvm_version, print_red, print_yellow, get_cbl_name, show_builds
13+
from utils import CI_ROOT, get_build, get_image_name, get_requested_llvm_version, print_red, get_cbl_name, show_builds, die, warn, info
1414

1515

1616
def _fetch(title, url, dest):
1717
current_time = time.strftime("%H:%M:%S", time.localtime())
18-
print_yellow(f"{current_time}: fetching {title} from: {url}")
18+
info(f"{current_time}: fetching {title} from: {url}")
1919
retries = 0
2020
max_retries = 7
2121
retry_codes = [404, 500, 504]
@@ -27,26 +27,22 @@ def _fetch(title, url, dest):
2727
urllib.request.urlretrieve(url, dest)
2828
break
2929
except ConnectionResetError as err:
30-
print_yellow(f"{title} download error ('{err}'), retrying...")
30+
warn(f"{title} download error ('{err}'), retrying...")
3131
except urllib.error.HTTPError as err:
3232
if err.code in retry_codes:
33-
print_yellow(
34-
f"{title} download error ({err.code}), retrying...")
33+
warn(f"{title} download error ({err.code}), retrying...")
3534
else:
36-
print_red(f"{err.code} error trying to download {title}")
37-
sys.exit(1)
35+
die(f"{err.code} error trying to download {title}")
3836
except urllib.error.URLError as err:
39-
print_yellow(f"{title} download error ('{err}'), retrying...")
37+
warn(f"{title} download error ('{err}'), retrying...")
4038

4139
if retries == max_retries:
42-
print_red(f"Unable to download {title} after {max_retries} tries")
43-
sys.exit(1)
40+
die(f"Unable to download {title} after {max_retries} tries")
4441

4542
if dest.exists():
46-
print_yellow(f"Filesize: {dest.stat().st_size}")
43+
info(f"Filesize: {dest.stat().st_size}")
4744
else:
48-
print_red(f"Unable to download {title}")
49-
sys.exit(1)
45+
die(f"Unable to download {title}")
5046

5147

5248
def verify_build():
@@ -60,8 +56,7 @@ def verify_build():
6056
while retries < max_retries:
6157
# build never started
6258
if (build_status := build['tuxbuild_status']) == 'error':
63-
print_red(f"msg from tuxsuite: {build['status_message']}")
64-
sys.exit(1)
59+
die(f"msg from tuxsuite: {build['status_message']}")
6560
# build is finished
6661
elif build_status == "complete":
6762
break
@@ -78,16 +73,14 @@ def verify_build():
7873
print(json.dumps(build, indent=4))
7974

8075
if retries == max_retries:
81-
print_red("Build is not finished on TuxSuite's side!")
82-
sys.exit(1)
76+
die("Build is not finished on TuxSuite's side!")
8377

8478
if "Build Timed Out" in build["status_message"]:
85-
print_red(build["status_message"])
86-
sys.exit(1)
79+
die(build["status_message"])
8780

8881
if build["status_message"] == "Unable to apply kernel patch":
8982
print_red(
90-
"Patch failed to apply to current kernel tree, does it need to be removed or updated?"
83+
"ERROR: Patch failed to apply to current kernel tree, does it need to be removed or updated?"
9184
)
9285
fetch_logs(build)
9386
sys.exit(1)
@@ -106,7 +99,7 @@ def check_log(build):
10699
warnings_count = build["warnings_count"]
107100
errors_count = build["errors_count"]
108101
if warnings_count + errors_count > 0:
109-
print_yellow(f"{warnings_count} warnings, {errors_count} errors")
102+
info(f"{warnings_count} warnings, {errors_count} errors")
110103
fetch_logs(build)
111104

112105

@@ -159,12 +152,12 @@ def check_built_config(build):
159152
elif line.startswith("# CONFIG_"):
160153
name, state = line.split(" ", 2)[1:]
161154
if state != "is not set":
162-
print_yellow(
155+
warn(
163156
f"Could not parse '{name}' from .config line '{line}'!?"
164157
)
165158
state = 'n'
166159
elif not line.startswith("#"):
167-
print_yellow(f"Could not parse .config line '{line}'!?")
160+
warn(f"Could not parse .config line '{line}'!?")
168161
configs[name] = state
169162

170163
# Compare requested configs against the loaded dictionary.
@@ -175,7 +168,7 @@ def check_built_config(build):
175168
name, state = config.split('=')
176169
# If a config is missing from the dictionary, it is considered 'n'.
177170
if state != configs.get(name, 'n'):
178-
print_red(f"FAIL: {config} not found in .config!")
171+
print_red(f"ERROR: {config} not found in .config!")
179172
fail = True
180173
else:
181174
print(f"ok: {name}={state}")
@@ -195,7 +188,7 @@ def print_clang_info(build):
195188
url = build["download_url"] + metadata_file.name
196189
_fetch(metadata_file, url, metadata_file)
197190
metadata_json = json.loads(metadata_file.read_text(encoding='utf-8'))
198-
print_yellow("Printing clang-nightly checkout date and hash")
191+
info("Printing clang-nightly checkout date and hash")
199192
parse_cmd = [
200193
Path(CI_ROOT, "scripts/parse-debian-clang.py"), "--print-info",
201194
"--version-string", metadata_json["compiler"]["version_full"]
@@ -243,8 +236,7 @@ def run_boot(build):
243236
boot_cmd += ["-t", "10m"]
244237
if "CONFIG_KASAN_KUNIT_TEST=y" in build["kconfig"] or \
245238
"CONFIG_KCSAN_KUNIT_TEST=y" in build["kconfig"]:
246-
print_yellow(
247-
"Disabling Oops problem matcher under Sanitizer KUnit build")
239+
info("Disabling Oops problem matcher under Sanitizer KUnit build")
248240
print("::remove-matcher owner=linux-kernel-oopses::")
249241

250242
# Before spawning a process with potentially different IO buffering,
@@ -256,19 +248,17 @@ def run_boot(build):
256248
subprocess.run(boot_cmd, check=True)
257249
except subprocess.CalledProcessError as err:
258250
if err.returncode == 124:
259-
print_red("Image failed to boot")
251+
print_red("ERROR: Image failed to boot")
260252
raise err
261253

262254

263255
def boot_test(build):
264256
if build["result"] == "unknown":
265-
print_red("unknown build result, skipping boot")
266-
sys.exit(1)
257+
die("unknown build result, skipping boot")
267258
if build["result"] == "fail":
268-
print_red("fatal build errors encountered during build, skipping boot")
269-
sys.exit(1)
259+
die("fatal build errors encountered during build, skipping boot")
270260
if "BOOT" in os.environ and os.environ["BOOT"] == "0":
271-
print_yellow("boot test disabled via config, skipping boot")
261+
info("boot test disabled via config, skipping boot")
272262
return
273263
fetch_kernel_image(build)
274264
fetch_dtb(build)
@@ -282,11 +272,11 @@ def boot_test(build):
282272
missing.append(var)
283273
if missing:
284274
for var in missing:
285-
print_red(f"${var} must be specified")
275+
print_red(f"ERROR: ${var} must be specified")
286276
show_builds()
287277
sys.exit(1)
288278
verified_build = verify_build()
289-
print_yellow("Register clang error/warning problem matchers")
279+
info("Register clang error/warning problem matchers")
290280
for problem_matcher in glob.glob(".github/problem-matchers/*.json"):
291281
print(f"::add-matcher::{problem_matcher}")
292282
print_clang_info(verified_build)

utils.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
LLVM_TOT_VERSION = Path(GENERATOR_ROOT, 'LLVM_TOT_VERSION')
1414

1515

16+
def die(msg):
17+
print_red(f"ERROR: {msg}")
18+
sys.exit(1)
19+
20+
1621
# Certain subsystems have more targeted -Werror configurations. If we have
1722
# CONFIG_WERROR=n, it means we are explicitly opting out of -Werror for some
1823
# reason, so all other known subsystem specific configurations should be
@@ -30,7 +35,7 @@ def disable_subsys_werror_configs(configs):
3035
def get_config_from_generator():
3136
if not (all_generator_files := sorted(
3237
Path(GENERATOR_ROOT, 'yml').glob('*.yml'))):
33-
raise FileNotFoundError('No generator files could not be found?')
38+
return die('No generator files could not be found?')
3439

3540
generator_pieces = []
3641
for file in all_generator_files:
@@ -131,18 +136,17 @@ def get_cbl_name():
131136
return unique_defconfigs[base_config]
132137
if "defconfig" in base_config or "virtconfig" in base_config:
133138
return "x86" if arch == "i386" else arch
134-
raise RuntimeError("unknown CBL name")
139+
return die("unknown CBL name")
135140

136141

137142
def _read_builds():
138143
file = "mock.builds.json" if os.environ.get("MOCK") else "builds.json"
139144
try:
140145
if (builds := Path(CI_ROOT, file)).stat().st_size == 0:
141-
raise RuntimeError(f"{file} is zero sized?")
146+
return die(f"{file} is zero sized?")
142147
builds_json = json.loads(builds.read_text(encoding='utf-8'))
143-
except FileNotFoundError as err:
144-
print_red(f"Unable to find {file}. Artifact not saved?")
145-
raise err
148+
except FileNotFoundError:
149+
return die(f"Unable to find {file}. Artifact not saved?")
146150
return builds_json["builds"].values()
147151

148152

@@ -157,6 +161,10 @@ def get_requested_llvm_version():
157161
return f"korg-clang-{ver}"
158162

159163

164+
def info(msg):
165+
print_yellow(f"INFO: {msg}")
166+
167+
160168
def show_builds():
161169
print_yellow("Available builds:")
162170
for build in _read_builds():
@@ -177,7 +185,7 @@ def get_build():
177185
build["toolchain"] == llvm_version and \
178186
build["kconfig"] == configs:
179187
return build
180-
print_red("Unable to find build")
188+
print_red("ERROR: Unable to find build")
181189
show_builds()
182190
sys.exit(1)
183191

@@ -186,7 +194,7 @@ def get_repo_ref(config, tree_name):
186194
for tree in config["trees"]:
187195
if tree["name"] == tree_name:
188196
return tree["git_repo"], tree["git_ref"]
189-
raise RuntimeError(f"Could not find git repo and ref for {tree_name}?")
197+
return die(f"Could not find git repo and ref for {tree_name}?")
190198

191199

192200
def get_llvm_versions(config, tree_name):
@@ -290,16 +298,20 @@ def update_repository_variable(
290298

291299

292300
def print_red(msg):
293-
print(f"\033[91m[CI ERROR] {msg}\033[0m", file=sys.stderr)
301+
print(f"\033[91m{msg}\033[0m", file=sys.stderr)
294302
sys.stderr.flush()
295303

296304

297305
def print_yellow(msg):
298-
print(f"\033[93m[CI WARNING] {msg}\033[0m", file=sys.stdout)
306+
print(f"\033[93m{msg}\033[0m", file=sys.stdout)
299307
sys.stdout.flush()
300308

301309

302310
def patch_series_flag(tree):
303311
patches_folder = Path('patches', tree)
304312
patch_files = list(Path(CI_ROOT, patches_folder).glob('*.patch'))
305313
return f"--patch-series {patches_folder} " if patch_files else ""
314+
315+
316+
def warn(msg):
317+
print_yellow(f"WARNING: {msg}")

0 commit comments

Comments
 (0)