Skip to content

Commit

Permalink
coverage_report: Allow package filtering for --by-platform (#745)
Browse files Browse the repository at this point in the history
Originally, both a --by-package and --by-platform flag was created to
describe the types of coverage reports able to be generated, and allow
for grouping the command line arguments based on these two flags.

With the adding of the ability to filter on packages for the platform
report, the --by-package flag no longer has any special arguments and
can be deprecated. Due to this, this change also removes the
--by-package flag, making it the default behavior, which is overridden
by --py-platform.
  • Loading branch information
Javagedes authored Feb 20, 2024
1 parent f1356d5 commit d895c0f
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions edk2toolext/environment/reporttypes/coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ def report_info(self) -> Tuple[str, str]:

def add_cli_options(self, parserobj: ArgumentParser) -> None:
"""Configure command line arguments for this report."""
# Group 1 - Calculate coverage only for files in a specific package
group = parserobj.add_argument_group("Coverage by package options")
group.add_argument("--by-package", action="store_true", dest="by_package", default=False,
help="Filters test coverage to only files in the specified packages(s)")
group.add_argument("-p", "--package", "--Package", "--PACKAGE", dest="package_list",
action=SplitCommaAction, default=[],
help="The package to include in the report. Can be specified multiple times.")

# Group 2 - Calculate coverage only on files used by a specific platform
group = parserobj.add_argument_group("Coverage by platform options")
group.add_argument("--by-platform", action="store_true", dest="by_platform", default=False,
Expand All @@ -83,9 +75,15 @@ def add_cli_options(self, parserobj: ArgumentParser) -> None:
action=SplitCommaAction, default=[],
help="Package path relative paths or file (.txt). Globbing is supported. Can be "
"specified multiple times")
parserobj.add_argument("-p", "--package", "--Package", "--PACKAGE", dest="package_list",
action=SplitCommaAction, default=[],
help="The package to include in the report. Can be specified multiple times.")
parserobj.add_argument("--flatten", action="store_true", dest="flatten", default=False,
help="Flatten the report to only source files. This removes duplicate files that are in "
"multiple INFs.")
group = parserobj.add_argument_group("Deprecated Options")
group.add_argument("--by-package", action="store_true", dest="by_package", default=False,
help="Filters test coverage to only files in the specified packages(s)")

def run_report(self, db: Edk2DB, args: Namespace) -> None:
"""Generate the Coverage report."""
Expand All @@ -97,21 +95,24 @@ def run_report(self, db: Edk2DB, args: Namespace) -> None:
self.update_excluded_files()

with db.session() as session:
if args.by_package:
logging.info("Organizing coverage report by Package.")
return self.run_by_package(session)
package_list = self.args.package_list or [pkg.name for pkg in session.query(Package).all()]
logging.info(f"Packages requested: {', '.join(package_list)}")
if args.by_platform:
logging.info("Organizing coverage report by Platform.")
return self.run_by_platform(session)

logging.error("No report type specified via command line or configuration file.")
return -1
return self.run_by_platform(session, package_list)
if args.by_package:
logging.warning(
"The --by-package flag is deprecated and will be removed in a future release."
" by-package is now the default behavior and overriden with by-platform."
)
return self.run_by_package(session, package_list)

def run_by_platform(self, session: Session) -> None:
def run_by_platform(self, session: Session, package_list: list) -> None:
"""Runs the report, only adding coverage data for source files used to build the platform.
Args:
session (Session): The session associated with the database
package_list (list): The list of packages to filter the results by
Returns:
(bool): True if the report was successful, False otherwise.
Expand All @@ -136,8 +137,6 @@ def run_by_platform(self, session: Session) -> None:
return -1
env_id = result.id

package_list = [pkg.name for pkg in session.query(Package).all()]

# Build source / coverage association dictionary
coverage_files = self.build_source_coverage_dictionary(self.args.xml, package_list)

Expand All @@ -164,19 +163,16 @@ def run_by_platform(self, session: Session) -> None:
# Build the report
return self.build_report(session, env_id, coverage_files, package_files)

def run_by_package(self, session: Session) -> bool:
def run_by_package(self, session: Session, package_list: list) -> bool:
"""Runs the report, only adding coverage data for source files in the specified packages.
Args:
session (Session): The session associated with the database
package_list (list): The list of packages to filter the results by
Returns:
(bool): True if the report was successful, False otherwise.
"""
# Get package_list
package_list = self.args.package_list or [pkg.name for pkg in session.query(Package).all()]
logging.info(f"Packages requested: {', '.join(package_list)}")

# Get env_id
env_id, = session.query(Environment.id).order_by(Environment.date.desc()).first()

Expand Down

0 comments on commit d895c0f

Please sign in to comment.