From acaab18a0a83d7aa939d4fdb28b95e670cfe045a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 22 Dec 2020 04:07:51 +0100 Subject: [PATCH] prepare_report.py: More information on stdout, with verbosity control --- scripts/bytecodecompare/prepare_report.py | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/bytecodecompare/prepare_report.py b/scripts/bytecodecompare/prepare_report.py index a2b14c9b3..f1a77e893 100755 --- a/scripts/bytecodecompare/prepare_report.py +++ b/scripts/bytecodecompare/prepare_report.py @@ -62,6 +62,26 @@ class FileReport: return report + def format_summary(self, verbose: bool) -> str: + error = (self.contract_reports is None) + contract_reports = self.contract_reports if self.contract_reports is not None else [] + no_bytecode = any(bytecode is None for bytecode in contract_reports) + no_metadata = any(metadata is None for metadata in contract_reports) + + if verbose: + flags = ('E' if error else ' ') + ('B' if no_bytecode else ' ') + ('M' if no_metadata else ' ') + contract_count = '?' if self.contract_reports is None else str(len(self.contract_reports)) + return f"{contract_count} {flags} {self.file_name}" + else: + if error: + return 'E' + if no_bytecode: + return 'B' + if no_metadata: + return 'M' + + return '.' + def load_source(path: Union[Path, str], smt_use: SMTUse) -> str: # NOTE: newline='' disables newline conversion. @@ -278,6 +298,7 @@ def generate_report( smt_use: SMTUse, force_no_optimize_yul: bool, report_file_path: Path, + verbose: bool, ): metadata_option_supported = detect_metadata_cli_option_support(compiler_path) @@ -296,6 +317,7 @@ def generate_report( metadata_option_supported, Path(tmp_dir), ) + print(report.format_summary(verbose), end=('\n' if verbose else ''), flush=True) report_file.write(report.format_report()) except subprocess.CalledProcessError as exception: print( @@ -345,6 +367,7 @@ def commandline_parser() -> ArgumentParser: help="Explicitly disable Yul optimizer in CLI runs without optimization to work around a bug in solc 0.6.0 and 0.6.1." ) parser.add_argument('--report-file', dest='report_file', default='report.txt', help="The file to write the report to.") + parser.add_argument('--verbose', dest='verbose', default=False, action='store_true', help="More verbose output.") return parser; @@ -357,4 +380,5 @@ if __name__ == "__main__": SMTUse(options.smt_use), options.force_no_optimize_yul, Path(options.report_file), + options.verbose, )