Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Javagedes committed Sep 27, 2023
1 parent deee5c7 commit e7ff927
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion edk2toolext/edk2_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def output_compiler_error(match, line, start_txt="Compiler"):
build_py_error_exp = re.compile(r"error (\d+)E:")
linker_error_exp = re.compile(r"error LNK(\d+):")
warning_exp = re.compile(r"warning [A-Z]?(\d+):")
rust_error_exp = re.compile(r"^(-->|\d+\s*\||error:)")
rust_error_exp = re.compile(r"^(-->|error(?:\[[A-Za-z]\d+\])?:)")

Check failure

Code scanning / CodeQL

Bad HTML filtering regexp High

This regular expression only parses --> and not --!> as a HTML comment end tag.
for raw_line in output_stream.readlines():
line = raw_line.strip("\n").strip()
match = error_exp.search(line)
Expand Down
61 changes: 57 additions & 4 deletions tests.unit/test_edk2_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
import io
import logging
import os
import tempfile
import unittest
import logging

from edk2toolext import edk2_logging


Expand Down Expand Up @@ -194,7 +195,7 @@ def test_scan_compiler_output_gcc_mixed_actual(self):
def test_NO_secret_filter(caplog):
end_list = [" ", ",", ";", ":", " "]
start_list = [" ", " ", " ", " ", ":"]

edk2_logging.setup_console_logging(logging.DEBUG)
# Test secret github (valid) 1
fake_secret = "ghp_aeiou1"
Expand All @@ -209,7 +210,7 @@ def test_CI_secret_filter(caplog):
caplog.set_level(logging.DEBUG)
end_list = [" ", ",", ";", ":", " "]
start_list = [" ", " ", " ", " ", ":"]

os.environ["CI"] = "TRUE"
edk2_logging.setup_console_logging(logging.DEBUG)
caplog.clear()
Expand All @@ -227,7 +228,7 @@ def test_TF_BUILD_secret_filter(caplog):
caplog.set_level(logging.DEBUG)
end_list = [" ", ",", ";", ":", " "]
start_list = [" ", " ", " ", " ", ":"]

os.environ["TF_BUILD"] = "TRUE"
edk2_logging.setup_console_logging(logging.DEBUG)
caplog.clear()
Expand Down Expand Up @@ -286,3 +287,55 @@ def test_catch_secrets_filter(caplog):
for (record, start, end) in zip(caplog.records, start_list, end_list):
assert record.msg == f"This is a secret{start}{fake_secret}{end}to be caught"
caplog.clear()

def test_scan_compiler_output_rust_scenarios():
output_stream = io.StringIO(r"""
error: This should be caught
error[AA500]: This should not be caught
error[E0605]: This should be caught
error[E0605] This should not be caught
catch this error: This should not be caught
--> This should be caught
> This should not be caught
catch this error --> This should not be caught
""")
expected_output = [
(logging.ERROR, 'error: This should be caught'),
(logging.ERROR, 'error[E0605]: This should be caught'),
(logging.ERROR, '--> This should be caught'),
]
assert edk2_logging.scan_compiler_output(output_stream) == expected_output

def test_scan_compiler_output_rust_actual():
output_stream = io.StringIO(r"""
[cargo-make] INFO - cargo make 0.37.1
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: build
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: individual-package-targets
[cargo-make] INFO - Execute Command: "cargo" "build" "-p" "DxeRust" "--profile" "dev" "--target" "x86_64-unknown-uefi" "-Zbuild-std=core,compiler_builtins,alloc" "-Zbuild-std-features=compiler-builtins-mem" "-Zunstable-options" "--timings=html"
Compiling DxeRust v0.1.0 (C:\\src\\UefiRust\\Platforms\\QemuQ35Pkg\\DxeRust)
error[E0605]: non-primitive cast: `MemorySpaceDescriptor` as `*mut MemorySpaceDescriptor`
--> Platforms\\QemuQ35Pkg\\DxeRust\\src/main.rs:248:66
|
248 | if get_memory_space_descriptor(desc.memory_base_address, descriptor as *mut MemorySpaceDescriptor)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
|
help: consider borrowing the value
|
248 | if get_memory_space_descriptor(desc.memory_base_address, &mut descriptor as *mut MemorySpaceDescriptor)
| ++++
For more information about this error, try `rustc --explain E0605`.
error: could not compile `DxeRust` (bin "DxeRust") due to previous error
Timing report saved to C:\\src\\UefiRust\\target\\cargo-timings\\cargo-timing-20230927T151803Z.html
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.
""")
expected_output = [(logging.ERROR, 'error[E0605]: non-primitive cast: `MemorySpaceDescriptor` as `*mut MemorySpaceDescriptor`'),
(logging.ERROR, r'--> Platforms\\QemuQ35Pkg\\DxeRust\\src/main.rs:248:66'),
(logging.ERROR, 'error: could not compile `DxeRust` (bin "DxeRust") due to previous error')]
assert edk2_logging.scan_compiler_output(output_stream) == expected_output

0 comments on commit e7ff927

Please sign in to comment.