Skip to content

Commit

Permalink
Merge pull request #514 from garythung/master
Browse files Browse the repository at this point in the history
SolcStandardJson: pass solc_env and solc_working_dir through to compilation
  • Loading branch information
montyly authored Apr 13, 2024
2 parents 20df04f + c526de8 commit 59b2b75
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crytic_compile/platform/solc_standard_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
import json
import logging
import os
from pathlib import Path
import shutil
import subprocess
from typing import TYPE_CHECKING, Dict, List, Optional, Union, Any
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

from crytic_compile.compilation_unit import CompilationUnit
from crytic_compile.compiler.compiler import CompilerVersion
from crytic_compile.platform.exceptions import InvalidCompilation
from crytic_compile.platform.solc import Solc, get_version, is_optimized, relative_to_short
from crytic_compile.platform.solc import (
Solc,
get_version,
is_optimized,
relative_to_short,
)
from crytic_compile.platform.types import Type
from crytic_compile.utils.naming import convert_filename

Expand Down Expand Up @@ -166,7 +171,6 @@ def run_solc_standard_json(
" ".join(cmd),
)
try:

with subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
Expand All @@ -176,7 +180,6 @@ def run_solc_standard_json(
executable=shutil.which(cmd[0]),
**additional_kwargs,
) as process:

stdout_b, stderr_b = process.communicate(json.dumps(solc_input).encode("utf-8"))
stdout, stderr = (
stdout_b.decode(),
Expand Down Expand Up @@ -457,7 +460,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:
Args:
crytic_compile (CryticCompile): Associated CryticCompile object
**kwargs: optional arguments. Used: "solc", "solc_disable_warnings", "solc_args", "solc_working_dir",
"solc_remaps"
"solc_remaps", "solc_env"
"""

solc: str = kwargs.get("solc", "solc")
Expand All @@ -466,13 +469,16 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:

solc_remaps: Optional[Union[str, List[str]]] = kwargs.get("solc_remaps", None)
solc_working_dir: Optional[str] = kwargs.get("solc_working_dir", None)
solc_env: Optional[Dict] = kwargs.get("solc_env", None)

compilation_unit = CompilationUnit(crytic_compile, "standard_json")

compilation_unit.compiler_version = CompilerVersion(
compiler="solc",
version=get_version(solc, None),
optimized=is_optimized(solc_arguments),
version=get_version(solc, solc_env),
optimized=is_optimized(solc_arguments)
or self.to_dict().get("settings", {}).get("optimizer", {}).get("enabled", False),
optimize_runs=self.to_dict().get("settings", {}).get("optimizer", {}).get("runs", None),
)

add_optimization(
Expand All @@ -493,6 +499,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:
self.to_dict(),
compilation_unit.compiler_version,
solc_disable_warnings=solc_disable_warnings,
working_dir=solc_working_dir,
)

parse_standard_json_output(
Expand Down

0 comments on commit 59b2b75

Please sign in to comment.