From d895c0f0bb9e863b964f885ce3da06093af71f3d Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 20 Feb 2024 12:25:35 -0800 Subject: [PATCH] coverage_report: Allow package filtering for --by-platform (#745) 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. --- .../reporttypes/coverage_report.py | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/edk2toolext/environment/reporttypes/coverage_report.py b/edk2toolext/environment/reporttypes/coverage_report.py index 9c6ff851..53fdc8b3 100644 --- a/edk2toolext/environment/reporttypes/coverage_report.py +++ b/edk2toolext/environment/reporttypes/coverage_report.py @@ -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, @@ -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.""" @@ -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. @@ -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) @@ -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()