Skip to content

Commit

Permalink
Merge pull request #111 from crytic/feature/legacy-json
Browse files Browse the repository at this point in the history
allow forcing legacy json
  • Loading branch information
montyly authored Sep 23, 2020
2 parents 399cc7c + 909d9a4 commit 7f6a1c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crytic_compile/cryticparser/cryticparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ def _init_solc(parser):
default=DEFAULTS_FLAG_IN_CONFIG["solc_standard_json"],
)

group_solc.add_argument(
"--solc-force-legacy-json",
help="Force the solc compiler to use the legacy json ast format over the compact json ast format",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["solc_force_legacy_json"],
)


def _init_waffle(parser):
group_waffle = parser.add_argument_group("Waffle options")
Expand Down
1 change: 1 addition & 0 deletions crytic_compile/cryticparser/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"solc_solcs_select": None,
"solc_solcs_bin": None,
"solc_standard_json": False,
"solc_force_legacy_json": False,
"truffle_version": None,
"truffle_ignore_compile": False,
"truffle_build_directory": "build/contracts",
Expand Down
13 changes: 13 additions & 0 deletions crytic_compile/platform/solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str):
solc_arguments = kwargs.get("solc_args", "")
solc_remaps = kwargs.get("solc_remaps", None)
solc_working_dir = kwargs.get("solc_working_dir", None)
force_legacy_json = kwargs.get("solc_force_legacy_json", False)

crytic_compile.compiler_version = CompilerVersion(
compiler="solc", version=get_version(solc), optimized=is_optimized(solc_arguments)
Expand All @@ -126,6 +127,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str):
solc_arguments,
solc_remaps=solc_remaps,
working_dir=solc_working_dir,
force_legacy_json=force_legacy_json,
)

elif solcs_env:
Expand All @@ -139,6 +141,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str):
solcs_env=solcs_env_list,
solc_remaps=solc_remaps,
working_dir=solc_working_dir,
force_legacy_json=force_legacy_json,
)

else:
Expand All @@ -150,6 +153,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str):
solc_arguments,
solc_remaps=solc_remaps,
working_dir=solc_working_dir,
force_legacy_json=force_legacy_json,
)

skip_filename = crytic_compile.compiler_version.version in [
Expand Down Expand Up @@ -274,6 +278,7 @@ def _run_solc(
solc_remaps=None,
env=None,
working_dir=None,
force_legacy_json=False,
):
"""
Note: Ensure that crytic_compile.compiler_version is set prior calling _run_solc
Expand Down Expand Up @@ -301,6 +306,8 @@ def _run_solc(
old_04_versions = [f"0.4.{x}" for x in range(0, 12)]
if compiler_version.version in old_04_versions or compiler_version.version.startswith("0.3"):
options = "abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc"
elif force_legacy_json:
options = "abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes"
else:
options = (
"abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes,compact-format"
Expand Down Expand Up @@ -374,6 +381,7 @@ def _run_solcs_path(
solc_remaps=None,
env=None,
working_dir=None,
force_legacy_json=False,
):
targets_json = None
if isinstance(solcs_path, dict):
Expand All @@ -391,6 +399,7 @@ def _run_solcs_path(
solc_remaps=solc_remaps,
env=env,
working_dir=working_dir,
force_legacy_json=force_legacy_json,
)
except InvalidCompilation:
pass
Expand All @@ -409,6 +418,7 @@ def _run_solcs_path(
solc_remaps=solc_remaps,
env=env,
working_dir=working_dir,
force_legacy_json=force_legacy_json,
)
except InvalidCompilation:
pass
Expand All @@ -432,6 +442,7 @@ def _run_solcs_env(
env=None,
working_dir=None,
solcs_env=None,
force_legacy_json=False,
):
env = dict(os.environ) if env is None else env
targets_json = None
Expand All @@ -450,6 +461,7 @@ def _run_solcs_env(
solc_remaps=solc_remaps,
env=env,
working_dir=working_dir,
force_legacy_json=force_legacy_json,
)
except InvalidCompilation:
pass
Expand All @@ -469,6 +481,7 @@ def _run_solcs_env(
solc_remaps=solc_remaps,
env=env,
working_dir=working_dir,
force_legacy_json=force_legacy_json,
)
except InvalidCompilation:
pass
Expand Down

0 comments on commit 7f6a1c6

Please sign in to comment.