Skip to content

Commit 1b5c6f6

Browse files
authored
Merge pull request #14731 from ethereum/fix-bytecode-report-ignoring-cli-exit-code
Fix `prepare_report.py` ignoring compiler exit code
2 parents b5eb0f9 + 646b342 commit 1b5c6f6

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Diff for: scripts/bytecodecompare/prepare_report.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ def parse_standard_json_output(source_file_name: Path, standard_json_output: str
183183
return file_report
184184

185185

186-
def parse_cli_output(source_file_name: Path, cli_output: str) -> FileReport:
186+
def parse_cli_output(source_file_name: Path, cli_output: str, exit_code: int) -> FileReport:
187+
if exit_code != 0:
188+
return FileReport(file_name=source_file_name, contract_reports=None)
189+
187190
# re.split() returns a list containing the text between pattern occurrences but also inserts the
188191
# content of matched groups in between. It also never omits the empty elements so the number of
189192
# list items is predictable (3 per match + the text before the first match)
@@ -312,7 +315,7 @@ def run_compiler(
312315
input=compiler_input,
313316
encoding='utf8',
314317
capture_output=True,
315-
check=exit_on_error,
318+
check=True,
316319
)
317320

318321
return parse_standard_json_output(Path(source_file_name), process.stdout)
@@ -345,7 +348,7 @@ def run_compiler(
345348
check=exit_on_error,
346349
)
347350

348-
return parse_cli_output(Path(source_file_name), process.stdout)
351+
return parse_cli_output(Path(source_file_name), process.stdout, process.returncode)
349352

350353

351354
def generate_report(

Diff for: scripts/common/cmdline_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def solc_bin_report(solc_binary: str, input_files: List[Path], via_ir: bool) ->
4848
(['--via-ir'] if via_ir else []),
4949
encoding='utf8',
5050
)
51-
return parse_cli_output('', output)
51+
return parse_cli_output('', output, 0)
5252

5353

5454
def save_bytecode(bytecode_path: Path, reports: FileReport, contract: Optional[str] = None):

Diff for: test/scripts/test_bytecodecompare_prepare_report.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -487,19 +487,19 @@ def test_parse_cli_output(self):
487487
]
488488
)
489489

490-
report = parse_cli_output(Path('syntaxTests/scoping/library_inherited2.sol'), LIBRARY_INHERITED2_SOL_CLI_OUTPUT)
490+
report = parse_cli_output(Path('syntaxTests/scoping/library_inherited2.sol'), LIBRARY_INHERITED2_SOL_CLI_OUTPUT, 0)
491491
self.assertEqual(report, expected_report)
492492

493493
def test_parse_cli_output_should_report_error_on_compiler_errors(self):
494494
expected_report = FileReport(file_name=Path('syntaxTests/pragma/unknown_pragma.sol'), contract_reports=None)
495495

496-
report = parse_cli_output(Path('syntaxTests/pragma/unknown_pragma.sol'), UNKNOWN_PRAGMA_SOL_CLI_OUTPUT)
496+
report = parse_cli_output(Path('syntaxTests/pragma/unknown_pragma.sol'), UNKNOWN_PRAGMA_SOL_CLI_OUTPUT, 0)
497497
self.assertEqual(report, expected_report)
498498

499499
def test_parse_cli_output_should_report_error_on_empty_output(self):
500500
expected_report = FileReport(file_name=Path('file.sol'), contract_reports=None)
501501

502-
self.assertEqual(parse_cli_output(Path('file.sol'), ''), expected_report)
502+
self.assertEqual(parse_cli_output(Path('file.sol'), '', 0), expected_report)
503503

