Skip to content

Commit 6a18ffb

Browse files
joevanloonbohendo
authored andcommitted
Fixed solc
Added break statements to loops in _run_solcs_env and _run_solcs_path to return on first successful compilation instead of last. Also added consolidated compilation error outputs to allow for easier debugging. When using a large range that includes earlier versions, this would sometimes select version 3.6, which causes other issues due to different output formats.
1 parent 441cabd commit 6a18ffb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

crytic_compile/platform/solc.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ def _run_solcs_path(
584584
targets_json = None
585585
if isinstance(solcs_path, dict):
586586
guessed_solcs = _guess_solc(filename, working_dir)
587+
compilation_errors = []
587588
for guessed_solc in guessed_solcs:
588589
if not guessed_solc in solcs_path:
589590
continue
@@ -624,12 +625,14 @@ def _run_solcs_path(
624625
working_dir=working_dir,
625626
force_legacy_json=force_legacy_json,
626627
)
627-
except InvalidCompilation:
628+
break
629+
except InvalidCompilation as ic:
630+
compilation_errors.append(version_env+': '+ic.args[0])
628631
pass
629632

630633
if not targets_json:
631634
raise InvalidCompilation(
632-
"Invalid solc compilation, none of the solc versions provided worked"
635+
"Invalid solc compilation, none of the solc versions provided worked:\n"+'\n'.join(compilation_errors)
633636
)
634637

635638
return targets_json
@@ -672,6 +675,7 @@ def _run_solcs_env(
672675
env = dict(os.environ) if env is None else env
673676
targets_json = None
674677
guessed_solcs = _guess_solc(filename, working_dir)
678+
compilation_errors = []
675679
for guessed_solc in guessed_solcs:
676680
if solcs_env and not guessed_solc in solcs_env:
677681
continue
@@ -688,6 +692,7 @@ def _run_solcs_env(
688692
working_dir=working_dir,
689693
force_legacy_json=force_legacy_json,
690694
)
695+
break
691696
except InvalidCompilation:
692697
pass
693698

@@ -708,12 +713,14 @@ def _run_solcs_env(
708713
working_dir=working_dir,
709714
force_legacy_json=force_legacy_json,
710715
)
711-
except InvalidCompilation:
716+
break
717+
except InvalidCompilation as ic:
718+
compilation_errors.append(version_env+': '+ic.args[0])
712719
pass
713720

714721
if not targets_json:
715722
raise InvalidCompilation(
716-
"Invalid solc compilation, none of the solc versions provided worked"
723+
"Invalid solc compilation, none of the solc versions provided worked:\n"+'\n'.join(compilation_errors)
717724
)
718725

719726
return targets_json

0 commit comments

Comments
 (0)