Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage_report: Gracefully handle missing file #814

Merged
merged 5 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions edk2toolext/environment/reporttypes/coverage_report.py
Original file line number Diff line number Diff line change
@@ -300,7 +300,9 @@ def build_report(self, session: Session, env_id: int, source_coverage_dict: dict
if match is not None:
classes.append(source_coverage_dict[match])
elif self.args.full:
classes.append(self.create_source_xml(source, edk2path))
xml = self.create_source_xml(source, edk2path)
if xml is not None:
classes.append(xml)

# Flaten the report to only source files, removing duplicates from INFs.
if self.args.flatten:
@@ -328,10 +330,13 @@ def update_excluded_files(self) -> None:
temporary_list.append(pattern)
self.args.exclude = temporary_list

def create_source_xml(self, source_path: str, edk2path: Edk2Path) -> ET:
def create_source_xml(self, source_path: str, edk2path: Edk2Path) -> Optional[ET.Element]:
"""Parses the source file and creates a coverage 'lines' xml element for it."""
from pygount import SourceAnalysis
full_path = edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath(source_path)
full_path = edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath(source_path, log_errors=False)
if full_path is None:
logging.warning(f"Could not find {source_path} in the workspace. Skipping...")
return None
code_count = SourceAnalysis.from_file(full_path, "_").code_count
file_xml = ET.Element("class", name="\\".join(Path(source_path).parts), filename=source_path)
lines_xml = ET.Element("lines")
10 changes: 5 additions & 5 deletions tests.unit/test_repo_resolver.py
Original file line number Diff line number Diff line change
@@ -8,13 +8,13 @@
##
import logging
import os
import pathlib
import tempfile
import unittest

import pytest
from edk2toolext.environment import repo_resolver
from edk2toollib.utility_functions import RemoveTree
import tempfile
import pathlib
import pytest


branch_dependency = {
"Url": "https://github.com/microsoft/mu",
@@ -326,7 +326,7 @@ def __init__(self, path, recursive):
self.recursive = recursive

temp_folder = tempfile.mkdtemp()
submodule_path = "Common/MU_TIANO"
submodule_path = "Common/MU"
deps = {"Url": "https://github.com/microsoft/mu_tiano_platforms"}
repo_resolver.clone_repo(temp_folder, deps)