504504
def test_parse_cli_output_should_report_missing_bytecode_and_metadata(self):
505505
compiler_output = dedent("""\
@@ -541,22 +541,25 @@ def test_parse_cli_output_should_report_missing_bytecode_and_metadata(self):
541541
]
542542
)
543543

544-
self.assertEqual(parse_cli_output(Path('syntaxTests/scoping/library_inherited2.sol'), compiler_output), expected_report)
544+
self.assertEqual(
545+
parse_cli_output(Path('syntaxTests/scoping/library_inherited2.sol'), compiler_output, 0),
546+
expected_report
547+
)
545548

546549
def test_parse_cli_output_should_report_error_on_unimplemented_feature_error(self):
547550
expected_report = FileReport(file_name=Path('file.sol'), contract_reports=None)
548551

549-
self.assertEqual(parse_cli_output(Path('file.sol'), UNIMPLEMENTED_FEATURE_CLI_OUTPUT), expected_report)
552+
self.assertEqual(parse_cli_output(Path('file.sol'), UNIMPLEMENTED_FEATURE_CLI_OUTPUT, 0), expected_report)
550553

551554
def test_parse_cli_output_should_report_error_on_stack_too_deep_error(self):
552555
expected_report = FileReport(file_name=Path('file.sol'), contract_reports=None)
553556

554-
self.assertEqual(parse_cli_output(Path('file.sol'), STACK_TOO_DEEP_CLI_OUTPUT), expected_report)
557+
self.assertEqual(parse_cli_output(Path('file.sol'), STACK_TOO_DEEP_CLI_OUTPUT, 0), expected_report)
555558

556559
def test_parse_cli_output_should_report_error_on_code_generation_error(self):
557560
expected_report = FileReport(file_name=Path('file.sol'), contract_reports=None)
558561

559-
self.assertEqual(parse_cli_output(Path('file.sol'), CODE_GENERATION_ERROR_CLI_OUTPUT), expected_report)
562+
self.assertEqual(parse_cli_output(Path('file.sol'), CODE_GENERATION_ERROR_CLI_OUTPUT, 0), expected_report)
560563

561564
def test_parse_cli_output_should_handle_output_from_solc_0_4_0(self):
562565
expected_report = FileReport(
@@ -571,7 +574,7 @@ def test_parse_cli_output_should_handle_output_from_solc_0_4_0(self):
571574
]
572575
)
573576

574-
self.assertEqual(parse_cli_output(Path('contract.sol'), SOLC_0_4_0_CLI_OUTPUT), expected_report)
577+
self.assertEqual(parse_cli_output(Path('contract.sol'), SOLC_0_4_0_CLI_OUTPUT, 0), expected_report)
575578

576579
def test_parse_cli_output_should_handle_output_from_solc_0_4_8(self):
577580
expected_report = FileReport(
@@ -588,7 +591,7 @@ def test_parse_cli_output_should_handle_output_from_solc_0_4_8(self):
588591
]
589592
)
590593

591-
self.assertEqual(parse_cli_output(Path('contract.sol'), SOLC_0_4_8_CLI_OUTPUT), expected_report)
594+
self.assertEqual(parse_cli_output(Path('contract.sol'), SOLC_0_4_8_CLI_OUTPUT, 0), expected_report)
592595

593596
def test_parse_cli_output_should_handle_leading_and_trailing_spaces(self):
594597
compiler_output = (
@@ -606,7 +609,7 @@ def test_parse_cli_output_should_handle_leading_and_trailing_spaces(self):
606609
]
607610
)
608611

609-
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output), expected_report)
612+
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output, 0), expected_report)
610613

611614
def test_parse_cli_output_should_handle_empty_bytecode_and_metadata_lines(self):
612615
compiler_output = dedent("""\
@@ -640,7 +643,7 @@ def test_parse_cli_output_should_handle_empty_bytecode_and_metadata_lines(self):
640643
]
641644
)
642645

643-
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output), expected_report)
646+
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output, 0), expected_report)
644647

645648
def test_parse_cli_output_should_handle_link_references_in_bytecode(self):
646649
compiler_output = dedent("""\
@@ -662,4 +665,4 @@ def test_parse_cli_output_should_handle_link_references_in_bytecode(self):
662665
)
663666
# pragma pylint: enable=line-too-long
664667

665-
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output), expected_report)
668+
self.assertEqual(parse_cli_output(Path('contract.sol'), compiler_output, 0), expected_report)

0 commit comments

Comments
 (0)