Skip to content

Commit

Permalink
coverage_report: Gracefully handle missing file (#814)
Browse files Browse the repository at this point in the history
Check if the file exists in the workspace before passing to pygount for source code analysis. If it does not exist, skip the file.
  • Loading branch information
Javagedes authored May 22, 2024
1 parent 2371cdd commit 2ff87aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions edk2toolext/environment/reporttypes/coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions tests.unit/test_repo_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 2ff87aa

Please sign in to comment.